From b3ae4e889872ca0b9ca76f1d17b2f0b961226729 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 05 Aug 2019 21:48:55 -0400
Subject: [PATCH] Fix physics UI

---
 CameraPane.java |  120 +++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 86 insertions(+), 34 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index bd26db2..28e9ff5 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -9316,10 +9316,9 @@
     double[] light2camera = new double[16];
     
     //int newenvy = -1;
-    boolean envyoff = true; // false;
-    String skyboxname = "";
-    String skyboxext;
-    String loadedskyboxname = "";
+    //boolean envyoff = false;
+    
+    String loadedskyboxname;
     
     cVector light0 = new cVector(0, 0, 0); // 1,3,2);
     //float[] light0 = { 0,0,0 };
@@ -11065,10 +11064,18 @@
 //
 //        newenvy = -1;
         
-        if (!skyboxname.equals(this.loadedskyboxname))
+        if (object.skyboxname != null)
         {
-            LoadSkybox(skyboxname + "/", skyboxext, false);
-            loadedskyboxname = skyboxname;
+            if (!object.skyboxname.equals(this.loadedskyboxname))
+            {
+                LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
+                loadedskyboxname = object.skyboxname;
+            }
+        }
+        else
+        {
+            cubemap = null;
+            loadedskyboxname = null;
         }
         
         ratio = ((double) getWidth()) / getHeight();
@@ -11372,7 +11379,7 @@
 
 //            if (cam != lightCamera)
             //for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
+                LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
         }
         
         LA.xformDir(lightposition, cam.toScreen, lightposition);
@@ -12446,7 +12453,7 @@
 
         //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
 
-        String program0 =
+        String programmin =
                 // Min shader
                 "!!ARBfp1.0\n" +
                 "PARAM zero123      = { 0.0, 1.0, 2, 1.25 };" +
@@ -12513,7 +12520,7 @@
                 "MOV result.color, temp;" +
                 "END";
         
-        String program =
+        String programmax =
                 "!!ARBfp1.0\n" +
                 
                 //"OPTION ARB_fragment_program_shadow;" +
@@ -13038,7 +13045,7 @@
            // display shadow only (fakedepth == 0)
          "SUB temp.x, half.x, shadow.x;" +
          "MOV temp.y, -params5.z;" + // params6.x;" +
-         "SLT temp.z, temp.y, -one2048th.x;" +
+         "SLT temp.z, temp.y, -c256i.x;" +
          "SUB temp.y, one.x, temp.z;" +
          "MUL temp.x, temp.x, temp.y;" +
          "KIL temp.x;" +
@@ -13369,6 +13376,13 @@
             //once = true;
         }
 
+        String program = programmax;
+        
+        if (Globals.MINSHADER)
+        {
+            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 " : ""));
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
@@ -14618,9 +14632,9 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.RotatePosition(0, -speed);
-        else
         manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
+        else
+        manipCamera.RotatePosition(0, -speed);
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -14639,9 +14653,9 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-        manipCamera.RotatePosition(0, speed);
-        else
         manipCamera.BackForth(0, speed*delta, 0); // getWidth());
+        else
+        manipCamera.RotatePosition(0, speed);
         /**/
         if ((mod & SHIFT) == SHIFT)
         {
@@ -15362,7 +15376,7 @@
                 OCCLUSION_CULLING ^= true;
                 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
                 break;
-            case '0': envyoff ^= true; repaint(); break;
+            //case '0': envyoff ^= true; repaint(); break;
             case '1':
             case '2':
             case '3':
@@ -15372,7 +15386,7 @@
             case '7':
             case '8':
             case '9':
-                if (envyoff)
+                if (true) // envyoff)
                 {
                     BGcolor = (key - '1')/8.f;
                 }
@@ -16084,7 +16098,7 @@
                                 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                             break;
                             case Object3D.hitScale: gr.setColor(Color.cyan);
-                                gr.drawLine(X, Y, 0, 0);
+                                gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                             break;
                         }
 
@@ -16570,6 +16584,8 @@
     private /*static*/ boolean firstime;
     private /*static*/ cVector newView = new cVector();
     private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
+    private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
+    private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
     private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                                              GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                                              GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
@@ -16582,22 +16598,56 @@
     {
         com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
 
+        int usedsuf = 0;
+        
         for (int i = 0; i < suffixes.length; i++)
         {
-            String resourceName = basename + suffixes[i] + "." + suffix;
-            TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
-                    mipmapped,
-                    FileUtil.getFileSuffix(resourceName));
-            if (data == null)
+            String[] suffixe = suffixes;
+            String[] fallback = suffixes2;
+            String[] fallfallback = suffixes3;
+            
+            for (int c=usedsuf; --c>=0;)
             {
-                throw new IOException("Unable to load texture " + resourceName);
+//                String[] temp = suffixe;
+//                suffixe = fallback;
+//                fallback = fallfallback;
+//                fallfallback = temp;
             }
+            
+            String resourceName = basename + suffixe[i] + "." + suffix;
+            TextureData data;
+            
+            try
+            {
+                data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                        mipmapped,
+                        FileUtil.getFileSuffix(resourceName));
+            }
+            catch (Exception e)
+            {
+                try
+                {
+                    resourceName = basename + fallback[i] + "." + suffix;
+                    data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                            mipmapped,
+                            FileUtil.getFileSuffix(resourceName));
+                }
+                catch (Exception e2)
+                {
+                    resourceName = basename + fallfallback[i] + "." + suffix;
+                    data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
+                            mipmapped,
+                            FileUtil.getFileSuffix(resourceName));
+                }
+            }
+            
             //System.out.println("Target = " + targets[i]);
             cubemap.updateImage(data, targets[i]);
         }
 
         return cubemap;
     }
+    
     int bigsphere = -1;
 
     float BGcolor = 0.5f;
@@ -16606,7 +16656,8 @@
     
     private void DrawSkyBox(GL gl, float ratio)
     {
-        if (envyoff || cubemap == null)
+        if (//envyoff ||
+                cubemap == null)
         {
             gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
             gl.glClear(gl.GL_COLOR_BUFFER_BIT);
@@ -16623,14 +16674,14 @@
         gl.glLoadIdentity();
         gl.glScalef(1,ratio,1);
 
-        colorV[0] = 2;
-        colorV[1] = 2;
-        colorV[2] = 2;
-        colorV[3] = 1;
-        gl.glDisable(gl.GL_COLOR_MATERIAL);
-        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
-        
-        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
+//        colorV[0] = 2;
+//        colorV[1] = 2;
+//        colorV[2] = 2;
+//        colorV[3] = 1;
+//        gl.glDisable(gl.GL_COLOR_MATERIAL);
+//        gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
+//        
+//        gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
         
         //gl.glActiveTexture(GL.GL_TEXTURE1);
         //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
@@ -16644,7 +16695,7 @@
         // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
         // causes the normals to be sent down. Thanks to Ken Dyke.
         //gl.glEnable(GL.GL_LIGHTING);
-        gl.glEnable(GL.GL_LIGHTING);
+        gl.glDisable(GL.GL_LIGHTING);
 
         gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
         gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
@@ -16663,6 +16714,7 @@
         {
             gl.glScalef(1.0f, -1.0f, 1.0f);
         }
+        gl.glScalef(-1.0f, 1.0f, 1.0f);
         gl.glMultMatrixd(viewrot_1, 0);
         gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance());  // 0.5f);
         //viewer.updateInverseRotation(gl);

--
Gitblit v1.6.2