From 54adfcbf93eb477bedeec45409f36cf7e102b790 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 16 Sep 2019 21:54:55 -0400
Subject: [PATCH] Navigation with intersection.

---
 CameraPane.java |  142 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 120 insertions(+), 22 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index 90689ce..6e4b50c 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -134,7 +134,7 @@
 static    boolean ZOOMBOXMODE = false;
 static    boolean BOXMODE = false;
 static    boolean IMAGEFLIP = false;
-static    boolean SMOOTHFOCUS = false;
+static    boolean SMOOTHFOCUS = true; // false;
 static    boolean SPEAKERMOCAP = true; // jan 2014 false;
 static    boolean SPEAKERCAMERA = false;
 static    boolean SPEAKERFOCUS = false;
@@ -2109,7 +2109,7 @@
         // Start with free camera
         SwitchCameras(true);
         
-        pingthread.jump = true; // optional?
+//        pingthread.jump = true; // optional?
         
         if (TRACKONCE)
         {
@@ -2296,18 +2296,6 @@
     public void ToggleTrack()
     {
         TRACK ^= true;
-        if (TRACK)
-        {
-            if (object.selection != null &&
-                object.selection.size() > 0 &&
-                object.selection.elementAt(0) != null &&
-                !(object.selection.elementAt(0) instanceof Camera) &&
-                !(object.selection.elementAt(0) instanceof ScriptNode))
-            {
-                trackedobject = object.selection.elementAt(0);
-                repaint();
-            }
-        }
         
         repaint();
     }
@@ -10916,6 +10904,12 @@
                 else
                     speedkey[RIGHT_ARROW] = 0;
                 
+                if (Globals.WALK && capsLocked)
+                {
+                    Walk();
+                    keyon = true;
+                }
+                
                 if (keyon)
                 {
                     repaint();
@@ -11870,7 +11864,7 @@
             repaint();
         }
         
-        if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
+        if (Globals.isLIVE() && DrawMode() == DEFAULT || pingthread.live) // may 2013
             repaint();
         
         displaydone = true;
@@ -11946,9 +11940,23 @@
         //GL gl = getGL();
         if ((TRACK || SHADOWTRACK) || zoomonce)
         {
+        if (TRACK)
+        {
+            if (object.selection != null &&
+                object.selection.size() > 0 &&
+                object.selection.elementAt(0) != null &&
+                !(object.selection.elementAt(0) instanceof Camera) &&
+                !(object.selection.elementAt(0) instanceof ScriptNode))
+            {
+                trackedobject = object.selection.elementAt(0);
+                //repaint();
+            }
+            else
+                trackedobject = null;
+        }
             if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
                 object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
-            pingthread.StepToTarget(true); // true);
+            pingthread.StepToTarget(); // true);
        //     zoomonce = false;
         }
 
@@ -14508,8 +14516,9 @@
 // fev 2014???
             if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
                 object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
-            pingthread.StepToTarget(true); // true);
+            pingthread.StepToTarget(); // true);
         }
+        
     //    if (!LIVE)
             super.repaint();
     }
@@ -14629,9 +14638,15 @@
             return targetLookAt;
     }
 
