Performance improvements to SineSpheres and 's' to toggle simulation
[SugarCubes.git] / _Internals.pde
CommitLineData
49815cc0 1/**
1ecdb44a
MS
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
d12e46b6 7 * \\// \\// \\// \\//H
1ecdb44a
MS
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
49815cc0
MS
11 * If you are an artist, you may ignore this file! It just sets
12 * up the framework to run the patterns. Should not need modification
13 * for general animation work.
14 */
15
16import glucose.*;
17import glucose.control.*;
3f8be614 18import glucose.effect.*;
f3f5a876 19import glucose.model.*;
49815cc0 20import glucose.pattern.*;
f3f5a876 21import glucose.transform.*;
49815cc0 22import glucose.transition.*;
49815cc0 23import heronarts.lx.*;
3f8be614 24import heronarts.lx.control.*;
49815cc0 25import heronarts.lx.effect.*;
49815cc0 26import heronarts.lx.modulator.*;
f3f5a876 27import heronarts.lx.pattern.*;
49815cc0
MS
28import heronarts.lx.transition.*;
29import ddf.minim.*;
30import ddf.minim.analysis.*;
31import processing.opengl.*;
5d70e4d7 32import rwmidi.*;
24fc0330 33import java.lang.reflect.*;
49815cc0
MS
34
35final int VIEWPORT_WIDTH = 900;
36final int VIEWPORT_HEIGHT = 700;
0e3c5542 37
92c06c97 38// The trailer is measured from the outside of the black metal (but not including the higher welded part on the front)
87998ff3
MS
39final float TRAILER_WIDTH = 240;
40final float TRAILER_DEPTH = 97;
41final float TRAILER_HEIGHT = 33;
42
41f26e8f 43final int MaxCubeHeight = 5;
41c436e4 44final int NumBackTowers = 11;
7e3329d2 45
51d0d59a 46int targetFramerate = 60;
49815cc0 47int startMillis, lastMillis;
a898d79b
MS
48
49// Core engine variables
49815cc0 50GLucose glucose;
d12e46b6 51LX lx;
49815cc0 52LXPattern[] patterns;
24fc0330 53Effects effects;
a898d79b 54MappingTool mappingTool;
79ae8245 55PandaDriver[] pandaBoards;
e0794d3a 56PresetManager presetManager;
1f974cbc 57MidiEngine midiEngine;
a898d79b
MS
58
59// Display configuration mode
bf551144 60boolean mappingMode = false;
cc9fcf4b 61boolean debugMode = false;
554e38ff 62DebugUI debugUI;
34327c96 63boolean uiOn = true;
f8295971 64boolean simulationOn = true;
34327c96 65LXPattern restoreToPattern = null;
4c640acc 66PImage logo;
a41f334c 67float[] hsb = new float[3];
d626bc9b 68
a898d79b 69// Handles to UI objects
d626bc9b
MS
70UIContext[] overlays;
71UIPatternDeck uiPatternA;
a898d79b 72UICrossfader uiCrossfader;
a8d55ade 73UIMidi uiMidi;
d626bc9b
MS
74UIMapping uiMapping;
75UIDebugText uiDebugText;
fa4f822d 76UISpeed uiSpeed;
cc9fcf4b 77
0a9f99cc 78// Camera variables
bda5421d 79float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ;
0a9f99cc 80
34327c96
MS
81/**
82 * Engine construction and initialization.
83 */
d1dcc4b5
MS
84
85LXTransition _transition(GLucose glucose) {
86 return new DissolveTransition(glucose.lx).setDuration(1000);
87}
88
89LXPattern[] _leftPatterns(GLucose glucose) {
d626bc9b
MS
90 LXPattern[] patterns = patterns(glucose);
91 for (LXPattern p : patterns) {
d1dcc4b5 92 p.setTransition(_transition(glucose));
d626bc9b
MS
93 }
94 return patterns;
95}
96
d1dcc4b5
MS
97LXPattern[] _rightPatterns(GLucose glucose) {
98 LXPattern[] patterns = _leftPatterns(glucose);
99 LXPattern[] rightPatterns = new LXPattern[patterns.length+1];
100 int i = 0;
101 rightPatterns[i++] = new BlankPattern(glucose).setTransition(_transition(glucose));
102 for (LXPattern p : patterns) {
103 rightPatterns[i++] = p;
104 }
105 return rightPatterns;
106}
24fc0330
MS
107
108LXEffect[] _effectsArray(Effects effects) {
109 List<LXEffect> effectList = new ArrayList<LXEffect>();
110 for (Field f : effects.getClass().getDeclaredFields()) {
111 try {
112 Object val = f.get(effects);
113 if (val instanceof LXEffect) {
114 effectList.add((LXEffect)val);
115 }
116 } catch (IllegalAccessException iax) {}
117 }
118 return effectList.toArray(new LXEffect[]{});
119}
d1dcc4b5 120
34327c96
MS
121void logTime(String evt) {
122 int now = millis();
123 println(evt + ": " + (now - lastMillis) + "ms");
124 lastMillis = now;
125}
126
49815cc0
MS
127void setup() {
128 startMillis = lastMillis = millis();
129
130 // Initialize the Processing graphics environment
131 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
0e3c5542 132 frameRate(targetFramerate);
3f8be614 133 noSmooth();
49815cc0
MS
134 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
135 logTime("Created viewport");
136
137 // Create the GLucose engine to run the cubes
186bc4d3 138 glucose = new GLucose(this, buildModel());
49815cc0 139 lx = glucose.lx;
cc9fcf4b 140 lx.enableKeyboardTempo();
49815cc0
MS
141 logTime("Built GLucose engine");
142
143 // Set the patterns
42a424d7 144 LXEngine engine = lx.engine;
d1dcc4b5
MS
145 engine.setPatterns(patterns = _leftPatterns(glucose));
146 engine.addDeck(_rightPatterns(glucose));
49815cc0 147 logTime("Built patterns");
a898d79b
MS
148 glucose.setTransitions(transitions(glucose));
149 logTime("Built transitions");
24fc0330 150 glucose.lx.addEffects(_effectsArray(effects = new Effects()));
49815cc0 151 logTime("Built effects");
4214e9a2 152
e0794d3a
MS
153 // Preset manager
154 presetManager = new PresetManager();
155 logTime("Loaded presets");
4214e9a2 156
1f974cbc
MS
157 // MIDI devices
158 midiEngine = new MidiEngine();
1f974cbc
MS
159 logTime("Setup MIDI devices");
160
e73ef85d 161 // Build output driver
186bc4d3 162 PandaMapping[] pandaMappings = buildPandaList();
45f43cc2
MS
163 pandaBoards = new PandaDriver[pandaMappings.length];
164 int pbi = 0;
165 for (PandaMapping pm : pandaMappings) {
44b8de9c 166 pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
45f43cc2
MS
167 }
168 mappingTool = new MappingTool(glucose, pandaMappings);
169 logTime("Built PandaDriver");
a8d55ade 170
49815cc0 171 // Build overlay UI
45f43cc2 172 debugUI = new DebugUI(pandaMappings);
d626bc9b 173 overlays = new UIContext[] {
42a424d7 174 uiPatternA = new UIPatternDeck(lx.engine.getDeck(GLucose.LEFT_DECK), "PATTERN A", 4, 4, 140, 324),
a8d55ade
MS
175 new UIBlendMode(4, 332, 140, 86),
176 new UIEffects(4, 422, 140, 144),
177 new UITempo(4, 570, 140, 50),
fa4f822d 178 uiSpeed = new UISpeed(4, 624, 140, 50),
a8d55ade 179
42a424d7 180 new UIPatternDeck(lx.engine.getDeck(GLucose.RIGHT_DECK), "PATTERN B", width-144, 4, 140, 324),
d6ac1ee8 181 uiMidi = new UIMidi(midiEngine, width-144, 332, 140, 158),
4df91daf 182 new UIOutput(width-144, 494, 140, 106),
d626bc9b 183
a8d55ade 184 uiCrossfader = new UICrossfader(width/2-90, height-90, 180, 86),
d626bc9b 185
a8d55ade
MS
186 uiDebugText = new UIDebugText(148, height-138, width-304, 44),
187 uiMapping = new UIMapping(mappingTool, 4, 4, 140, 324),
d626bc9b
MS
188 };
189 uiMapping.setVisible(false);
49815cc0 190 logTime("Built overlay UI");
4c640acc
MS
191
192 // Load logo image
193 logo = loadImage("data/logo.png");
194
0a9f99cc 195 // Setup camera
d626bc9b 196 midX = TRAILER_WIDTH/2.;
0a9f99cc 197 midY = glucose.model.yMax/2;
e0cea600
MS
198 midZ = TRAILER_DEPTH/2.;
199 eyeR = -290;
0a9f99cc 200 eyeA = .15;
d626bc9b 201 eyeY = midY + 70;
0a9f99cc
MS
202 eyeX = midX + eyeR*sin(eyeA);
203 eyeZ = midZ + eyeR*cos(eyeA);
d6ac1ee8
MS
204
205 // Add mouse scrolling event support
bda5421d
MS
206 addMouseWheelListener(new java.awt.event.MouseWheelListener() {
207 public void mouseWheelMoved(java.awt.event.MouseWheelEvent mwe) {
208 mouseWheel(mwe.getWheelRotation());
209 }});
210
49815cc0 211 println("Total setup: " + (millis() - startMillis) + "ms");
e73ef85d 212 println("Hit the 'p' key to toggle Panda Board output");
49815cc0
MS
213}
214
34327c96
MS
215/**
216 * Core render loop and drawing functionality.
217 */
49815cc0 218void draw() {
0a9f99cc
MS
219 // Draws the simulation and the 2D UI overlay
220 background(40);
a898d79b 221
19d16a16
MS
222 color[] simulationColors;
223 color[] sendColors;
224 simulationColors = sendColors = glucose.getColors();
a898d79b 225 String displayMode = uiCrossfader.getDisplayMode();
d626bc9b 226 if (displayMode == "A") {
6b3d53ca 227 simulationColors = lx.engine.getDeck(GLucose.LEFT_DECK).getColors();
d626bc9b 228 } else if (displayMode == "B") {
6b3d53ca 229 simulationColors = lx.engine.getDeck(GLucose.RIGHT_DECK).getColors();
d626bc9b 230 }
554e38ff 231 if (debugMode) {
19d16a16
MS
232 debugUI.maskColors(simulationColors);
233 debugUI.maskColors(sendColors);
554e38ff 234 }
51d0d59a 235
f8295971
MS
236 if (simulationOn) {
237 drawSimulation(simulationColors);
238 }
239
240 // 2D Overlay UI
241 drawUI();
242
243 // Gamma correction here. Apply a cubic to the brightness
244 // for better representation of dynamic range
245 for (int i = 0; i < sendColors.length; ++i) {
246 lx.RGBtoHSB(sendColors[i], hsb);
247 float b = hsb[2];
248 sendColors[i] = lx.hsb(360.*hsb[0], 100.*hsb[1], 100.*(b*b*b));
249 }
250
251 // TODO(mcslee): move into GLucose engine
252 for (PandaDriver p : pandaBoards) {
253 p.send(sendColors);
254 }
255}
256
257void drawSimulation(color[] simulationColors) {
258 camera(
0a9f99cc
MS
259 eyeX, eyeY, eyeZ,
260 midX, midY, midZ,
261 0, -1, 0
262 );
51d0d59a 263
a8d55ade 264 translate(0, 40, 0);
d626bc9b 265
51d0d59a
MS
266 noStroke();
267 fill(#141414);
87998ff3 268 drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
51d0d59a
MS
269 fill(#070707);
270 stroke(#222222);
0a9f99cc 271 beginShape();
51d0d59a 272 vertex(0, 0, 0);
87998ff3
MS
273 vertex(TRAILER_WIDTH, 0, 0);
274 vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
275 vertex(0, 0, TRAILER_DEPTH);
51d0d59a 276 endShape();
4c640acc
MS
277
278 // Draw the logo on the front of platform
279 pushMatrix();
280 translate(0, 0, -1);
281 float s = .07;
282 scale(s, -s, s);
283 image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s);
284 popMatrix();
0a9f99cc 285
51d0d59a 286 noStroke();
e89eda9f
MS
287 if (glucose.model.bassBox.exists) {
288 drawBassBox(glucose.model.bassBox, false);
289 }
290 for (Speaker speaker : glucose.model.speakers) {
291 drawSpeaker(speaker);
292 }
51d0d59a
MS
293 for (Cube c : glucose.model.cubes) {
294 drawCube(c);
295 }
296
0a9f99cc
MS
297 noFill();
298 strokeWeight(2);
299 beginShape(POINTS);
e89eda9f 300 for (Point p : glucose.model.points) {
19d16a16 301 stroke(simulationColors[p.index]);
190d91c2 302 vertex(p.x, p.y, p.z);
0a9f99cc
MS
303 }
304 endShape();
49815cc0
MS
305}
306
e89eda9f
MS
307void drawBassBox(BassBox b, boolean hasSub) {
308
92c06c97 309 float in = .15;
e89eda9f
MS
310
311 if (hasSub) {
312 noStroke();
313 fill(#191919);
314 pushMatrix();
315 translate(b.x + BassBox.EDGE_WIDTH/2., b.y + BassBox.EDGE_HEIGHT/2, b.z + BassBox.EDGE_DEPTH/2.);
316 box(BassBox.EDGE_WIDTH-20*in, BassBox.EDGE_HEIGHT-20*in, BassBox.EDGE_DEPTH-20*in);
317 popMatrix();
318 }
e76480d4
MS
319
320 noStroke();
321 fill(#393939);
92c06c97
MS
322 drawBox(b.x+in, b.y+in, b.z+in, 0, 0, 0, BassBox.EDGE_WIDTH-in*2, BassBox.EDGE_HEIGHT-in*2, BassBox.EDGE_DEPTH-in*2, Cube.CHANNEL_WIDTH-in);
323
39011e7e
MS
324 pushMatrix();
325 translate(b.x+(Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT-in, b.z + BassBox.EDGE_DEPTH/2.);
326 float lastOffset = 0;
327 for (float offset : BoothFloor.STRIP_OFFSETS) {
328 translate(offset - lastOffset, 0, 0);
329 box(Cube.CHANNEL_WIDTH-in, 0, BassBox.EDGE_DEPTH - 2*in);
330 lastOffset = offset;
331 }
332 popMatrix();
333
92c06c97
MS
334 pushMatrix();
335 translate(b.x + (Cube.CHANNEL_WIDTH-in)/2., b.y + BassBox.EDGE_HEIGHT/2., b.z + in);
336 for (int j = 0; j < 2; ++j) {
337 pushMatrix();
338 for (int i = 0; i < BassBox.NUM_FRONT_STRUTS; ++i) {
339 translate(BassBox.FRONT_STRUT_SPACING, 0, 0);
340 box(Cube.CHANNEL_WIDTH-in, BassBox.EDGE_HEIGHT - in*2, 0);
341 }
342 popMatrix();
343 translate(0, 0, BassBox.EDGE_DEPTH - 2*in);
344 }
345 popMatrix();
346
347 pushMatrix();
348 translate(b.x + in, b.y + BassBox.EDGE_HEIGHT/2., b.z + BassBox.SIDE_STRUT_SPACING + (Cube.CHANNEL_WIDTH-in)/2.);
349 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
350 translate(BassBox.EDGE_WIDTH-2*in, 0, 0);
351 box(0, BassBox.EDGE_HEIGHT - in*2, Cube.CHANNEL_WIDTH-in);
ab77005f 352 popMatrix();
e76480d4 353
92c06c97
MS
354}
355
51d0d59a 356void drawCube(Cube c) {
254d34c0 357 float in = .15;
e76480d4
MS
358 noStroke();
359 fill(#393939);
254d34c0 360 drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in);
51d0d59a
MS
361}
362
e76480d4
MS
363void drawSpeaker(Speaker s) {
364 float in = .15;
365
366 noStroke();
367 fill(#191919);
368 pushMatrix();
369 translate(s.x, s.y, s.z);
370 rotate(s.ry / 180. * PI, 0, -1, 0);
371 translate(Speaker.EDGE_WIDTH/2., Speaker.EDGE_HEIGHT/2., Speaker.EDGE_DEPTH/2.);
372 box(Speaker.EDGE_WIDTH-20*in, Speaker.EDGE_HEIGHT-20*in, Speaker.EDGE_DEPTH-20*in);
254fbb68
MS
373 translate(0, Speaker.EDGE_HEIGHT/2. + Speaker.EDGE_HEIGHT*.8/2, 0);
374
375 fill(#222222);
376 box(Speaker.EDGE_WIDTH*.6, Speaker.EDGE_HEIGHT*.8, Speaker.EDGE_DEPTH*.75);
e76480d4
MS
377 popMatrix();
378
e76480d4
MS
379 noStroke();
380 fill(#393939);
381 drawBox(s.x+in, s.y+in, s.z+in, 0, s.ry, 0, Speaker.EDGE_WIDTH-in*2, Speaker.EDGE_HEIGHT-in*2, Speaker.EDGE_DEPTH-in*2, Cube.CHANNEL_WIDTH-in);
ab77005f 382}
e76480d4 383
51d0d59a
MS
384void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
385 pushMatrix();
386 translate(x, y, z);
e0cea600 387 rotate(rx / 180. * PI, -1, 0, 0);
51d0d59a 388 rotate(ry / 180. * PI, 0, -1, 0);
e0cea600 389 rotate(rz / 180. * PI, 0, 0, -1);
51d0d59a
MS
390 for (int i = 0; i < 4; ++i) {
391 float wid = (i % 2 == 0) ? xd : zd;
392
393 beginShape();
394 vertex(0, 0);
395 vertex(wid, 0);
396 vertex(wid, yd);
397 vertex(wid - sw, yd);
398 vertex(wid - sw, sw);
399 vertex(0, sw);
400 endShape();
401 beginShape();
402 vertex(0, sw);
403 vertex(0, yd);
404 vertex(wid - sw, yd);
405 vertex(wid - sw, yd - sw);
406 vertex(sw, yd - sw);
407 vertex(sw, sw);
408 endShape();
409
410 translate(wid, 0, 0);
411 rotate(HALF_PI, 0, -1, 0);
412 }
413 popMatrix();
414}
415
49815cc0 416void drawUI() {
d626bc9b
MS
417 camera();
418 javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
419 gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
420 ((PGraphicsOpenGL)g).endGL();
421 strokeWeight(1);
422
49815cc0 423 if (uiOn) {
d626bc9b
MS
424 for (UIContext context : overlays) {
425 context.draw();
426 }
427 }
428
429 // Always draw FPS meter
430 fill(#555555);
431 textSize(9);
432 textAlign(LEFT, BASELINE);
433 text("FPS: " + ((int) (frameRate*10)) / 10. + " / " + targetFramerate + " (-/+)", 4, height-4);
434
435 if (debugMode) {
436 debugUI.draw();
49815cc0 437 }
49815cc0
MS
438}
439
4c640acc 440
34327c96
MS
441/**
442 * Top-level keyboard event handling
443 */
49815cc0 444void keyPressed() {
bf551144 445 if (mappingMode) {
d626bc9b 446 mappingTool.keyPressed(uiMapping);
bf551144 447 }
3f8be614 448 switch (key) {
2b068dd5
MS
449 case '1':
450 case '2':
451 case '3':
452 case '4':
453 case '5':
454 case '6':
455 case '7':
456 case '8':
457 if (!midiEngine.isQwertyEnabled()) {
458 presetManager.select(midiEngine.getFocusedDeck(), key - '1');
459 }
460 break;
461
462 case '!':
463 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 0);
464 break;
465 case '@':
466 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 1);
467 break;
468 case '#':
469 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 2);
470 break;
471 case '$':
472 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 3);
473 break;
474 case '%':
475 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 4);
476 break;
477 case '^':
478 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 5);
479 break;
480 case '&':
481 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 6);
482 break;
483 case '*':
484 if (!midiEngine.isQwertyEnabled()) presetManager.store(midiEngine.getFocusedDeck(), 7);
485 break;
486
0e3c5542
MS
487 case '-':
488 case '_':
489 frameRate(--targetFramerate);
490 break;
491 case '=':
492 case '+':
493 frameRate(++targetFramerate);
75e1ddde
MS
494 break;
495 case 'b':
24fc0330 496 effects.boom.trigger();
75e1ddde 497 break;
cc9fcf4b 498 case 'd':
d6ac1ee8 499 if (!midiEngine.isQwertyEnabled()) {
a8d55ade
MS
500 debugMode = !debugMode;
501 println("Debug output: " + (debugMode ? "ON" : "OFF"));
502 }
554e38ff 503 break;
bf551144 504 case 'm':
d6ac1ee8 505 if (!midiEngine.isQwertyEnabled()) {
a8d55ade
MS
506 mappingMode = !mappingMode;
507 uiPatternA.setVisible(!mappingMode);
508 uiMapping.setVisible(mappingMode);
509 if (mappingMode) {
510 restoreToPattern = lx.getPattern();
511 lx.setPatterns(new LXPattern[] { mappingTool });
512 } else {
513 lx.setPatterns(patterns);
514 LXTransition pop = restoreToPattern.getTransition();
515 restoreToPattern.setTransition(null);
516 lx.goPattern(restoreToPattern);
517 restoreToPattern.setTransition(pop);
518 }
bf551144
MS
519 }
520 break;
19d16a16
MS
521 case 't':
522 if (!midiEngine.isQwertyEnabled()) {
523 lx.engine.setThreaded(!lx.engine.isThreaded());
524 }
525 break;
e73ef85d 526 case 'p':
79ae8245
MS
527 for (PandaDriver p : pandaBoards) {
528 p.toggle();
529 }
cc9fcf4b 530 break;
f8295971
MS
531 case 's':
532 if (!midiEngine.isQwertyEnabled()) {
533 simulationOn = !simulationOn;
534 }
535 break;
3f8be614 536 case 'u':
d6ac1ee8 537 if (!midiEngine.isQwertyEnabled()) {
4df91daf
MS
538 uiOn = !uiOn;
539 }
3f8be614 540 break;
49815cc0
MS
541 }
542}
543
34327c96
MS
544/**
545 * Top-level mouse event handling
546 */
0a9f99cc 547int mx, my;
0a9f99cc 548void mousePressed() {
d626bc9b
MS
549 boolean debugged = false;
550 if (debugMode) {
551 debugged = debugUI.mousePressed();
552 }
553 if (!debugged) {
554 for (UIContext context : overlays) {
555 context.mousePressed(mouseX, mouseY);
556 }
0a9f99cc 557 }
d626bc9b
MS
558 mx = mouseX;
559 my = mouseY;
0a9f99cc
MS
560}
561
562void mouseDragged() {
d626bc9b
MS
563 boolean dragged = false;
564 for (UIContext context : overlays) {
565 dragged |= context.mouseDragged(mouseX, mouseY);
566 }
567 if (!dragged) {
0a9f99cc
MS
568 int dx = mouseX - mx;
569 int dy = mouseY - my;
570 mx = mouseX;
571 my = mouseY;
572 eyeA += dx*.003;
573 eyeX = midX + eyeR*sin(eyeA);
574 eyeZ = midZ + eyeR*cos(eyeA);
575 eyeY += dy;
576 }
577}
578
579void mouseReleased() {
d626bc9b
MS
580 for (UIContext context : overlays) {
581 context.mouseReleased(mouseX, mouseY);
582 }
0a9f99cc 583}
73687629 584
a0140e21 585void mouseWheel(int delta) {
d626bc9b
MS
586 boolean wheeled = false;
587 for (UIContext context : overlays) {
588 wheeled |= context.mouseWheel(mouseX, mouseY, delta);
589 }
590
591 if (!wheeled) {
0ba6ac44
MS
592 eyeR = constrain(eyeR - delta, -500, -80);
593 eyeX = midX + eyeR*sin(eyeA);
594 eyeZ = midZ + eyeR*cos(eyeA);
595 }
bda5421d 596}