Normand Briere
2019-11-07 f868664f7e7626f651e6ade9c9f6863851ef43b7
Camera.java
....@@ -288,25 +288,15 @@
288288 // Zoom
289289 double factor = Math.exp(-dy/300.0); // (1 + dy/100);
290290
291
- if (viewCode != 0)
292
- {
293
- LA.vecSub(location, lookAt, location);
291
+ LA.vecSub(location, lookAt, location);
294292
295
- cVector p = location;
293
+ cVector p = location;
296294
297
- p.x *= factor;
298
- p.y *= factor;
299
- p.z *= factor;
295
+ p.x *= factor;
296
+ p.y *= factor;
297
+ p.z *= factor;
300298
301
- LA.vecAdd(location, lookAt, location);
302
- }
303
- else
304
- if (//shaper_fovy < 180 && factor > 1 ||
305
- shaper_fovy * factor < 150)
306
- {
307
- shaper_fovy *= factor;
308
- //System.out.println("fovy = " + shaper_fovy);
309
- }
299
+ LA.vecAdd(location, lookAt, location);
310300 }
311301 else
312302 {
....@@ -334,19 +324,35 @@
334324
335325 void RotateInterest(float dx, float dy)
336326 {
327
+ right.mul(-1);
328
+
337329 cStatic.point1.set(location);
338330 location.set(lookAt);
339331 lookAt.set(cStatic.point1);
340
- 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
+ }
341339 // UP.mul(-1);
342340
343341 RotatePosition(dx,-dy);
344342
345343 // UP.mul(-1);
346344 right.mul(-1);
345
+
347346 cStatic.point1.set(location);
348347 location.set(lookAt);
349348 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
+ }
350356
351357 computeTransform();
352358 }
....@@ -361,33 +367,85 @@
361367 fromScreen = LA.newMatrix();
362368 }
363369
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
+
364420 cVector up2 = up;
365421 cVector right2 = right;
366422
367
- up2.x = UP.x;
368
- up2.y = UP.y;
369
- up2.z = UP.z;
370
- 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);
371427 LA.vecNormalize(away);
372428 LA.vecCross(away, up2, right2);
373429 if (right2.length2() < 0.0001)
374430 {
431
+ //System.out.println("right2.length2() < 0.0001");
375432 // UP failed
376433 up2.x = UP2.x;
377434 up2.y = UP2.y;
378435 up2.z = UP2.z;
379
- LA.vecSub(lookAt, location, away);
380
- LA.vecNormalize(away);
381436 LA.vecCross(away, up2, right2);
382437 if (!(right2.length2() > 0))
383438 {
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
+
384444 // old problem...
385445 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
386446 up2.x = UP.x = 0;
387447 up2.y = UP.y = 1;
388448 up2.z = UP.z = 0;
389
- LA.vecSub(lookAt, location, away);
390
- LA.vecNormalize(away);
391449 LA.vecCross(away, up2, right2);
392450 }
393451 }
....@@ -410,10 +468,10 @@
410468 }
411469
412470 for (int i=0; i < 3; i++)
413
- fromScreen[3][i] = location.get(i);
471
+ fromScreen[3][i] = locationBuf.get(i);
414472
415473 for (int i=0; i < 3; i++)
416
- temp[3][i] = -location.get(i);
474
+ temp[3][i] = -locationBuf.get(i);
417475
418476 LA.matConcat(temp, toScreen, toScreen);
419477
....@@ -500,11 +558,20 @@
500558 static final int viewFront = 2;
501559 static final int viewSide = 3;
502560 int viewCode;
561
+
503562 cVector location;
504563 cVector lookAt;
564
+
565
+ transient cVector locationBuf;
566
+ transient cVector lookAtBuf;
567
+ transient cVector upBuf;
568
+ //transient cVector up2Buf;
569
+
505570 cVector direction;
571
+
506572 double[][] toScreen;
507573 double[][] fromScreen;
574
+
508575 boolean perspective;
509576 int hAspect = 0; // Free camera
510577 int vAspect;