Normand Briere
2019-11-07 f868664f7e7626f651e6ade9c9f6863851ef43b7
Camera.java
....@@ -3,7 +3,6 @@
33 // Decompiler options: packimports(3)
44 // Source File Name: Camera.java
55
6
-
76 class Camera extends Object3D
87 {
98 static final long serialVersionUID = 4754289789178680517L;
....@@ -21,7 +20,7 @@
2120 //<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6>
2221 // location = LA.newVector(2,0.7,-2);
2322 // lookAt = new cVector(0.6,0.3,-0.6);
24
- location = LA.newVector(3,2,2);
23
+ location = LA.newVector(6,2,4);
2524 lookAt = new cVector(0.0,0.5,0);
2625 direction = new cVector();
2726 toParent = LA.newMatrix();
....@@ -53,7 +52,7 @@
5352 perspective = true;
5453 break;
5554 case 1: // '\001'
56
- location = LA.newVector(0, 0, 4);
55
+ location = LA.newVector(0, 0, 4); // Needed for translation direction
5756 perspective = false;
5857 break;
5958 case 2: // '\002'
....@@ -64,7 +63,7 @@
6463 //LA.matXRotate(fromScreen, LA.toRadians(90));
6564 break;
6665 case 3: // '\003'
67
- location = LA.newVector(4, 0, 0);
66
+ location = LA.newVector(4, 0, 0); // Needed for translation direction
6867 //LA.matZRotate(toScreen, LA.toRadians(-90));
6968 //LA.matXRotate(toScreen, LA.toRadians(-90));
7069 //LA.matXRotate(fromScreen, LA.toRadians(90));
....@@ -72,7 +71,7 @@
7271 perspective = false;
7372 break;
7473 case 4: // Default light
75
- location = LA.newVector(10, 30, 20);
74
+ location = LA.newVector(-5, 15, 10);
7675 perspective = false;
7776 break;
7877 }
....@@ -105,6 +104,15 @@
105104 focalLength = 1;
106105 setAspect(4, 3);
107106 background = LA.newVector(0.8, 0.8, 0.8);
107
+ }
108
+
109
+ void CreateMaterial(boolean multiply)
110
+ {
111
+ super.CreateMaterial(multiply);
112
+
113
+ material.shift = 90;
114
+ material.cameralight = 0.2f;
115
+ material.shadowbias = 10;
108116 }
109117
110118 void setAspect(int width, int height)
....@@ -151,6 +159,11 @@
151159 void RotatePosition(float dx, float dy)
152160 {
153161 if(hAspect != 0) return;
162
+
163
+ if (CameraPane.IMAGEFLIP)
164
+ {
165
+ dx = -dx;
166
+ }
154167
155168 if (CameraPane.ROTATECAMERA)
156169 {
....@@ -208,6 +221,11 @@
208221 void Translate(float dx, float dy, float scale)
209222 {
210223 if(hAspect != 0) return;
224
+
225
+ if (CameraPane.IMAGEFLIP)
226
+ {
227
+ dx = -dx;
228
+ }
211229
212230 if (CameraPane.ROTATECAMERA)
213231 {
....@@ -268,11 +286,11 @@
268286 if (scale == 0)
269287 {
270288 // Zoom
289
+ double factor = Math.exp(-dy/300.0); // (1 + dy/100);
290
+
271291 LA.vecSub(location, lookAt, location);
272292
273293 cVector p = location;
274
-
275
- double factor = Math.exp(-dy/300.0); // (1 + dy/100);
276294
277295 p.x *= factor;
278296 p.y *= factor;
....@@ -285,7 +303,7 @@
285303 LA.vecSub(location, lookAt, direction);
286304
287305 //scale /= Distance();
288
- scale /= shaper_fovy/20;
306
+ // scale /= shaper_fovy/20;
289307
290308 location.x -= dy * direction.x / scale;
291309 //location.y -= dy * direction.y / scale;
....@@ -306,19 +324,35 @@
306324
307325 void RotateInterest(float dx, float dy)
308326 {
327
+ right.mul(-1);
328
+
309329 cStatic.point1.set(location);
310330 location.set(lookAt);
311331 lookAt.set(cStatic.point1);
312
- right.mul(-1);
332
+
333
+ if (viewCode == 0 && locationBuf != null)
334
+ {
335
+ cStatic.point1.set(locationBuf);
336
+ locationBuf.set(lookAtBuf);
337
+ lookAtBuf.set(cStatic.point1);
338
+ }
313339 // UP.mul(-1);
314340
315341 RotatePosition(dx,-dy);
316342
317343 // UP.mul(-1);
318344 right.mul(-1);
345
+
319346 cStatic.point1.set(location);
320347 location.set(lookAt);
321348 lookAt.set(cStatic.point1);
349
+
350
+ if (viewCode == 0 && locationBuf != null)
351
+ {
352
+ cStatic.point1.set(locationBuf);
353
+ locationBuf.set(lookAtBuf);
354
+ lookAtBuf.set(cStatic.point1);
355
+ }
322356
323357 computeTransform();
324358 }
....@@ -333,33 +367,85 @@
333367 fromScreen = LA.newMatrix();
334368 }
335369
370
+ if (locationBuf == null)
371
+ {
372
+ locationBuf = new cVector();
373
+ locationBuf.set(location);
374
+ lookAtBuf = new cVector();
375
+ lookAtBuf.set(lookAt);
376
+ upBuf = new cVector();
377
+ upBuf.set(UP);
378
+// up2Buf = new cVector();
379
+// up2Buf.set(UP2);
380
+ }
381
+ else
382
+ {
383
+ double K = 0.25;
384
+
385
+ if (!CameraPane.capsLocked || CameraPane.ambientOcclusion)
386
+ K = 1;
387
+
388
+ locationBuf.y = location.y * K + locationBuf.y * (1 - K);
389
+ lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K);
390
+
391
+ int Y = 1;
392
+
393
+ if (UP.y < 0)
394
+ Y = -1;
395
+
396
+ UP.x = 0 * K + UP.x * (1 - K);
397
+ UP.y = Y * K + UP.y * (1 - K);
398
+ UP.z = 0 * K + UP.z * (1 - K);
399
+ UP.normalize();
400
+
401
+ if (CameraPane.capsLocked && !CameraPane.ambientOcclusion)
402
+ K = 0.1;
403
+
404
+ upBuf.x = UP.x * K + upBuf.x * (1 - K);
405
+ upBuf.y = UP.y * K + upBuf.y * (1 - K);
406
+ upBuf.z = UP.z * K + upBuf.z * (1 - K);
407
+ upBuf.normalize();
408
+// up2Buf.x = UP2.x * K + up2Buf.x * (1 - K);
409
+// up2Buf.y = UP2.y * K + up2Buf.y * (1 - K);
410
+// up2Buf.z = UP2.z * K + up2Buf.z * (1 - K);
411
+
412
+ K = 1;
413
+
414
+ locationBuf.x = location.x * K + locationBuf.x * (1 - K);
415
+ locationBuf.z = location.z * K + locationBuf.z * (1 - K);
416
+ lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K);
417
+ lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K);
418
+ }
419
+
336420 cVector up2 = up;
337421 cVector right2 = right;
338422
339
- up2.x = UP.x;
340
- up2.y = UP.y;
341
- up2.z = UP.z;
342
- LA.vecSub(lookAt, location, away);
423
+ up2.x = upBuf.x;
424
+ up2.y = upBuf.y;
425
+ up2.z = upBuf.z;
426
+ LA.vecSub(lookAtBuf, locationBuf, away);
343427 LA.vecNormalize(away);
344428 LA.vecCross(away, up2, right2);
345429 if (right2.length2() < 0.0001)
346430 {
431
+ //System.out.println("right2.length2() < 0.0001");
347432 // UP failed
348433 up2.x = UP2.x;
349434 up2.y = UP2.y;
350435 up2.z = UP2.z;
351
- LA.vecSub(lookAt, location, away);
352
- LA.vecNormalize(away);
353436 LA.vecCross(away, up2, right2);
354437 if (!(right2.length2() > 0))
355438 {
439
+ System.out.println("NO UP VECTOR: " + up2);
440
+ System.out.println("lookAtBuf: " + lookAtBuf);
441
+ System.out.println("locationBuf: " + locationBuf);
442
+ System.exit(0);
443
+
356444 // old problem...
357445 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
358446 up2.x = UP.x = 0;
359447 up2.y = UP.y = 1;
360448 up2.z = UP.z = 0;
361
- LA.vecSub(lookAt, location, away);
362
- LA.vecNormalize(away);
363449 LA.vecCross(away, up2, right2);
364450 }
365451 }
....@@ -382,23 +468,32 @@
382468 }
383469
384470 for (int i=0; i < 3; i++)
385
- fromScreen[3][i] = location.get(i);
471
+ fromScreen[3][i] = locationBuf.get(i);
386472
387473 for (int i=0; i < 3; i++)
388
- temp[3][i] = -location.get(i);
474
+ temp[3][i] = -locationBuf.get(i);
389475
390476 LA.matConcat(temp, toScreen, toScreen);
391477
392478 if (CameraPane.ROTATECAMERA)
393479 {
394480 double[][] rotate = { { 0,1,0,0 }, { -1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
395
- double[][] rotate_1 = { { 0,-1,0,0 }, { 1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
481
+ //double[][] rotate_1 = { { 0,-1,0,0 }, { 1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
396482
397
- LA.matConcat(rotate, fromScreen, fromScreen);
398
- LA.matConcat(toScreen, rotate_1, toScreen);
483
+ LA.matConcat(fromScreen, rotate, fromScreen);
484
+ //LA.matConcat(toScreen, rotate_1, toScreen);
399485 }
486
+
487
+ if (CameraPane.IMAGEFLIP)
488
+ {
489
+ double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
490
+
491
+ LA.matConcat(fromScreen, flip, fromScreen);
492
+ }
493
+
400494 //if (this == CameraPane.lightCamera)
401495 //CameraPane.lighttouched = true;
496
+ LA.matInvert(fromScreen, toScreen);
402497 }
403498
404499 // void Draw(CameraPane display, Object3D /*Composite*/ root, boolean selected)
....@@ -463,11 +558,20 @@
463558 static final int viewFront = 2;
464559 static final int viewSide = 3;
465560 int viewCode;
561
+
466562 cVector location;
467563 cVector lookAt;
564
+
565
+ transient cVector locationBuf;
566
+ transient cVector lookAtBuf;
567
+ transient cVector upBuf;
568
+ //transient cVector up2Buf;
569
+
468570 cVector direction;
469
- double toScreen[][];
470
- double fromScreen[][];
571
+
572
+ double[][] toScreen;
573
+ double[][] fromScreen;
574
+
471575 boolean perspective;
472576 int hAspect = 0; // Free camera
473577 int vAspect;