From dce400da7c65d659129abf9bc6e8f38b360a63d2 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 26 Aug 2019 20:13:01 -0400
Subject: [PATCH] Fix camera version + VR using spacebar.

---
 ObjEditor.java   |   29 +++++++++++++-
 CameraPane.java  |   36 +++++++++++++-----
 Globals.java     |    2 +
 GroupEditor.java |    4 +-
 cMaterial.java   |    1 
 Object3D.java    |   21 +++++++---
 6 files changed, 71 insertions(+), 22 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index b983dd6..68bd5e4 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -9840,7 +9840,10 @@
             DrawSkyBox(gl, (float)rati);
             gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
             gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
-            accPerspective(gl, renderCamera.shaper_fovy / ratio,
+            
+            boolean vr = capsLocked && !lightMode;
+            
+            accPerspective(gl, renderCamera.shaper_fovy / ratio * (vr ? 2 : 1),
                     ratio,
                     //near_plane, far_plane,
                     renderCamera.shaper_zNear * renderCamera.Distance(), renderCamera.shaper_zFar * renderCamera.Distance(),
@@ -11397,7 +11400,9 @@
                 //gl.glOrtho(-BOOST, BOOST, -BOOST, BOOST, 0.001, 1000);
                 } else
                 {
-                    glu.gluPerspective(cam.shaper_fovy / ratio, ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance());
+                    boolean vr = capsLocked && !lightMode;
+                    
+                    glu.gluPerspective(cam.shaper_fovy / ratio * (vr ? 2 : 1), ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance());
                 }
             }
 
@@ -14250,10 +14255,12 @@
             return;
 	}
         
-        boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
+        //boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
+        
+        boolean vr = capsLocked && !lightMode;
         
         // TIMER
-        if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
+        if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !vr) // VR
         {
             keepboxmode = BOXMODE;
             keepsupport = SUPPORT;
@@ -15239,8 +15246,10 @@
             mouseMode |= ZOOM;
         }
         
-        boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
-        if (capsLocked) // || (modifiers & META) == META)
+        //boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
+        boolean vr = capsLocked && !lightMode;
+
+        if (vr) // || (modifiers & META) == META)
         {
             mouseMode |= VR; // BACKFORTH;
         }
@@ -15456,8 +15465,8 @@
                 RevertCamera();
                 repaint();
                 break;
