From: Mark Slee Date: Fri, 28 Jun 2013 18:44:00 +0000 (-0700) Subject: Overhaul GL rendering to use Processing primitives, much faster X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0a9f99cc0140d7ff58b5b900b4cc63b4266302a9;p=SugarCubes.git Overhaul GL rendering to use Processing primitives, much faster --- 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 fe2ba46..bffecfd 100644 Binary files a/code/GLucose.jar and b/code/GLucose.jar differ