From cbe4e90105d07d7d3fecabffaa01342403aa2ae3 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 19 Sep 2019 20:54:00 -0400
Subject: [PATCH] Better navigation.

---
 CameraPane.java |   44 +++++++++++++++++----
 Camera.java     |   53 +++++++++++++-------------
 Object3D.java   |    4 +-
 3 files changed, 64 insertions(+), 37 deletions(-)

diff --git a/Camera.java b/Camera.java
index 9968d81..27803e7 100644
--- a/Camera.java
+++ b/Camera.java
@@ -288,25 +288,15 @@
                     // Zoom
                     double factor = Math.exp(-dy/300.0); // (1 + dy/100);
 
-                    if (viewCode != 0)
-                    {
-                        LA.vecSub(location, lookAt, location);
+                    LA.vecSub(location, lookAt, location);
 
-                        cVector p = location;
+                    cVector p = location;
 
-                        p.x *= factor;
-                        p.y *= factor;
-                        p.z *= factor;
+                    p.x *= factor;
+                    p.y *= factor;
+                    p.z *= factor;
 
-                        LA.vecAdd(location, lookAt, location);
-                    }
-                    else
-                    if (//shaper_fovy < 180 && factor > 1 ||
-                        shaper_fovy * factor < 150)
-                    {
-                        shaper_fovy *= factor;
-                        //System.out.println("fovy = " + shaper_fovy);
-                    }
+                    LA.vecAdd(location, lookAt, location);
                 }
                 else
                 {
@@ -340,9 +330,12 @@
             location.set(lookAt);
             lookAt.set(cStatic.point1);
             
-            cStatic.point1.set(locationBuf);
-            locationBuf.set(lookAtBuf);
-            lookAtBuf.set(cStatic.point1);
+            if (viewCode == 0 && locationBuf != null)
+            {
+                cStatic.point1.set(locationBuf);
+                locationBuf.set(lookAtBuf);
+                lookAtBuf.set(cStatic.point1);
+            }
          //   UP.mul(-1);
             
             RotatePosition(dx,-dy);
@@ -354,9 +347,12 @@
             location.set(lookAt);
             lookAt.set(cStatic.point1);
             
-            cStatic.point1.set(locationBuf);
-            locationBuf.set(lookAtBuf);
-            lookAtBuf.set(cStatic.point1);
+            if (viewCode == 0 && locationBuf != null)
+            {
+                cStatic.point1.set(locationBuf);
+                locationBuf.set(lookAtBuf);
+                lookAtBuf.set(cStatic.point1);
+            }
             
             computeTransform();
 	}
@@ -386,8 +382,13 @@
         {
             double K = 0.25;
             
+            if (!CameraPane.capsLocked)
+                K = 1;
+            
             locationBuf.y = location.y * K + locationBuf.y * (1 - K);
             lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K);
+            
+            K = 0.1;
             
             upBuf.x = UP.x * K + upBuf.x * (1 - K);
             upBuf.y = UP.y * K + upBuf.y * (1 - K);
@@ -421,19 +422,19 @@
 			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);
                         }
 		}
diff --git a/CameraPane.java b/CameraPane.java
index 116e9a8..517889f 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -11865,7 +11865,10 @@
         }
         
         if (Globals.isLIVE() && DrawMode() == DEFAULT || pingthread.live) // may 2013
+        {
+            renderCamera.computeTransform();
             repaint();
+        }
         
         displaydone = true;
     }
@@ -14421,7 +14424,7 @@
         //}
         
         SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
-        drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
+        drag(anchorX, anchorY + e.getUnitsToScroll()*8, e.getModifiers(), e.getModifiersEx());
         anchorX = ax;
         anchorY = ay;
         prevX = px;
@@ -14667,7 +14670,7 @@
             if (mute)
                 return;
             
-            if (capsLocked)
+            if (capsLocked && manipCamera.viewCode == 0)
             {
                 eye.x = manipCamera.location.x;
                 eye.y = manipCamera.location.y + 0.25;
@@ -14958,6 +14961,18 @@
         targetLookAt.set(manipCamera.lookAt);
     }
     
+    void ViewAngle(float dy)
+    {
+        double factor = Math.exp(-dy/300.0); // (1 + dy/100);
+                    
+        if (manipCamera.shaper_fovy * factor > 1 &&
+            manipCamera.shaper_fovy * factor < 150)
+        {
+            manipCamera.shaper_fovy *= factor;
+            //System.out.println("fovy = " + shaper_fovy);
+        }
+    }
+    
     void GoDown(int mod)
     {
         MODIFIERS |= COMMAND;
@@ -14968,6 +14983,9 @@
 //            if (isVR)
 //                manipCamera.RotateInterest(0, speed);
 //            else
+            if (isVR)
+                ViewAngle(-speed*delta);
+            else
                 manipCamera.Translate(0, -speed*delta, getWidth());
         }
         else
@@ -15004,6 +15022,9 @@
 //            if (isVR)
 //                manipCamera.RotateInterest(0, -speed);
 //            else
+            if (isVR)
+                ViewAngle(speed*delta);
+            else
                 manipCamera.Translate(0, speed*delta, getWidth());
         }
         else
@@ -15034,13 +15055,13 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-            manipCamera.Translate(speed*delta, 0, getWidth());
+            manipCamera.Translate(speed, 0, getWidth());
         else
         {
             if ((mouseMode&VR)!=0)
-                manipCamera.RotateInterest(-speed, 0);
+                manipCamera.RotateInterest(-speed*manipCamera.shaper_fovy/90, 0);
             else
-                manipCamera.RotatePosition(speed, 0);
+                manipCamera.RotatePosition(speed*manipCamera.shaper_fovy/90, 0);
         }
         
         /**/
@@ -15066,13 +15087,13 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-            manipCamera.Translate(-speed*delta, 0, getWidth());
+            manipCamera.Translate(-speed, 0, getWidth());
         else
         {
             if ((mouseMode&VR)!=0)
-                manipCamera.RotateInterest(speed, 0);
+                manipCamera.RotateInterest(speed*manipCamera.shaper_fovy/90, 0);
             else
-                manipCamera.RotatePosition(-speed, 0);
+                manipCamera.RotatePosition(-speed*manipCamera.shaper_fovy/90, 0);
         }
         
         /**/
@@ -15219,6 +15240,11 @@
                 if ((mouseMode & ZOOM) != 0)
                 {
                     //if ((mouseMode & BACKFORTH) != 0)
+                    if ((modifiersex & SHIFT) == SHIFT)
+                    {
+                        ViewAngle(dy);
+                    }
+                    else
                     if ((mouseMode & VR) != 0)
                         manipCamera.BackForth(dx, dy, getWidth());
                     else
@@ -18210,7 +18236,7 @@
     
     private boolean keepshadow;
     
-    public boolean capsLocked = false; // VR
+    static public boolean capsLocked = false; // VR
     
     static public int indexcount = 0;
     /*static*/ cColor vertexOcclusion = new cColor();
diff --git a/Object3D.java b/Object3D.java
index 3b928eb..24c90ab 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -8869,7 +8869,7 @@
         double diry = ray.viewDirection.y;
         double dirz = ray.viewDirection.z;
         
-        if (this.fromParent != null)
+        if (this.fromParent != null && !(this instanceof TextureNode))
         {
             eye.x = eyex;
             eye.y = eyey;
@@ -8894,7 +8894,7 @@
         
         boolean touch = false;
         
-        if (bRep != null)
+        if (bRep != null && link2support)
         {
             if (bbox == null)
             {

--
Gitblit v1.6.2