Normand Briere
2019-11-07 f868664f7e7626f651e6ade9c9f6863851ef43b7
Camera.java
....@@ -52,7 +52,7 @@
5252 perspective = true;
5353 break;
5454 case 1: // '\001'
55
- location = LA.newVector(4, 0, 0);
55
+ location = LA.newVector(0, 0, 4); // Needed for translation direction
5656 perspective = false;
5757 break;
5858 case 2: // '\002'
....@@ -63,7 +63,7 @@
6363 //LA.matXRotate(fromScreen, LA.toRadians(90));
6464 break;
6565 case 3: // '\003'
66
- location = LA.newVector(0, 0, 4);
66
+ location = LA.newVector(4, 0, 0); // Needed for translation direction
6767 //LA.matZRotate(toScreen, LA.toRadians(-90));
6868 //LA.matXRotate(toScreen, LA.toRadians(-90));
6969 //LA.matXRotate(fromScreen, LA.toRadians(90));
....@@ -160,6 +160,11 @@
160160 {
161161 if(hAspect != 0) return;
162162
163
+ if (CameraPane.IMAGEFLIP)
164
+ {
165
+ dx = -dx;
166
+ }
167
+
163168 if (CameraPane.ROTATECAMERA)
164169 {
165170 float t = dx;
....@@ -216,6 +221,11 @@
216221 void Translate(float dx, float dy, float scale)
217222 {
218223 if(hAspect != 0) return;
224
+
225
+ if (CameraPane.IMAGEFLIP)
226
+ {
227
+ dx = -dx;
228
+ }
219229
220230 if (CameraPane.ROTATECAMERA)
221231 {
....@@ -276,11 +286,11 @@
276286 if (scale == 0)
277287 {
278288 // Zoom
289
+ double factor = Math.exp(-dy/300.0); // (1 + dy/100);
290
+
279291 LA.vecSub(location, lookAt, location);
280292
281293 cVector p = location;
282
-
283
- double factor = Math.exp(-dy/300.0); // (1 + dy/100);
284294
285295 p.x *= factor;
286296 p.y *= factor;
....@@ -293,7 +303,7 @@
293303 LA.vecSub(location, lookAt, direction);
294304
295305 //scale /= Distance();
296
- scale /= shaper_fovy/20;
306
+ // scale /= shaper_fovy/20;
297307
298308 location.x -= dy * direction.x / scale;
299309 //location.y -= dy * direction.y / scale;
....@@ -314,21 +324,37 @@
314324
315325 void RotateInterest(float dx, float dy)
316326 {
327
+ right.mul(-1);
328
+
317329 cStatic.point1.set(location);
318330 location.set(lookAt);
319331 lookAt.set(cStatic.point1);
320
- 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
+ }
321339 // UP.mul(-1);
322340
323341 RotatePosition(dx,-dy);
324342
325343 // UP.mul(-1);
326344 right.mul(-1);
345
+
327346 cStatic.point1.set(location);
328347 location.set(lookAt);
329348 lookAt.set(cStatic.point1);
330349
331
- //computeTransform();
350
+ if (viewCode == 0 && locationBuf != null)
351
+ {
352
+ cStatic.point1.set(locationBuf);
353
+ locationBuf.set(lookAtBuf);
354
+ lookAtBuf.set(cStatic.point1);
355
+ }
356
+
357
+ computeTransform();
332358 }
333359
334360 //synchronized // june 2014
....@@ -341,33 +367,85 @@
341367 fromScreen = LA.newMatrix();
342368 }
343369
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
+
344420 cVector up2 = up;
345421 cVector right2 = right;
346422
347
- up2.x = UP.x;
348
- up2.y = UP.y;
349
- up2.z = UP.z;
350
- 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);
351427 LA.vecNormalize(away);
352428 LA.vecCross(away, up2, right2);
353429 if (right2.length2() < 0.0001)
354430 {
431
+ //System.out.println("right2.length2() < 0.0001");
355432 // UP failed
356433 up2.x = UP2.x;
357434 up2.y = UP2.y;
358435 up2.z = UP2.z;
359
- LA.vecSub(lookAt, location, away);
360
- LA.vecNormalize(away);
361436 LA.vecCross(away, up2, right2);
362437 if (!(right2.length2() > 0))
363438 {
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
+
364444 // old problem...
365445 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
366446 up2.x = UP.x = 0;
367447 up2.y = UP.y = 1;
368448 up2.z = UP.z = 0;
369
- LA.vecSub(lookAt, location, away);
370
- LA.vecNormalize(away);
371449 LA.vecCross(away, up2, right2);
372450 }
373451 }
....@@ -390,10 +468,10 @@
390468 }
391469
392470 for (int i=0; i < 3; i++)
393
- fromScreen[3][i] = location.get(i);
471
+ fromScreen[3][i] = locationBuf.get(i);
394472
395473 for (int i=0; i < 3; i++)
396
- temp[3][i] = -location.get(i);
474
+ temp[3][i] = -locationBuf.get(i);
397475
398476 LA.matConcat(temp, toScreen, toScreen);
399477
....@@ -405,9 +483,16 @@
405483 LA.matConcat(fromScreen, rotate, fromScreen);
406484 //LA.matConcat(toScreen, rotate_1, toScreen);
407485 }
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
+
408494 //if (this == CameraPane.lightCamera)
409495 //CameraPane.lighttouched = true;
410
-
411496 LA.matInvert(fromScreen, toScreen);
412497 }
413498
....@@ -473,11 +558,20 @@
473558 static final int viewFront = 2;
474559 static final int viewSide = 3;
475560 int viewCode;
561
+
476562 cVector location;
477563 cVector lookAt;
564
+
565
+ transient cVector locationBuf;
566
+ transient cVector lookAtBuf;
567
+ transient cVector upBuf;
568
+ //transient cVector up2Buf;
569
+
478570 cVector direction;
479
- double toScreen[][];
480
- double fromScreen[][];
571
+
572
+ double[][] toScreen;
573
+ double[][] fromScreen;
574
+
481575 boolean perspective;
482576 int hAspect = 0; // Free camera
483577 int vAspect;