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