Skip to content
Browse files

Receive UDP data correctly, yeah!

  • Loading branch information...
1 parent 31fdb32 commit e2fc5276cf1aa7dc299495ad10d9e1a129f3760c @cibomahto cibomahto committed Mar 18, 2012
Showing with 103 additions and 21 deletions.
  1. +61 −19 BlinkeyDomeSimulator.pde
  2. +3 −2 BlinkeyLights.pde
  3. +39 −0 ImageHUD.pde
View
80 BlinkeyDomeSimulator.pde
@@ -2,25 +2,30 @@ import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import processing.opengl.*;
+import hypermedia.net.*;
int DOME_RADIUS = 8;
-
int strips = 25; // Number of strips around the circumference of the sphere
int lights_per_strip = 45*3; // Number of lights along the strip
-PeasyCam pCamera;
+Boolean demoMode = true;
+Boolean newData = false;
+color[] newImage;
-BlinkeyLights blinkeyLights;
+UDP udp;
+PeasyCam pCamera;
+BlinkeyLights blinkeyLights;
Dome dome;
Hud hud;
+ImageHud imageHud;
PFont font;
-
PImage groundTexture;
void setup() {
- size(1024, 1024, OPENGL);
+ //size(1024, 1024, OPENGL);
+ size(1680, 1000, OPENGL);
pCamera = new PeasyCam(this, 0, 0, 10, 200);
pCamera.setMinimumDistance(1);
pCamera.setMaximumDistance(150*10);
@@ -29,19 +34,52 @@ void setup() {
pCamera.lookAt(0, -10, -20);
pCamera.setWheelScale(0.05);
- dome = new Dome(DOME_RADIUS);
+ newImage = new color[strips*lights_per_strip];
+
+ udp = new UDP( this, 58082 );
+ udp.listen( true );
font = loadFont("Serif-24.vlw");
-
- groundTexture = loadImage("Lost Lake.jpg");
-
- blinkeyLights = new BlinkeyLights(DOME_RADIUS, strips, lights_per_strip);
hud = new Hud();
+ dome = new Dome(DOME_RADIUS);
+ blinkeyLights = new BlinkeyLights(DOME_RADIUS, strips, lights_per_strip);
+ imageHud = new ImageHud(10,10, strips, lights_per_strip);
+
+ groundTexture = loadImage("Lost Lake.jpg");
}
int animationStep = 0;
-color[] GetNextFrame() {
+int convertByte(byte b) {
+ return (b<0) ? 256+b : b;
+}
+
+void receive(byte[] data, String ip, int port) {
+ //println(" new datas!");
+ if (demoMode) {
+ println("Started receiving data from " + ip + ". Demo mode disabled.");
+ demoMode = false;
+ }
+
+ if (data[0] == 1) {
+ if (data.length != strips*lights_per_strip*3 + 1) {
+ println("Packet size mismatch. Expected many, got " + data.length);
+ return;
+ }
+
+ for (int i=0; i< strips*lights_per_strip; i++) {
+ newImage[i] = color(convertByte(data[i*3 + 1]),
+ convertByte(data[i*3 + 2]),
+ convertByte(data[i*3 + 3]));
+ }
+ newData = true;
+ }
+ else {
+ println("Packet header mismatch. Expected 1, got " + data[0]);
+ }
+}
+
+color[] MakeDemoFrame() {
int image_size = strips*lights_per_strip;
color[] imageData = new color[image_size];
@@ -53,6 +91,7 @@ color[] GetNextFrame() {
else {
imageData[i] = color(0, 0, 0);
}
+ newData = true;
}
//animationStep = (animationStep+1)%blinkeyLights.size();
animationStep = (animationStep + 1)%10;
@@ -61,13 +100,15 @@ color[] GetNextFrame() {
}
void draw() {
- color imageData[] = GetNextFrame();
-
- if (imageData.length != blinkeyLights.size()) {
- print("Bad frame size received!");
- }
- else {
+ if (demoMode) {
+ color imageData[] = MakeDemoFrame();
blinkeyLights.update(imageData);
+ imageHud.update(imageData);
+ }
+ else if(newData) {
+ blinkeyLights.update(newImage);
+ imageHud.update(newImage);
+ newData = false;
}
background(0);
@@ -90,9 +131,10 @@ void draw() {
endShape();
popMatrix();
- dome.draw();
+ //dome.draw();
blinkeyLights.draw();
- hud.draw();
+ //hud.draw();
+ //imageHud.draw();
}
View
5 BlinkeyLights.pde
@@ -7,8 +7,9 @@ class BlinkeyLights {
radius_ = radius_ * 10;
- for (int strip = 0; strip < strips_; strip++) {
- for (int light = 0; light < lights_per_strip_; light++) {
+ for (int light = lights_per_strip_ -1; light > 0; light--) {
+ for (int strip = 0; strip < strips_; strip++) {
+
float inclination = HALF_PI + (HALF_PI)*((float)light/lights_per_strip_);
float azimuth = (2*PI)*((float)strip/strips_);
View
39 ImageHUD.pde
@@ -0,0 +1,39 @@
+class ImageHud {
+ PImage img;
+ float x;
+ float y;
+
+ ImageHud(float x_, float y_, int w_, int h_) {
+ x = x_;
+ y = y_;
+ img = new PImage(w_,h_);
+ }
+
+ void update(color[] imageData) {
+ img.loadPixels();
+ for (int i = 0; i < blinkeyLights.size(); i++) {
+ img.pixels[i] = imageData[i];
+ }
+ img.updatePixels();
+ }
+
+ void draw() {
+ pCamera.beginHUD();
+ image(img, x, y);
+ pCamera.endHUD();
+
+// pushMatrix();
+// translate(0, 0.5, 0);
+//
+// beginShape();
+// texture(groundTexture);
+// textureMode(NORMALIZED);
+//
+// vertex(w_, h_, 0, 0, 0);
+// vertex(bound, .5, -bound, 1, 0);
+// vertex(bound, .5, bound, 1, 1);
+// vertex(-bound, .5, bound, 0, 1);
+// endShape();
+// popMatrix();
+ }
+}

0 comments on commit e2fc527

Please sign in to comment.
Something went wrong with that request. Please try again.