From f868664f7e7626f651e6ade9c9f6863851ef43b7 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Wed, 06 Nov 2019 23:12:57 -0500
Subject: [PATCH] Dangerous "reset".

---
 Camera.java |  146 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 124 insertions(+), 22 deletions(-)

diff --git a/Camera.java b/Camera.java
index 8454950..2bb124c 100644
--- a/Camera.java
+++ b/Camera.java
@@ -3,7 +3,6 @@
 // Decompiler options: packimports(3) 
 // Source File Name:   Camera.java
 
-
 class Camera extends Object3D
 {
     static final long serialVersionUID = 4754289789178680517L;
@@ -21,7 +20,7 @@
         //<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6>
     //    location = LA.newVector(2,0.7,-2);
     //    lookAt = new cVector(0.6,0.3,-0.6);
-        location = LA.newVector(3,2,2);
+        location = LA.newVector(6,2,4);
         lookAt = new cVector(0.0,0.5,0);
         direction = new cVector();
         toParent = LA.newMatrix();
@@ -53,7 +52,7 @@
             perspective = true;
             break;
         case 1: // '\001'
-            location = LA.newVector(0, 0, 4);
+            location = LA.newVector(0, 0, 4); // Needed for translation direction
             perspective = false;
             break;
         case 2: // '\002'
@@ -64,7 +63,7 @@
             //LA.matXRotate(fromScreen, LA.toRadians(90));
             break;
         case 3: // '\003'
-            location = LA.newVector(4, 0, 0);
+            location = LA.newVector(4, 0, 0); // Needed for translation direction
             //LA.matZRotate(toScreen, LA.toRadians(-90));
             //LA.matXRotate(toScreen, LA.toRadians(-90));
             //LA.matXRotate(fromScreen, LA.toRadians(90));
@@ -72,7 +71,7 @@
             perspective = false;
             break;
         case 4: // Default light
-            location = LA.newVector(10, 30, 20);
+            location = LA.newVector(-5, 15, 10);
             perspective = false;
             break;
         }
@@ -105,6 +104,15 @@
         focalLength = 1;
         setAspect(4, 3);
         background = LA.newVector(0.8, 0.8, 0.8);
+    }
+
+    void CreateMaterial(boolean multiply)
+    {
+        super.CreateMaterial(multiply);
+        
+        material.shift = 90;
+        material.cameralight = 0.2f;
+        material.shadowbias = 10;
     }
 
     void setAspect(int width, int height)
