diff --git a/BlinkeyDomeSimulator.pde b/BlinkeyDomeSimulator.pde index faa6a8f..9d1dabe 100644 --- a/BlinkeyDomeSimulator.pde +++ b/BlinkeyDomeSimulator.pde @@ -2,15 +2,17 @@ import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import processing.opengl.*; +//import javax.media.opengl.GL; import hypermedia.net.*; +import java.util.concurrent.*; + 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 Boolean demoMode = true; -Boolean newData = false; -color[] newImage; +LinkedBlockingQueue newImageQueue; UDP udp; @@ -25,17 +27,24 @@ PImage groundTexture; void setup() { size(1024, 850, OPENGL); + frameRate(60); + +// PGraphicsOpenGL pgl = (PGraphicsOpenGL) g; //processing graphics object +// GL gl = pgl.beginGL(); //begin opengl +// gl.setSwapInterval(2); //set vertical sync on +// pgl.endGL(); //end opengl + //size(1680, 1000, OPENGL); pCamera = new PeasyCam(this, 0, 0, 10, 200); pCamera.setMinimumDistance(1); pCamera.setMaximumDistance(150*10); pCamera.setSuppressRollRotationMode(); pCamera.rotateX(-0.2); -// pCamera.lookAt(0, -10, -20); -// pCamera.rotateY(-HALF_PI); + // pCamera.lookAt(0, -10, -20); + // pCamera.rotateY(-HALF_PI); pCamera.setWheelScale(0.05); - newImage = new color[strips*lights_per_strip]; + newImageQueue = new LinkedBlockingQueue(); udp = new UDP( this, 58082 ); udp.listen( true ); @@ -55,28 +64,41 @@ int convertByte(byte b) { return (b<0) ? 256+b : b; } -void receive(byte[] data, String ip, int port) { +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; - } + if (data[0] != 1) { + println("Packet header mismatch. Expected 1, got " + data[0]); + 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; + if (data.length != strips*lights_per_strip*3 + 1) { + println("Packet size mismatch. Expected many, got " + data.length); + return; } - else { - println("Packet header mismatch. Expected 1, got " + data[0]); + + if (newImageQueue.size() > 0) { + println("Buffer full, dropping frame!"); + return; + } + + color[] newImage = new color[strips*lights_per_strip]; + + 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])); + } + + try { + newImageQueue.put(newImage); + } + catch( InterruptedException e ) { + println("Interrupted Exception caught"); } } @@ -92,7 +114,6 @@ color[] MakeDemoFrame() { else { imageData[i] = color(0, 0, 0); } - newData = true; } //animationStep = (animationStep+1)%blinkeyLights.size(); animationStep = (animationStep + 1)%10; @@ -106,10 +127,11 @@ void draw() { blinkeyLights.update(imageData); imageHud.update(imageData); } - else if (newData) { + else if (newImageQueue.size() > 0) { + color[] newImage = (color[]) newImageQueue.poll(); + blinkeyLights.update(newImage); imageHud.update(newImage); - newData = false; } background(0); @@ -135,9 +157,15 @@ void draw() { dome.draw(); blinkeyLights.draw(); - - noLights(); hud.draw(); imageHud.draw(); + + pCamera.beginHUD(); + noLights(); + fill(255,255,255); + textFont(font); + textAlign(CENTER); + text(int(frameRate),width - 50, height - 50); + pCamera.endHUD(); } diff --git a/BlinkeyLight.pde b/BlinkeyLight.pde index 579cc74..0186e64 100644 --- a/BlinkeyLight.pde +++ b/BlinkeyLight.pde @@ -23,7 +23,10 @@ class BlinkeyLight { stroke(c); fill(c); scale(rad); - ellipse(0,0,1.5,1.5); + rect(-.5,-.5,.5,.5); + //ellipse(0,0,1.5,1.5); + //sphereDetail(3); + //sphere(.3); popMatrix(); } }