+        javax.vecmath.Point3d eye = new javax.vecmath.Point3d();
+        javax.vecmath.Point3d eye2 = new javax.vecmath.Point3d();
+        javax.vecmath.Vector3d dir = new javax.vecmath.Vector3d();
+
+                
     class PingThread extends Thread
     {
         boolean jump;
+        boolean live;
         
         boolean mute;
         
@@ -14651,6 +14666,70 @@
         {
             if (mute)
                 return;
+            
+            if (capsLocked)
+            {
+                eye.x = manipCamera.location.x;
+                eye.y = manipCamera.location.y + 0.25;
+                eye.z = manipCamera.location.z;
+
+                dir.y = -1;
+
+                Ray ray = new Ray(eye, dir);
+
+                IntersectResult res = new IntersectResult();
+                res.t = Double.POSITIVE_INFINITY;
+
+                tmp.set(targetLookAt);
+                tmp.sub(manipCamera.location);
+                
+                double dist = tmp.length();
+                
+                tmp.normalize();
+                    
+                eye2.x = manipCamera.location.x + tmp.x * 0.25;
+                eye2.y = manipCamera.location.y + 0.25;
+                eye2.z = manipCamera.location.z + tmp.z * 0.25;
+
+                Ray ray2 = new Ray(eye2, dir);
+
+                IntersectResult res2 = new IntersectResult();
+                res2.t = Double.POSITIVE_INFINITY;
+
+                if (object.intersect(ray, res) && object.intersect(ray2, res2) && Math.abs(res.t - res2.t) < 0.25)
+                {
+                    //tmp.set(manipCamera.location);
+
+                    manipCamera.location.x = ray.eyePoint.x + ray.viewDirection.x * res.t;
+                    manipCamera.location.y = ray.eyePoint.y + ray.viewDirection.y * res.t + 0.5;
+                    manipCamera.location.z = ray.eyePoint.z + ray.viewDirection.z * res.t;
+
+                    //tmp.sub(manipCamera.location);
+
+                    targetLookAt.x = ray2.eyePoint.x + ray2.viewDirection.x * res2.t;
+                    targetLookAt.y = ray2.eyePoint.y + ray2.viewDirection.y * res2.t + 0.5;
+                    targetLookAt.z = ray2.eyePoint.z + ray2.viewDirection.z * res2.t;
+                    
+                    targetLookAt.sub(manipCamera.location);
+                    targetLookAt.normalize();
+                    targetLookAt.mul(dist);
+                    targetLookAt.add(manipCamera.location);
+                    
+                    //if (tmp.dot(tmp) > 0.000001)
+                    //    System.out.println("INTERSECTION " + manipCamera.location);
+
+                    manipCamera.lookAt.set(targetLookAt);
+                    
+                    tmp.x = res.n.x;
+                    tmp.y = res.n.y;
+                    tmp.z = res.n.z;
+                    tmp.x += res2.n.x;
+                    tmp.y += res2.n.y;
+                    tmp.z += res2.n.z;
+                    tmp.normalize();
+                    manipCamera.UP.set(tmp);
+                }
+            }
             
             tmp.set(targetLookAt);
             tmp.sub(manipCamera.lookAt); // june 2014
@@ -14689,7 +14768,7 @@
                 
                 if (tmp.dot(tmp) > 1) // may 2014. far away: jump to target
                 {
-                    jump = true; // step = 1;
+                    // sep 2019 jump = true; // step = 1;
                 }
                 
                 if (OEILONCE && OEIL)
@@ -14724,7 +14803,10 @@
                 if (tmp.dot(tmp) < 0.00001)
                 {
                     zoomonce = false;
+                    live = false;
                 }
+                else
+                    live = true;
                 
                 tmp.mul(step > step2 ? step : step2);
             }
@@ -14866,8 +14948,16 @@
     PingThread pingthread = new PingThread();
     int delta = 1;
     int speed = 1;
+    int walk = 8;
     boolean autorepeat = false;
 
+    void Walk()
+    {
+        manipCamera.BackForth(0, walk, 1000);
+        
+        targetLookAt.set(manipCamera.lookAt);
+    }
+    
     void GoDown(int mod)
     {
         MODIFIERS |= COMMAND;
@@ -15869,17 +15959,23 @@
                     object.GetWindow().refreshContents(true);
                 break;
             case '{':
-                manipCamera.shaper_fovy /= 1.1;
+                double factor = 1.1;
+                if (manipCamera.shaper_fovy / factor > 0.1)
+                    manipCamera.shaper_fovy /= factor;
                 System.out.println("FOV = " + manipCamera.shaper_fovy);
                 repaint();
                 break;
             case '}':
-                manipCamera.shaper_fovy *= 1.1;
+                factor = 1.1;
+                if (manipCamera.shaper_fovy * factor < 150)
+                    manipCamera.shaper_fovy *= factor;
                 System.out.println("FOV = " + manipCamera.shaper_fovy);
                 repaint();
                 break;
             case '[':
-                manipCamera.shaper_fovy /= 1.01;
+                factor = 1.01;
+                if (manipCamera.shaper_fovy / factor > 0.1)
+                    manipCamera.shaper_fovy /= factor;
                 if (false) //manipCamera.hAspect == 0)
                 {
                     double x = Math.tan(manipCamera.shaper_fovy * Math.PI / 180 / 2);
@@ -15895,7 +15991,9 @@
                 break;
             case ']':
                 //manipCamera.shaper_fovy += (180 - manipCamera.shaper_fovy)*0.1;
-                manipCamera.shaper_fovy *= 1.01;
+                factor = 1.01;
+                if (manipCamera.shaper_fovy * factor < 150)
+                    manipCamera.shaper_fovy *= factor;
                 if (false) //manipCamera.hAspect == 0)
                 {
                     double x = Math.tan(manipCamera.shaper_fovy * Math.PI / 180 / 2);

--
Gitblit v1.6.2