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(0, 0, 4);
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(4, 0, 0);
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));
....@@ -71,7 +71,7 @@
7171 perspective = false;
7272 break;
7373 case 4: // Default light
74
- location = LA.newVector(-10, 30, 20);
74
+ location = LA.newVector(-5, 15, 10);
7575 perspective = false;
7676 break;
7777 }
....@@ -104,6 +104,15 @@
104104 focalLength = 1;
105105 setAspect(4, 3);
106106 background = LA.newVector(0.8, 0.8, 0.8);
107
+ }
108
+
109
+ void CreateMaterial(boolean multiply)
110
+ {
111
+ super.CreateMaterial(multiply);
112
+
113
+ material.shift = 90;
114
+ material.cameralight = 0.2f;
115
+ material.shadowbias = 10;
107116 }
108117
109118 void setAspect(int width, int height)
....@@ -150,6 +159,11 @@
150159 void RotatePosition(float dx, float dy)
151160 {
152161 if(hAspect != 0) return;
162
+
163
+ if (CameraPane.IMAGEFLIP)
164
+ {
165
+ dx = -dx;
166
+ }
153167
154168 if (CameraPane.ROTATECAMERA)
155169 {
....@@ -207,6 +221,11 @@
207221 void Translate(float dx, float dy, float scale)
208222 {
209223 if(hAspect != 0) return;
224
+
225
+ if (CameraPane.IMAGEFLIP)
226
+ {
227
+ dx = -dx;
228
+ }
210229
211230 if (CameraPane.ROTATECAMERA)
212231 {
....@@ -267,11 +286,11 @@
267286 if (scale == 0)
268287 {
269288 // Zoom
289
+ double factor = Math.exp(-dy/300.0); // (1 + dy/100);
290
+
270291 LA.vecSub(location, lookAt, location);
271292
272293 cVector p = location;
273
-
274
- double factor = Math.exp(-dy/300.0); // (1 + dy/100);
275294
276295 p.x *= factor;
277296 p.y *= factor;
....@@ -284,7 +303,7 @@
284303 LA.vecSub(location, lookAt, direction);
285304
286305 //scale /= Distance();
287
- scale /= shaper_fovy/20;
306
+ // scale /= shaper_fovy/20;
288307
289308 location.x -= dy * direction.x / scale;
290309 //location.y -= dy * direction.y / scale;
....@@ -305,19 +324,35 @@
305324
306325 void RotateInterest(float dx, float dy)
307326 {
327
+ right.mul(-1);
328
+
308329 cStatic.point1.set(location);
309330 location.set(lookAt);
310331 lookAt.set(cStatic.point1);
311
- 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
+ }
312339 // UP.mul(-1);
313340
314341 RotatePosition(dx,-dy);
315342
316343 // UP.mul(-1);
317344 right.mul(-1);
345
+
318346 cStatic.point1.set(location);
319347 location.set(lookAt);
320348 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
+ }
321356
322357 computeTransform();
323358 }
....@@ -332,33 +367,85 @@
332367 fromScreen = LA.newMatrix();
333368 }
334369
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
+
335420 cVector up2 = up;
336421 cVector right2 = right;
337422
338
- up2.x = UP.x;
339
- up2.y = UP.y;
340
- up2.z = UP.z;
341
- 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);
342427 LA.vecNormalize(away);
343428 LA.vecCross(away, up2, right2);
344429 if (right2.length2() < 0.0001)
345430 {
431
+ //System.out.println("right2.length2() < 0.0001");
346432 // UP failed
347433 up2.x = UP2.x;
348434 up2.y = UP2.y;
349435 up2.z = UP2.z;
350
- LA.vecSub(lookAt, location, away);
351
- LA.vecNormalize(away);
352436 LA.vecCross(away, up2, right2);
353437 if (!(right2.length2() > 0))
354438 {
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
+
355444 // old problem...
356445 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
357446 up2.x = UP.x = 0;
358447 up2.y = UP.y = 1;
359448 up2.z = UP.z = 0;
360
- LA.vecSub(lookAt, location, away);
361
- LA.vecNormalize(away);
362449 LA.vecCross(away, up2, right2);
363450 }
364451 }
....@@ -381,10 +468,10 @@
381468 }
382469
383470 for (int i=0; i < 3; i++)
384
- fromScreen[3][i] = location.get(i);
471
+ fromScreen[3][i] = locationBuf.get(i);
385472
386473 for (int i=0; i < 3; i++)
387
- temp[3][i] = -location.get(i);
474
+ temp[3][i] = -locationBuf.get(i);
388475
389476 LA.matConcat(temp, toScreen, toScreen);
390477
....@@ -396,9 +483,16 @@
396483 LA.matConcat(fromScreen, rotate, fromScreen);
397484 //LA.matConcat(toScreen, rotate_1, toScreen);
398485 }
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
+
399494 //if (this == CameraPane.lightCamera)
400495 //CameraPane.lighttouched = true;
401
-
402496 LA.matInvert(fromScreen, toScreen);
403497 }
404498
....@@ -464,11 +558,20 @@
464558 static final int viewFront = 2;
465559 static final int viewSide = 3;
466560 int viewCode;
561
+
467562 cVector location;
468563 cVector lookAt;
564
+
565
+ transient cVector locationBuf;
566
+ transient cVector lookAtBuf;
567
+ transient cVector upBuf;
568
+ //transient cVector up2Buf;
569
+
469570 cVector direction;
470
- double toScreen[][];
471
- double fromScreen[][];
571
+
572
+ double[][] toScreen;
573
+ double[][] fromScreen;
574
+
472575 boolean perspective;
473576 int hAspect = 0; // Free camera
474577 int vAspect;