From 0a9f99cc0140d7ff58b5b900b4cc63b4266302a9 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Fri, 28 Jun 2013 11:44:00 -0700 Subject: [PATCH] Overhaul GL rendering to use Processing primitives, much faster --- _Internals.pde | 83 ++++++++++++++++++++++++++++++++++++++++++++--- _Overlay.pde | 20 ------------ code/GLucose.jar | Bin 18788 -> 18737 bytes 3 files changed, 79 insertions(+), 24 deletions(-) diff --git a/_Internals.pde b/_Internals.pde index 5603698..7936724 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -34,7 +34,7 @@ import rwmidi.*; final int VIEWPORT_WIDTH = 900; final int VIEWPORT_HEIGHT = 700; -int targetFramerate = 30; +int targetFramerate = 45; int startMillis, lastMillis; GLucose glucose; @@ -54,6 +54,10 @@ boolean pandaBoardsEnabled = false; boolean debugMode = false; +// Camera variables +final float eyeR = -270; +float eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ; + void setup() { startMillis = lastMillis = millis(); @@ -99,6 +103,15 @@ void setup() { SCMidiDevices.initializeStandardDevices(glucose); logTime("Setup MIDI devices"); + // Setup camera + midX = glucose.model.xMax/2 + 20; + midY = glucose.model.yMax/2; + midZ = glucose.model.zMax/2; + eyeA = .15; + eyeY = midY + 20; + eyeX = midX + eyeR*sin(eyeA); + eyeZ = midZ + eyeR*cos(eyeA); + println("Total setup: " + (millis() - startMillis) + "ms"); println("Hit the 'p' key to toggle Panda Board output"); } @@ -128,12 +141,43 @@ void logTime(String evt) { } void draw() { - // The glucose engine deals with the core simulation here, we don't need - // to do anything specific. This method just needs to exist. + // Draws the simulation and the 2D UI overlay + background(40); + color[] colors = glucose.getColors(); + camera( + eyeX, eyeY, eyeZ, + midX, midY, midZ, + 0, -1, 0 + ); + stroke(#333333); + fill(#292929); + float yFloor = -3; + beginShape(); + vertex(0, yFloor, 0); + vertex(glucose.model.xMax, yFloor, 0); + vertex(glucose.model.xMax, yFloor, glucose.model.zMax); + vertex(0, yFloor, glucose.model.zMax); + endShape(CLOSE); + + noFill(); + strokeWeight(2); + beginShape(POINTS); + for (Point p : glucose.model.points) { + stroke(colors[p.index]); + vertex(p.fx, p.fy, p.fz); + } + endShape(); + + // 2D Overlay + camera(); + javax.media.opengl.GL gl= ((PGraphicsOpenGL)g).beginGL(); + gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT); + ((PGraphicsOpenGL)g).endGL(); + strokeWeight(1); + drawUI(); // TODO(mcslee): move into GLucose engine if (pandaBoardsEnabled) { - color[] colors = glucose.getColors(); pandaFront.send(colors); pandaRear.send(colors); } @@ -195,4 +239,35 @@ void keyPressed() { } } +int mx, my; + +void mousePressed() { + if (mouseX > ui.leftPos) { + ui.mousePressed(); + } else { + mx = mouseX; + my = mouseY; + } +} + +void mouseDragged() { + if (mouseX > ui.leftPos) { + ui.mouseDragged(); + } else { + int dx = mouseX - mx; + int dy = mouseY - my; + mx = mouseX; + my = mouseY; + eyeA += dx*.003; + eyeX = midX + eyeR*sin(eyeA); + eyeZ = midZ + eyeR*cos(eyeA); + eyeY += dy; + } +} + +void mouseReleased() { + if (mouseX > ui.leftPos) { + ui.mouseReleased(); + } +} diff --git a/_Overlay.pde b/_Overlay.pde index 827223a..5ee02a4 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -612,25 +612,5 @@ class MappingUI extends OverlayUI { } } - - -} - -void mousePressed() { - if (mouseX > ui.leftPos) { - ui.mousePressed(); - } -} - -void mouseReleased() { - if (mouseX > ui.leftPos) { - ui.mouseReleased(); - } -} - -void mouseDragged() { - if (mouseX > ui.leftPos) { - ui.mouseDragged(); - } } diff --git a/code/GLucose.jar b/code/GLucose.jar index fe2ba46acbc8c9023cc3456713fe752a021ebc5a..bffecfd5f58bf6d8f8a3ce5fc5996cd21278d41e 100644 GIT binary patch delta 2875 zcmZWrc|2768=k>fXYBjFgcvinp|NH#V<%ixLf5{GY%^J|%(W!46eqg&vZU-=QNkTV zev&9|$=XCB$uhE){22Xy_tU-S^EsdAJ(Zawr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