From: Mark Slee Date: Fri, 28 Jun 2013 19:01:04 +0000 (-0700) Subject: Add mouse scroll to zoom X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bda5421da267a18ee8bf80d54f4daf12c56c1a8d;p=SugarCubes.git Add mouse scroll to zoom --- diff --git a/_Internals.pde b/_Internals.pde index 7936724..3bf4d31 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -55,8 +55,7 @@ boolean pandaBoardsEnabled = false; boolean debugMode = false; // Camera variables -final float eyeR = -270; -float eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ; +float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ; void setup() { startMillis = lastMillis = millis(); @@ -107,10 +106,16 @@ void setup() { midX = glucose.model.xMax/2 + 20; midY = glucose.model.yMax/2; midZ = glucose.model.zMax/2; + eyeR = -270; eyeA = .15; eyeY = midY + 20; eyeX = midX + eyeR*sin(eyeA); eyeZ = midZ + eyeR*cos(eyeA); + addMouseWheelListener(new java.awt.event.MouseWheelListener() { + public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) { + mouseWheel(mwe.getWheelRotation()); + }}); + println("Total setup: " + (millis() - startMillis) + "ms"); println("Hit the 'p' key to toggle Panda Board output"); @@ -270,4 +275,10 @@ void mouseReleased() { ui.mouseReleased(); } } + +void mouseWheel(int delta) { + eyeR = constrain(eyeR - delta, -500, -80); + eyeX = midX + eyeR*sin(eyeA); + eyeZ = midZ + eyeR*cos(eyeA); +}