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));
....@@ -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,11 +286,11 @@
275286 if (scale == 0)
276287 {
277288 // Zoom
289
+ double factor = Math.exp(-dy/300.0); // (1 + dy/100);
290
+
278291 LA.vecSub(location, lookAt, location);
279292
280293 cVector p = location;
281
-
282
- double factor = Math.exp(-dy/300.0); // (1 + dy/100);
283294
284295 p.x *= factor;
285296 p.y *= factor;
....@@ -292,7 +303,7 @@
292303 LA.vecSub(location, lookAt, direction);
293304
294305 //scale /= Distance();
295
- scale /= shaper_fovy/20;
306
+ // scale /= shaper_fovy/20;
296307
297308 location.x -= dy * direction.x / scale;
298309 //location.y -= dy * direction.y / scale;
....@@ -313,21 +324,37 @@
313324
314325 void RotateInterest(float dx, float dy)
315326 {
327
+ right.mul(-1);
328
+
316329 cStatic.point1.set(location);
317330 location.set(lookAt);
318331 lookAt.set(cStatic.point1);
319
- 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
+ }
320339 // UP.mul(-1);
321340
322341 RotatePosition(dx,-dy);
323342
324343 // UP.mul(-1);
325344 right.mul(-1);
345
+
326346 cStatic.point1.set(location);
327347 location.set(lookAt);
328348 lookAt.set(cStatic.point1);
329349
330
- //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();
331358 }
332359
333360 //synchronized // june 2014
....@@ -340,33 +367,85 @@
340367 fromScreen = LA.newMatrix();
341368 }
342369
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
+
343420 cVector up2 = up;
344421 cVector right2 = right;
345422
346
- up2.x = UP.x;
347
- up2.y = UP.y;
348
- up2.z = UP.z;
349
- 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);
350427 LA.vecNormalize(away);
351428 LA.vecCross(away, up2, right2);
352429 if (right2.length2() < 0.0001)
353430 {
431
+ //System.out.println("right2.length2() < 0.0001");
354432 // UP failed
355433 up2.x = UP2.x;
356434 up2.y = UP2.y;
357435 up2.z = UP2.z;
358
- LA.vecSub(lookAt, location, away);
359
- LA.vecNormalize(away);
360436 LA.vecCross(away, up2, right2);
361437 if (!(right2.length2() > 0))
362438 {
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
+
363444 // old problem...
364445 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
365446 up2.x = UP.x = 0;
366447 up2.y = UP.y = 1;
367448 up2.z = UP.z = 0;
368
- LA.vecSub(lookAt, location, away);
369
- LA.vecNormalize(away);
370449 LA.vecCross(away, up2, right2);
371450 }
372451 }
....@@ -389,10 +468,10 @@
389468 }
390469
391470 for (int i=0; i < 3; i++)
392
- fromScreen[3][i] = location.get(i);
471
+ fromScreen[3][i] = locationBuf.get(i);
393472
394473 for (int i=0; i < 3; i++)
395
- temp[3][i] = -location.get(i);
474
+ temp[3][i] = -locationBuf.get(i);
396475
397476 LA.matConcat(temp, toScreen, toScreen);
398477
....@@ -404,9 +483,16 @@
404483 LA.matConcat(fromScreen, rotate, fromScreen);
405484 //LA.matConcat(toScreen, rotate_1, toScreen);
406485 }
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
+
407494 //if (this == CameraPane.lightCamera)
408495 //CameraPane.lighttouched = true;
409
-
410496 LA.matInvert(fromScreen, toScreen);
411497 }
412498
....@@ -472,11 +558,20 @@
472558 static final int viewFront = 2;
473559 static final int viewSide = 3;
474560 int viewCode;
561
+
475562 cVector location;
476563 cVector lookAt;
564
+
565
+ transient cVector locationBuf;
566
+ transient cVector lookAtBuf;
567
+ transient cVector upBuf;
568
+ //transient cVector up2Buf;
569
+
477570 cVector direction;
478
- double toScreen[][];
479
- double fromScreen[][];
571
+
572
+ double[][] toScreen;
573
+ double[][] fromScreen;
574
+
480575 boolean perspective;
481576 int hAspect = 0; // Free camera
482577 int vAspect;