From 64e20f390e4b8e58bd0006dde8fa10fba1dac1d5 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Fri, 16 Aug 2019 13:25:19 -0400
Subject: [PATCH] Fix box and VR keys.

---
 CameraPane.java |  110 +++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 86 insertions(+), 24 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index df28651..8acf68e 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -110,7 +110,11 @@
     //private Mat4f spotlightTransform = new Mat4f();
     //private Mat4f spotlightInverseTransform = new Mat4f();
     static GLContext glcontext = null;
-    /*static*/ com.sun.opengl.util.texture.Texture cubemap;
+    /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
+    /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
+    /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
+    boolean transformMode;
+    
     boolean reverseUP = false;
     static boolean frozen = false;
     boolean enablebackspace = false; // patch for back buffer refresh
@@ -188,15 +192,16 @@
     
     private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
 
-    public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
+    public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
     {
         try
         {
-            cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
+            return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
         } catch (IOException e)
         {
             System.out.println("NAME = " + name);
             e.printStackTrace(); // throw new RuntimeException(e);
+            return null;
         }
     }
     
@@ -2512,7 +2517,7 @@
                     com.sun.opengl.util.texture.TextureIO.newTextureData(
                     getClass().getClassLoader().getResourceAsStream(name),
                     true,
-                    com.sun.opengl.util.texture.TextureIO.PNG);
+                    GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
         } catch (java.io.IOException e)
         {
             throw new javax.media.opengl.GLException(e);
@@ -9233,6 +9238,8 @@
 
     void LoadEnvy(int which)
     {
+        assert(false);
+        
         String name;
         String ext;
 
@@ -11077,18 +11084,34 @@
 //
 //        newenvy = -1;
         
-        if (object.skyboxname != null)
+        if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
         {
-            if (!object.skyboxname.equals(this.loadedskyboxname))
+            if (cubemaprgb == null)
             {
-                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
-                loadedskyboxname = object.skyboxname;
+                cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
             }
+            
+            cubemap = cubemaprgb;
         }
         else
         {
-            cubemap = null;
-            loadedskyboxname = null;
+            if (object.skyboxname != null)
+            {
+                if (!object.skyboxname.equals(this.loadedskyboxname))
+                {
+                    if (cubemap != null && cubemap != cubemaprgb)
+                        cubemap.dispose();
+                    cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                    loadedskyboxname = object.skyboxname;
+                }
+            }
+            else
+            {
+                cubemapcustom = null;
+                loadedskyboxname = null;
+            }
+            
+            cubemap = cubemapcustom;
         }
         
         ratio = ((double) getWidth()) / getHeight();
@@ -13396,8 +13419,12 @@
             program = programmin;
         }
         
-        System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
-        System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
+        if (Globals.DEBUG)
+        {
+            System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
+            System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
+        }
+        
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
 
     //gl.glNewList(displayListID, GL.GL_COMPILE);
@@ -13444,7 +13471,8 @@
                 "\n" +
                 "END\n";
 
-        System.out.println("Program shadow #" + 0 + "; length = " + program.length());
+        if (Globals.DEBUG)
+            System.out.println("Program shadow #" + 0 + "; length = " + program.length());
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
 
     //gl.glNewList(displayListID, GL.GL_COMPILE);
@@ -14643,11 +14671,17 @@
     void GoDown(int mod)
     {
         MODIFIERS |= COMMAND;
+        boolean isVR = (mouseMode&VR)!=0;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
+        {
+            if (isVR)
+                manipCamera.RotateInterest(0, -speed);
+            else
+                manipCamera.RotatePosition(0, -speed);
+        }
         else
-        manipCamera.RotatePosition(0, -speed);
+            manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14657,6 +14691,8 @@
             mouseMode |= BACKFORTH;
         }
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         //prevX = X = anchorX;
         prevY = Y = anchorY - (int) (renderCamera.Distance());
     }
@@ -14665,10 +14701,17 @@
     {
         MODIFIERS |= COMMAND;
         /**/
+        boolean isVR = (mouseMode&VR)!=0;
+        
         if((mod&SHIFT) == SHIFT)
-        manipCamera.BackForth(0, speed*delta, 0); // getWidth());
+        {
+            if (isVR)
+                manipCamera.RotateInterest(0, speed);
+            else
+                manipCamera.RotatePosition(0, speed);
+        }
         else
-        manipCamera.RotatePosition(0, speed);
+            manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14678,6 +14721,8 @@
             mouseMode |= BACKFORTH;
         }
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         //prevX = X = anchorX;
         prevY = Y = anchorY + (int) (renderCamera.Distance());
     }
@@ -14687,9 +14732,14 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.Translate(speed*delta, 0, getWidth());
+            manipCamera.Translate(speed*delta, 0, getWidth());
         else
-        manipCamera.RotatePosition(speed, 0);
+        {
+            if ((mouseMode&VR)!=0)
+                manipCamera.RotateInterest(-speed, 0);
+            else
+                manipCamera.RotatePosition(speed, 0);
+        }
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14699,6 +14749,8 @@
             mouseMode |= ROTATE;
         } // TRANSLATE;
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
         prevY = Y = anchorY;
     }
@@ -14708,9 +14760,15 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.Translate(-speed*delta, 0, getWidth());
+            manipCamera.Translate(-speed*delta, 0, getWidth());
         else
-        manipCamera.RotatePosition(-speed, 0);
+        {
+            if ((mouseMode&VR)!=0)
+                manipCamera.RotateInterest(speed, 0);
+            else
+                manipCamera.RotatePosition(-speed, 0);
+        }
+        
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14720,6 +14778,8 @@
             mouseMode |= ROTATE;
         } // TRANSLATE;
 
+        targetLookAt.set(manipCamera.lookAt);
+        
         prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
         prevY = Y = anchorY;
     }
@@ -16104,7 +16164,7 @@
                     {
                         switch (hitSomething)
                         {
-                            case Object3D.hitCenter: gr.setColor(Color.pink);
+                            case Object3D.hitCenter: gr.setColor(Color.white);
                                 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                                 break;
                             case Object3D.hitRotate: gr.setColor(Color.yellow);
@@ -16130,7 +16190,7 @@
         if (hasMarquee)
         {
             gr.setXORMode(Color.white);
-            gr.setColor(Color.red);
+            gr.setColor(Color.white);
             if (!firstime)
             {
                 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
@@ -16769,7 +16829,8 @@
         gl.glDisable(GL.GL_TEXTURE_GEN_R);
 
         cubemap.disable();
-        ////cubemap.unbind();
+        //cubemap.dispose();
+        
         if (CULLFACE)
         {
             gl.glEnable(gl.GL_CULL_FACE);
@@ -17305,6 +17366,7 @@
 
         public void init(GLAutoDrawable drawable)
         {
+        if (Globals.DEBUG)
             System.out.println("shadow buffer init");
 
             GL gl = drawable.getGL();

--
Gitblit v1.6.2