From d248db5fc21c4b0ab24968974e5e590f413ef8fc Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Tue, 17 Sep 2019 18:56:45 -0400
Subject: [PATCH] Smooth navigation.

---
 CameraPane.java |    4 ++
 Camera.java     |   69 +++++++++++++++++++++++++++++++---
 2 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/Camera.java b/Camera.java
index e9360b7..9968d81 100644
--- a/Camera.java
+++ b/Camera.java
@@ -334,19 +334,29 @@
 	
 	void RotateInterest(float dx, float dy)
 	{
+            right.mul(-1);
+            
             cStatic.point1.set(location);
             location.set(lookAt);
             lookAt.set(cStatic.point1);
-            right.mul(-1);
+            
+            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);
+            
+            cStatic.point1.set(locationBuf);
+            locationBuf.set(lookAtBuf);
+            lookAtBuf.set(cStatic.point1);
             
             computeTransform();
 	}
@@ -361,17 +371,52 @@
             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;
+            
+            locationBuf.y = location.y * K + locationBuf.y * (1 - K);
+            lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K);
+            
+            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;
@@ -381,6 +426,7 @@
 			LA.vecCross(away, up2, right2);
 			if (!(right2.length2() > 0))
                         {
+                    System.exit(0);
                             // old problem...
                             assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
                             up2.x = UP.x = 0;
@@ -410,10 +456,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);
 
@@ -500,11 +546,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;
+    
     boolean perspective;
     int hAspect = 0; // Free camera
     int vAspect;
diff --git a/CameraPane.java b/CameraPane.java
index 6e4b50c..e49e0a3 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -15923,6 +15923,10 @@
             case ENTER:
                 // object.editWindow.ScreenFit(); // Edit();
                 ToggleLive();
+                if (capsLocked)
+                {
+                    Globals.WALK ^= true;
+                }
                 break;
             case DELETE:
                 ClearSelection();

--
Gitblit v1.6.2