@@ -151,6 +159,11 @@
 	void RotatePosition(float dx, float dy)
 	{
         if(hAspect != 0) return;
+        
+        if (CameraPane.IMAGEFLIP)
+        {
+            dx = -dx;
+        }
         
         if (CameraPane.ROTATECAMERA)
         {
@@ -208,6 +221,11 @@
 	void Translate(float dx, float dy, float scale)
 	{
         if(hAspect != 0) return;
+        
+        if (CameraPane.IMAGEFLIP)
+        {
+            dx = -dx;
+        }
         
         if (CameraPane.ROTATECAMERA)
         {
@@ -268,11 +286,11 @@
                 if (scale == 0)
                 {
                     // Zoom
+                    double factor = Math.exp(-dy/300.0); // (1 + dy/100);
+
                     LA.vecSub(location, lookAt, location);
 
                     cVector p = location;
-
-                    double factor = Math.exp(-dy/300.0); // (1 + dy/100);
 
                     p.x *= factor;
                     p.y *= factor;
@@ -285,7 +303,7 @@
                     LA.vecSub(location, lookAt, direction);
 
                     //scale /= Distance();
-                    scale /= shaper_fovy/20;
+           //         scale /= shaper_fovy/20;
 
                     location.x -= dy * direction.x / scale;
                     //location.y -= dy * direction.y / scale;
@@ -306,19 +324,35 @@
 	
 	void RotateInterest(float dx, float dy)
 	{
+            right.mul(-1);
+            
             cStatic.point1.set(location);
             location.set(lookAt);
             lookAt.set(cStatic.point1);
-            right.mul(-1);
+            
+            if (viewCode == 0 && locationBuf != null)
+            {
+                cStatic.point1.set(locationBuf);
+                locationBuf.set(lookAtBuf);
+                lookAtBuf.set(cStatic.point1);
+            }
          //   UP.mul(-1);
             
             RotatePosition(dx,-dy);
             
          //   UP.mul(-1);
             right.mul(-1);
+            
             cStatic.point1.set(location);
             location.set(lookAt);
             lookAt.set(cStatic.point1);
+            
+            if (viewCode == 0 && locationBuf != null)
+            {
+                cStatic.point1.set(locationBuf);
+                locationBuf.set(lookAtBuf);
+                lookAtBuf.set(cStatic.point1);
+            }
             
             computeTransform();
 	}
@@ -333,33 +367,85 @@
             fromScreen = LA.newMatrix();
         }
         
+        if (locationBuf == null)
+        {
+            locationBuf = new cVector();
+            locationBuf.set(location);
+            lookAtBuf = new cVector();
+            lookAtBuf.set(lookAt);
+            upBuf = new cVector();
+            upBuf.set(UP);
+//            up2Buf = new cVector();
+//            up2Buf.set(UP2);
+        }
+        else
+        {
+            double K = 0.25;
+            
+            if (!CameraPane.capsLocked || CameraPane.ambientOcclusion)
+                K = 1;
+            
+            locationBuf.y = location.y * K + locationBuf.y * (1 - K);
+            lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K);
+            
+            int Y = 1;
+            
+            if (UP.y < 0)
+                Y = -1;
+            
+            UP.x = 0 * K + UP.x * (1 - K);
+            UP.y = Y * K + UP.y * (1 - K);
+            UP.z = 0 * K + UP.z * (1 - K);
+            UP.normalize();
+            
+            if (CameraPane.capsLocked && !CameraPane.ambientOcclusion)
+                K = 0.1;
+            
+            upBuf.x = UP.x * K + upBuf.x * (1 - K);
+            upBuf.y = UP.y * K + upBuf.y * (1 - K);
+            upBuf.z = UP.z * K + upBuf.z * (1 - K);
+            upBuf.normalize();
+//            up2Buf.x = UP2.x * K + up2Buf.x * (1 - K);
+//            up2Buf.y = UP2.y * K + up2Buf.y * (1 - K);
+//            up2Buf.z = UP2.z * K + up2Buf.z * (1 - K);
+            
+            K = 1;
+            
+            locationBuf.x = location.x * K + locationBuf.x * (1 - K);
+            locationBuf.z = location.z * K + locationBuf.z * (1 - K);
+            lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K);
+            lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K);
+        }
+        
         cVector up2 = up;
         cVector right2 = right;
         
-	up2.x = UP.x;
-	up2.y = UP.y;
-	up2.z = UP.z;
-        LA.vecSub(lookAt, location, away);
+	up2.x = upBuf.x;
+	up2.y = upBuf.y;
+	up2.z = upBuf.z;
+        LA.vecSub(lookAtBuf, locationBuf, away);
         LA.vecNormalize(away);
         LA.vecCross(away, up2, right2);
 		if (right2.length2() < 0.0001)
 		{
+                    //System.out.println("right2.length2() < 0.0001");
 			// UP failed
 			up2.x = UP2.x;
 			up2.y = UP2.y;
 			up2.z = UP2.z;
-			LA.vecSub(lookAt, location, away);
-			LA.vecNormalize(away);
 			LA.vecCross(away, up2, right2);
 			if (!(right2.length2() > 0))
                         {
+                            System.out.println("NO UP VECTOR: " + up2);
+                            System.out.println("lookAtBuf: " + lookAtBuf);
+                            System.out.println("locationBuf: " + locationBuf);
+                    System.exit(0);
+
                             // old problem...
                             assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
                             up2.x = UP.x = 0;
                             up2.y = UP.y = 1;
                             up2.z = UP.z = 0;
-                            LA.vecSub(lookAt, location, away);
-                            LA.vecNormalize(away);
                             LA.vecCross(away, up2, right2);
                         }
 		}
@@ -382,10 +468,10 @@
 		}
 
         for (int i=0; i < 3; i++)
-            fromScreen[3][i] = location.get(i);
+            fromScreen[3][i] = locationBuf.get(i);
 
         for (int i=0; i < 3; i++)
-            temp[3][i] = -location.get(i);
+            temp[3][i] = -locationBuf.get(i);
 
         LA.matConcat(temp, toScreen, toScreen);
 
@@ -397,9 +483,16 @@
             LA.matConcat(fromScreen, rotate, fromScreen);
             //LA.matConcat(toScreen, rotate_1, toScreen);
         }
+        
+        if (CameraPane.IMAGEFLIP)
+        {
+            double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
+        
+            LA.matConcat(fromScreen, flip, fromScreen);
+        }
+        
 		//if (this == CameraPane.lightCamera)
 			//CameraPane.lighttouched = true;
-        
         LA.matInvert(fromScreen, toScreen);
     }
 
@@ -465,11 +558,20 @@
     static final int viewFront = 2;
     static final int viewSide = 3;
     int viewCode;
+    
     cVector location;
     cVector lookAt;
+    
+    transient cVector locationBuf;
+    transient cVector lookAtBuf;
+    transient cVector upBuf;
+    //transient cVector up2Buf;
+    
     cVector direction;
-    double toScreen[][];
-    double fromScreen[][];
+    
+    double[][] toScreen;
+    double[][] fromScreen;
+    
     boolean perspective;
     int hAspect = 0; // Free camera
     int vAspect;

--
Gitblit v1.6.2