Normand Briere
2019-09-18 f9325048496d7cdbcad233f8a6b84c88e79adcc2
Camera.java
....@@ -3,7 +3,6 @@
33 // Decompiler options: packimports(3)
44 // Source File Name: Camera.java
55
6
-
76 class Camera extends Object3D
87 {
98 static final long serialVersionUID = 4754289789178680517L;
....@@ -21,7 +20,7 @@
2120 //<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6>
2221 // location = LA.newVector(2,0.7,-2);
2322 // lookAt = new cVector(0.6,0.3,-0.6);
24
- location = LA.newVector(3,2,2);
23
+ location = LA.newVector(6,2,4);
2524 lookAt = new cVector(0.0,0.5,0);
2625 direction = new cVector();
2726 toParent = LA.newMatrix();
....@@ -53,7 +52,7 @@
5352 perspective = true;
5453 break;
5554 case 1: // '\001'
56
- location = LA.newVector(0, 0, 4);
55
+ location = LA.newVector(0, 0, 4); // Needed for translation direction
5756 perspective = false;
5857 break;
5958 case 2: // '\002'
....@@ -64,7 +63,7 @@
6463 //LA.matXRotate(fromScreen, LA.toRadians(90));
6564 break;
6665 case 3: // '\003'
67
- location = LA.newVector(4, 0, 0);
66
+ location = LA.newVector(4, 0, 0); // Needed for translation direction
6867 //LA.matZRotate(toScreen, LA.toRadians(-90));
6968 //LA.matXRotate(toScreen, LA.toRadians(-90));
7069 //LA.matXRotate(fromScreen, LA.toRadians(90));
....@@ -72,7 +71,7 @@
7271 perspective = false;
7372 break;
7473 case 4: // Default light
75
- location = LA.newVector(10, 30, 20);
74
+ location = LA.newVector(-5, 15, 10);
7675 perspective = false;
7776 break;
7877 }
....@@ -105,6 +104,15 @@
105104 focalLength = 1;
106105 setAspect(4, 3);
107106 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;
108116 }
109117
110118 void setAspect(int width, int height)
....@@ -151,6 +159,11 @@
151159 void RotatePosition(float dx, float dy)
152160 {
153161 if(hAspect != 0) return;
162
+
163
+ if (CameraPane.IMAGEFLIP)
164
+ {
165
+ dx = -dx;
166
+ }
154167
155168 if (CameraPane.ROTATECAMERA)
156169 {
....@@ -208,6 +221,11 @@
208221 void Translate(float dx, float dy, float scale)
209222 {
210223 if(hAspect != 0) return;
224
+
225
+ if (CameraPane.IMAGEFLIP)
226
+ {
227
+ dx = -dx;
228
+ }
211229
212230 if (CameraPane.ROTATECAMERA)
213231 {
....@@ -268,24 +286,34 @@
268286 if (scale == 0)
269287 {
270288 // Zoom
271
- LA.vecSub(location, lookAt, location);
272
-
273
- cVector p = location;
274
-
275289 double factor = Math.exp(-dy/300.0); // (1 + dy/100);
276290
277
- p.x *= factor;
278
- p.y *= factor;
279
- p.z *= factor;
291
+ if (viewCode != 0)
292
+ {
293
+ LA.vecSub(location, lookAt, location);
280294
281
- 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
+ }
282310 }
283311 else
284312 {
285313 LA.vecSub(location, lookAt, direction);
286314
287315 //scale /= Distance();
288
- scale /= shaper_fovy/20;
316
+ // scale /= shaper_fovy/20;
289317
290318 location.x -= dy * direction.x / scale;
291319 //location.y -= dy * direction.y / scale;
....@@ -306,19 +334,29 @@
306334
307335 void RotateInterest(float dx, float dy)
308336 {
337
+ right.mul(-1);
338
+
309339 cStatic.point1.set(location);
310340 location.set(lookAt);
311341 lookAt.set(cStatic.point1);
312
- right.mul(-1);
342
+
343
+ cStatic.point1.set(locationBuf);
344
+ locationBuf.set(lookAtBuf);
345
+ lookAtBuf.set(cStatic.point1);
313346 // UP.mul(-1);
314347
315348 RotatePosition(dx,-dy);
316349
317350 // UP.mul(-1);
318351 right.mul(-1);
352
+
319353 cStatic.point1.set(location);
320354 location.set(lookAt);
321355 lookAt.set(cStatic.point1);
356
+
357
+ cStatic.point1.set(locationBuf);
358
+ locationBuf.set(lookAtBuf);
359
+ lookAtBuf.set(cStatic.point1);
322360
323361 computeTransform();
324362 }
....@@ -333,17 +371,52 @@
333371 fromScreen = LA.newMatrix();
334372 }
335373
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
+
336408 cVector up2 = up;
337409 cVector right2 = right;
338410
339
- up2.x = UP.x;
340
- up2.y = UP.y;
341
- up2.z = UP.z;
342
- 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);
343415 LA.vecNormalize(away);
344416 LA.vecCross(away, up2, right2);
345417 if (right2.length2() < 0.0001)
346418 {
419
+ //System.out.println("right2.length2() < 0.0001");
347420 // UP failed
348421 up2.x = UP2.x;
349422 up2.y = UP2.y;
....@@ -353,6 +426,7 @@
353426 LA.vecCross(away, up2, right2);
354427 if (!(right2.length2() > 0))
355428 {
429
+ System.exit(0);
356430 // old problem...
357431 assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
358432 up2.x = UP.x = 0;
....@@ -382,23 +456,32 @@
382456 }
383457
384458 for (int i=0; i < 3; i++)
385
- fromScreen[3][i] = location.get(i);
459
+ fromScreen[3][i] = locationBuf.get(i);
386460
387461 for (int i=0; i < 3; i++)
388
- temp[3][i] = -location.get(i);
462
+ temp[3][i] = -locationBuf.get(i);
389463
390464 LA.matConcat(temp, toScreen, toScreen);
391465
392466 if (CameraPane.ROTATECAMERA)
393467 {
394468 double[][] rotate = { { 0,1,0,0 }, { -1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
395
- double[][] rotate_1 = { { 0,-1,0,0 }, { 1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
469
+ //double[][] rotate_1 = { { 0,-1,0,0 }, { 1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
396470
397
- LA.matConcat(rotate, fromScreen, fromScreen);
398
- LA.matConcat(toScreen, rotate_1, toScreen);
471
+ LA.matConcat(fromScreen, rotate, fromScreen);
472
+ //LA.matConcat(toScreen, rotate_1, toScreen);
399473 }
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
+
400482 //if (this == CameraPane.lightCamera)
401483 //CameraPane.lighttouched = true;
484
+ LA.matInvert(fromScreen, toScreen);
402485 }
403486
404487 // void Draw(CameraPane display, Object3D /*Composite*/ root, boolean selected)
....@@ -463,11 +546,20 @@
463546 static final int viewFront = 2;
464547 static final int viewSide = 3;
465548 int viewCode;
549
+
466550 cVector location;
467551 cVector lookAt;
552
+
553
+ transient cVector locationBuf;
554
+ transient cVector lookAtBuf;
555
+ transient cVector upBuf;
556
+ //transient cVector up2Buf;
557
+
468558 cVector direction;
469
- double toScreen[][];
470
- double fromScreen[][];
559
+
560
+ double[][] toScreen;
561
+ double[][] fromScreen;
562
+
471563 boolean perspective;
472564 int hAspect = 0; // Free camera
473565 int vAspect;