-            case 'l':
-            //case 'L':
+            //case 'l':
+            case 'L':
                 if (lightMode)
                 {
                     lightMode = false;
@@ -15515,8 +15524,8 @@
                 break;
             case 'O':
                 // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
-                repaint();
-                break;
+                //repaint();
+                //break;
             case 'o':
                 OCCLUSION_CULLING ^= true;
                 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
@@ -15608,6 +15617,10 @@
 //                kompactbit = 6;
 //                break;
             case ' ':
+                capsLocked ^= true;
+                repaint();
+                break;
+            case 'l':
                 lightMode ^= true;
                 Globals.lighttouched = true;
                 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
@@ -17911,6 +17924,9 @@
     static boolean DEBUG_SELECTION = false;
     boolean OCCLUSION_CULLING = false; //true;
     public boolean lightMode = false;
+    
+    public boolean capsLocked = false; // VR
+    
     static public int indexcount = 0;
     /*static*/ cColor vertexOcclusion = new cColor();
     //private int selection_view = -1;
diff --git a/Globals.java b/Globals.java
index 7832547..17bae5d 100644
--- a/Globals.java
+++ b/Globals.java
@@ -1,6 +1,8 @@
 
 public class Globals
 {
+        static boolean SHOWINFO = true;
+    
         static boolean ADVANCED = false;   // false;
         
         static boolean NIMBUSLAF = false; // false;
diff --git a/GroupEditor.java b/GroupEditor.java
index c1f3bea..2e6edb6 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -5374,7 +5374,7 @@
 			if (tps != null && tps.length > 0 && tps[0].getLastPathComponent() instanceof Camera)
                             // a camera
                         {
-                            if (tps[0].getLastPathComponent() != Globals.theRenderer.LightCamera()) // Crash the camera because of invalid lightspace
+                            if (tps[0].getLastPathComponent() != Globals.theRenderer.LightCamera()) // Crashes the camera because of invalid lightspace
                             {
                                 CameraPane.camerachangeframe = 0; // don't refuse it
                                 Globals.theRenderer.SetCamera((Camera) tps[0].getLastPathComponent());
@@ -5426,7 +5426,7 @@
 
         void refreshContents(boolean cp)
         {
-            if (Globals.ADVANCED)
+            if (Globals.SHOWINFO)
             //if (objectPanel.getSelectedIndex() == 2) // objectPanel.indexOfTab("Info"))
             if (!Globals.MOUSEDRAGGED && group.selection != null) // && !Globals.TIMERRUNNING)
             {
diff --git a/ObjEditor.java b/ObjEditor.java
index fd5504d..68657fd 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -1882,7 +1882,7 @@
         tabbedPane.add(creditsPanel);
         tabbedPane.setToolTipTextAt(3, "Credits");
         
-        if (Globals.ADVANCED)
+        if (Globals.SHOWINFO)
         {
             objectPanel.add(infoPanel);
             objectPanel.setIconAt(5, GetIcon("icons/info.png"));
@@ -4469,6 +4469,8 @@
             CopyChanged(copy);
         
         SetVersionStates();
+        
+        SetCameras();
     }
     
     public boolean Save(boolean user)
@@ -4547,6 +4549,11 @@
     void RefreshSelection()
     {
         Object3D selection = new Object3D();
+        
+        if (objEditor.copy.selection == null)
+        {
+            objEditor.copy.selection = new Object3D();
+        }
         
         for (int i = 0; i < objEditor.copy.selection.size(); i++)
         {
@@ -4682,7 +4689,7 @@
         // Option?
         Replace();
         
-        System.err.println("Undo");
+        //System.err.println("Previous");
         
         //cRadio tab = GetCurrentTab();
         
@@ -4711,6 +4718,8 @@
         
         SetVersionStates();
         
+        SetCameras();
+        
         return true;
     }
 
@@ -4730,6 +4739,8 @@
         CopyChanged(copy);
         
         SetVersionStates();
+        
+        SetCameras();
         
         return true;
     }
@@ -4771,9 +4782,20 @@
         //if (!tab.user[tab.versionindex])
         //    tab.graphs[tab.versionindex] = null;
         
-        SetVersionStates();        
+        SetVersionStates();
+        
+        SetCameras();
     }
 
+    void SetCameras()
+    {
+        Camera neweye = (Camera)copy.GetObject(cameraView.cameras[0].GetUUID());
+        Camera newlight = (Camera)copy.GetObject(cameraView.LightCamera().GetUUID());
+        
+        cameraView.SetCamera(neweye);
+        cameraView.SetLight(newlight);
+    }
+    
         void ImportGFD()
         {
             FileDialog browser = new FileDialog(objEditor.frame, "Import GrafreeD", FileDialog.LOAD);
@@ -5119,6 +5141,7 @@
                 copy.versionindex = version;
                 CopyChanged(copy);
                 SetVersionStates();
+                SetCameras();
             }
             
             return;
diff --git a/Object3D.java b/Object3D.java
index 9d52cb0..b8c4bc0 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -194,6 +194,8 @@
     {
         Object3D o;
         
+        boolean isnew = false;
+        
         if (hashtable.containsKey(GetUUID()))
         {
             o = hashtable.get(GetUUID());
@@ -206,6 +208,8 @@
         }
         else
         {
+            isnew = true;
+            
             o = new Object3D("copy of " + this.name);
 
             hashtable.put(GetUUID(), o);
@@ -222,12 +226,15 @@
 
             blockloop = false;
         }
-        
-        ExtractBigData(o);
+
+        if (isnew)
+            ExtractBigData(o);
     }
 
     void ExtractBigData(Object3D o)
     {
+        //System.err.println("ExtractBigData : " + this + " --> " + o);
+        
         if (o.bRep != null)
             Grafreed.Assert(o.bRep == this.bRep);
         
@@ -238,8 +245,8 @@
 //            o.bRep.support = null;
 //        }
         o.selection = this.selection;
-        o.versionlist = this.versionlist;
-        o.versionindex = this.versionindex;
+        //o.versionlist = this.versionlist;
+        //o.versionindex = this.versionindex;
         
         if (this.support != null)
         {
@@ -355,6 +362,8 @@
 
     void RestoreBigData(Object3D o)
     {
+        //System.err.println("RestoreBigData : " + this + " <-- " + o);
+        
         this.bRep = o.bRep;
         if (this.support != null && o.transientrep != null)
         {
@@ -363,8 +372,8 @@
         
         this.selection = o.selection;
         
-        this.versionlist = o.versionlist;
-        this.versionindex = o.versionindex;
+        //this.versionlist = o.versionlist;
+        //this.versionindex = o.versionindex;
 // July 2019        if (this.bRep != null)
 //            this.bRep.support = o.transientrep;
     //    this.support = o.support;
diff --git a/cMaterial.java b/cMaterial.java
index c84b510..0d302bd 100644
--- a/cMaterial.java
+++ b/cMaterial.java
@@ -41,7 +41,6 @@
 
     public cMaterial(cMaterial mat)
     {
-        this();
         if (mat != null)
         {
             Set(mat);

--
Gitblit v1.6.2