Normand Briere
2019-09-18 f9325048496d7cdbcad233f8a6b84c88e79adcc2
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));
....@@ -112,6 +112,7 @@
112112
113113 material.shift = 90;
114114 material.cameralight = 0.2f;
115
+ material.shadowbias = 10;
115116 }
116117
117118 void setAspect(int width, int height)
....@@ -158,6 +159,11 @@
158159 void RotatePosition(float dx, float dy)
159160 {
160161 if(hAspect != 0) return;
162
+
163
+ if (CameraPane.IMAGEFLIP)
164
+ {
165
+ dx = -dx;
166
+ }
161167
162168 if (CameraPane.ROTATECAMERA)
163169 {
....@@ -215,6 +221,11 @@
215221 void Translate(float dx, float dy, float scale)
216222 {
217223 if(hAspect != 0) return;
224
+
225
+ if (CameraPane.IMAGEFLIP)
226
+ {
227
+ dx = -dx;
228
+ }
218229
219230 if (CameraPane.ROTATECAMERA)
220231 {
....@@ -275,24 +286,34 @@
275286 if (scale == 0)
276287 {
277288 // Zoom
278
- LA.vecSub(location, lookAt, location);
279
-
280
- cVector p = location;
281
-
282289 double factor = Math.exp(-dy/300.0); // (1 + dy/100);
283290
284
- p.x *= factor;
285
- p.y *= factor;
286
- p.z *= factor;
291
+ if (viewCode != 0)
292
+ {
293
+ LA.vecSub(location, lookAt, location);
287294
288
- 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
+ }
289310 }
290311 else
291312 {
292313 LA.vecSub(location, lookAt, direction);
293314
294315 //scale /= Distance();
295
- scale /= shaper_fovy/20;
316
+ // scale /= shaper_fovy/20;
296317
297318 location.x -= dy * direction.x / scale;
298319 //location.y -= dy * direction.y / scale;
....@@ -313,21 +334,31 @@
313334
314335 void RotateInterest(float dx, float dy)
315336 {
337
+ right.mul(-1);
338
+
316339 cStatic.point1.set(location);
317340 location.set(lookAt);
318341 lookAt.set(cStatic.point1);
319
- right.mul(-1);
342
+
343
+ cStatic.point1.set(locationBuf);
344
+ locationBuf.set(lookAtBuf);
345
+ lookAtBuf.set(cStatic.point1);
320346 // UP.mul(-1);
321347
322348 RotatePosition(dx,-dy);
323349
324350 // UP.mul(-1);
325351 right.mul(-1);
352
+
326353 cStatic.point1.set(location);
327354 location.set(lookAt);
328355 lookAt.set(cStatic.point1);
329356
330
- //computeTransform();
357
+ cStatic.point1.set(locationBuf);
358
+ locationBuf.set(lookAtBuf);
359
+ lookAtBuf.set(cStatic.point1);
360
+
361
+ computeTransform();
331362 }
332363
333364 //synchronized // june 2014
....@@ -340,17 +371,52 @@
340371 fromScreen = LA.newMatrix();
341372 }
342373
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
+
343408 cVector up2 = up;
344409 cVector right2 = right;
345410
346
- up2.x = UP.x;
347
- up2.y = UP.y;
348
- up2.z = UP.z;
349
- 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);
350415 LA.vecNormalize(away);
351416 LA.vecCross(away, up2, right2);
352417 if (right2.length2() < 0.0001)
353418 {
419
+ //System.out.println("right2.length2() < 0.0001");
354420 // UP failed
355421 up2.x = UP2.x;
356422 up2.y = UP2.y;
....@@ -360,6 +426,7 @@
360426 LA.vecCross(away, up2, right2);
361427 if (!(right2.length2() > 0))
362428 {
429
+ System.exit(0);
363430 // old problem...
364431 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
365432 up2.x = UP.x = 0;
....@@ -389,10 +456,10 @@
389456 }
390457
391458 for (int i=0; i < 3; i++)
392
- fromScreen[3][i] = location.get(i);
459
+ fromScreen[3][i] = locationBuf.get(i);
393460
394461 for (int i=0; i < 3; i++)
395
- temp[3][i] = -location.get(i);
462
+ temp[3][i] = -locationBuf.get(i);
396463
397464 LA.matConcat(temp, toScreen, toScreen);
398465
....@@ -404,9 +471,16 @@
404471 LA.matConcat(fromScreen, rotate, fromScreen);
405472 //LA.matConcat(toScreen, rotate_1, toScreen);
406473 }
474
+
475
+ if (CameraPane.IMAGEFLIP)
476
+ {
477
+ double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
478
+
479
+ LA.matConcat(fromScreen, flip, fromScreen);
480
+ }
481
+
407482 //if (this == CameraPane.lightCamera)
408483 //CameraPane.lighttouched = true;
409
-
410484 LA.matInvert(fromScreen, toScreen);
411485 }
412486
....@@ -472,11 +546,20 @@
472546 static final int viewFront = 2;
473547 static final int viewSide = 3;
474548 int viewCode;
549
+
475550 cVector location;
476551 cVector lookAt;
552
+
553
+ transient cVector locationBuf;
554
+ transient cVector lookAtBuf;
555
+ transient cVector upBuf;
556
+ //transient cVector up2Buf;
557
+
477558 cVector direction;
478
- double toScreen[][];
479
- double fromScreen[][];
559
+
560
+ double[][] toScreen;
561
+ double[][] fromScreen;
562
+
480563 boolean perspective;
481564 int hAspect = 0; // Free camera
482565 int vAspect;