Normand Briere
2019-09-18 f9325048496d7cdbcad233f8a6b84c88e79adcc2
Camera.java
....@@ -286,24 +286,34 @@
286286 if (scale == 0)
287287 {
288288 // Zoom
289
- LA.vecSub(location, lookAt, location);
290
-
291
- cVector p = location;
292
-
293289 double factor = Math.exp(-dy/300.0); // (1 + dy/100);
294290
295
- p.x *= factor;
296
- p.y *= factor;
297
- p.z *= factor;
291
+ if (viewCode != 0)
292
+ {
293
+ LA.vecSub(location, lookAt, location);
298294
299
- LA.vecAdd(location, lookAt, location);
295
+ cVector p = location;
296
+
297
+ p.x *= factor;
298
+ p.y *= factor;
299
+ p.z *= factor;
300
+
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
+ }
300310 }
301311 else
302312 {
303313 LA.vecSub(location, lookAt, direction);
304314
305315 //scale /= Distance();
306
- scale /= shaper_fovy/20;
316
+ // scale /= shaper_fovy/20;
307317
308318 location.x -= dy * direction.x / scale;
309319 //location.y -= dy * direction.y / scale;
....@@ -324,19 +334,29 @@
324334
325335 void RotateInterest(float dx, float dy)
326336 {
337
+ right.mul(-1);
338
+
327339 cStatic.point1.set(location);
328340 location.set(lookAt);
329341 lookAt.set(cStatic.point1);
330
- right.mul(-1);
342
+
343
+ cStatic.point1.set(locationBuf);
344
+ locationBuf.set(lookAtBuf);
345
+ lookAtBuf.set(cStatic.point1);
331346 // UP.mul(-1);
332347
333348 RotatePosition(dx,-dy);
334349
335350 // UP.mul(-1);
336351 right.mul(-1);
352
+
337353 cStatic.point1.set(location);
338354 location.set(lookAt);
339355 lookAt.set(cStatic.point1);
356
+
357
+ cStatic.point1.set(locationBuf);
358
+ locationBuf.set(lookAtBuf);
359
+ lookAtBuf.set(cStatic.point1);
340360
341361 computeTransform();
342362 }
....@@ -351,17 +371,52 @@
351371 fromScreen = LA.newMatrix();
352372 }
353373
374
+ if (locationBuf == null)
375
+ {
376
+ locationBuf = new cVector();
377
+ locationBuf.set(location);
378
+ lookAtBuf = new cVector();
379
+ lookAtBuf.set(lookAt);
380
+ upBuf = new cVector();
381
+ upBuf.set(UP);
382
+// up2Buf = new cVector();
383
+// up2Buf.set(UP2);
384
+ }
385
+ else
386
+ {
387
+ double K = 0.25;
388
+
389
+ locationBuf.y = location.y * K + locationBuf.y * (1 - K);
390
+ lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K);
391
+
392
+ upBuf.x = UP.x * K + upBuf.x * (1 - K);
393
+ upBuf.y = UP.y * K + upBuf.y * (1 - K);
394
+ upBuf.z = UP.z * K + upBuf.z * (1 - K);
395
+ upBuf.normalize();
396
+// up2Buf.x = UP2.x * K + up2Buf.x * (1 - K);
397
+// up2Buf.y = UP2.y * K + up2Buf.y * (1 - K);
398
+// up2Buf.z = UP2.z * K + up2Buf.z * (1 - K);
399
+
400
+ K = 1;
401
+
402
+ locationBuf.x = location.x * K + locationBuf.x * (1 - K);
403
+ locationBuf.z = location.z * K + locationBuf.z * (1 - K);
404
+ lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K);
405
+ lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K);
406
+ }
407
+
354408 cVector up2 = up;
355409 cVector right2 = right;
356410
357
- up2.x = UP.x;
358
- up2.y = UP.y;
359
- up2.z = UP.z;
360
- LA.vecSub(lookAt, location, away);
411
+ up2.x = upBuf.x;
412
+ up2.y = upBuf.y;
413
+ up2.z = upBuf.z;
414
+ LA.vecSub(lookAtBuf, locationBuf, away);
361415 LA.vecNormalize(away);
362416 LA.vecCross(away, up2, right2);
363417 if (right2.length2() < 0.0001)
364418 {
419
+ //System.out.println("right2.length2() < 0.0001");
365420 // UP failed
366421 up2.x = UP2.x;
367422 up2.y = UP2.y;
....@@ -371,6 +426,7 @@
371426 LA.vecCross(away, up2, right2);
372427 if (!(right2.length2() > 0))
373428 {
429
+ System.exit(0);
374430 // old problem...
375431 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
376432 up2.x = UP.x = 0;
....@@ -400,10 +456,10 @@
400456 }
401457
402458 for (int i=0; i < 3; i++)
403
- fromScreen[3][i] = location.get(i);
459
+ fromScreen[3][i] = locationBuf.get(i);
404460
405461 for (int i=0; i < 3; i++)
406
- temp[3][i] = -location.get(i);
462
+ temp[3][i] = -locationBuf.get(i);
407463
408464 LA.matConcat(temp, toScreen, toScreen);
409465
....@@ -490,11 +546,20 @@
490546 static final int viewFront = 2;
491547 static final int viewSide = 3;
492548 int viewCode;
549
+
493550 cVector location;
494551 cVector lookAt;
552
+
553
+ transient cVector locationBuf;
554
+ transient cVector lookAtBuf;
555
+ transient cVector upBuf;
556
+ //transient cVector up2Buf;
557
+
495558 cVector direction;
559
+
496560 double[][] toScreen;
497561 double[][] fromScreen;
562
+
498563 boolean perspective;
499564 int hAspect = 0; // Free camera
500565 int vAspect;