From c67da2e5d8655704601d6d06e8bc60aabe212253 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 23 Jun 2019 21:49:12 -0400
Subject: [PATCH] Compute shadow when live option.

---
 CameraPane.java |  405 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 320 insertions(+), 85 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index 830f914..7afdef6 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -37,7 +37,6 @@
     static boolean[] selectedstack = new boolean[65536];
     static int materialdepth = 0;
 
-    static boolean DEBUG = false;
     static boolean FRUSTUM = false; // still bogus true; // frustum culling
 
     // camera change fix
@@ -149,6 +148,8 @@
         defaultcaps.setAccumBlueBits(16);
         defaultcaps.setAccumAlphaBits(16);
     }
+    
+    private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
     
     void SetAsGLRenderer(boolean b)
     {
@@ -325,7 +326,7 @@
                 cStatic.objectstack[materialdepth++] = obj;
                 //System.out.println("material " + material);
                 //Applet3D.tracein(this, selected);
-                display.vector2buffer = obj.projectedVertices;
+                //display.vector2buffer = obj.projectedVertices;
                 if (obj instanceof Camera)
                 {
                     display.options1[0] = material.shift;
@@ -357,7 +358,7 @@
                 /**/
                 } else
                 {
-                    DrawMaterial(material, selected);
+                    DrawMaterial(material, selected, obj.projectedVertices);
                 }
             } else
             {
@@ -381,8 +382,8 @@
             cStatic.objectstack[materialdepth++] = obj;
             //System.out.println("material " + material);
             //Applet3D.tracein("selected ", selected);
-            display.vector2buffer = obj.projectedVertices;
-            display.DrawMaterial(material, selected);
+            //display.vector2buffer = obj.projectedVertices;
+            display.DrawMaterial(material, selected, obj.projectedVertices);
         }
     }
     
@@ -399,8 +400,8 @@
                 materialdepth -= 1;
                 if (materialdepth > 0)
                 {
-                    display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
-                    display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
+                    //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
+                    display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
                 }
             //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
             } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
@@ -420,8 +421,8 @@
             materialdepth -= 1;
             if (materialdepth > 0)
             {
-                display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
-                display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
+                //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
+                display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
             }
         //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
         //else
@@ -462,10 +463,12 @@
         if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
         {
             //gl.glBegin(gl.GL_TRIANGLES);
-            boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
+            boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
+                    // TEST LIVE NORMALS && !obj.dontselect
+                    ;
             if (!hasnorm)
             {
-           //     System.out.println("FUCK!!");
+           //     System.out.println("Mesh normal");
                 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
                 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
                 LA.vecCross(obj.v0, obj.v1, obj.v2);
@@ -1190,10 +1193,12 @@
                                     gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
                                 }
                             }
+                            
                             if (flipV)
                                 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
                             else
                                 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+                            
                             //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
                             gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
 
@@ -1213,10 +1218,12 @@
                                     gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
                                 }
                             }
+                            
                             if (flipV)
                                 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
                             else
                                 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+                            
                             //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
                             gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
 
@@ -1244,8 +1251,10 @@
                                     gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
                                 else
                                     gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+                                
                                 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
                                 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+                                
                                 count2 += 2;
                                 count3 += 3;
                             }
@@ -1601,7 +1610,7 @@
 //        gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
     }
     
-    void DrawMaterial(cMaterial material, boolean selected)
+    void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
     {
             CameraPane display = this;
         //new Exception().printStackTrace();
@@ -1636,7 +1645,7 @@
             colorV[0] = display.modelParams0[0] * material.diffuse;
             colorV[1] = display.modelParams0[1] * material.diffuse;
             colorV[2] = display.modelParams0[2] * material.diffuse;
-            colorV[3] = material.opacity;
+            colorV[3] = 1; // material.opacity;
 
             gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
             //System.out.println("Opacity = " + opacity);
@@ -1744,9 +1753,9 @@
         display.modelParams7[2] = 0;
         display.modelParams7[3] = 0;
 
-        display.modelParams6[0] = 100; // criss de bug de bump
+        //display.modelParams6[0] = 100; // criss de bug de bump
         
-        Object3D.cVector2[] extparams = display.vector2buffer;
+        Object3D.cVector2[] extparams = others; // display.vector2buffer;
         if (extparams != null && extparams.length > 0 && extparams[0] != null)
         {
             display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
@@ -1888,7 +1897,7 @@
     void PushMatrix(double[][] matrix)
     {
     //    GrafreeD.tracein(matrix);
-        PushMatrix(matrix,1);
+        PushMatrix(matrix, 1);
     }
     
     void PushMatrix()
@@ -2257,7 +2266,7 @@
     
     void ToggleDebug()
     {
-        DEBUG ^= true;
+        Globals.DEBUG ^= true;
     }
 
     void ToggleLookAt()
@@ -2265,7 +2274,7 @@
         LOOKAT ^= true;
     }
 
-    void ToggleRandom()
+    void ToggleSwitch()
     {
         SWITCH ^= true;
     }
@@ -2374,7 +2383,7 @@
     {
         return currentGL;
     }
-    
+
     /**/
     class CacheTexture
     {
@@ -7919,6 +7928,64 @@
         ReleaseTexture(pigment, false);
     }
     
+    public void ReleasePigmentTexture(cTexture tex) // INTERFACE
+    {
+        if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
+        {
+            return;
+        }
+
+        if (tex == null)
+        {
+            ReleaseTexture(null, false);
+            return;
+        }
+        
+        String pigment = Object3D.GetPigment(tex);
+
+        if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
+        {
+        //    System.out.print("RELEASE  +++++++++++++++  pigment = " + pigment);
+        //    System.out.println("; bump = " + bump);
+        }
+        
+        if (pigment.equals(""))
+        {
+            pigment = null;
+        }
+        
+        ReleaseTexture(pigment, false);
+    }
+    
+    public void ReleaseBumpTexture(cTexture tex) // INTERFACE
+    {
+        if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
+        {
+            return;
+        }
+
+        if (tex == null)
+        {
+            ReleaseTexture(null, true);
+            return;
+        }
+        
+        String bump = Object3D.GetBump(tex);
+
+        if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
+        {
+        //    System.out.print("RELEASE  +++++++++++++++  pigment = " + pigment);
+        //    System.out.println("; bump = " + bump);
+        }
+        
+        if (bump.equals(""))
+        {
+            bump = null;
+        }
+        
+        ReleaseTexture(bump, true);
+    }
+    
     void ReleaseTexture(String tex, boolean bump)
     {
         if (// DrawMode() != 0 || /*tex == null ||*/
@@ -8022,7 +8089,7 @@
         }
     }
 
-    /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
+    /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
     {
         if (// DrawMode() != 0 || /*tex == null ||*/
                 ambientOcclusion ) // || !textureon)
@@ -8067,7 +8134,94 @@
         return; // true;
     }
     
-    CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
+    /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
+    {
+        if (// DrawMode() != 0 || /*tex == null ||*/
+                ambientOcclusion ) // || !textureon)
+        {
+            return; // false;
+        }
+
+        if (tex == null)
+        {
+            BindTexture(null,false,resolution);
+            return;
+        }
+        
+        String pigment = Object3D.GetPigment(tex);
+
+        usedtextures.put(pigment, pigment);
+        
+        if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
+        {
+        //    System.out.print("BIND  +++++++++++++++  pigment = " + pigment);
+        //    System.out.println("; bump = " + bump);
+        }
+        
+        if (pigment.equals(""))
+        {
+            pigment = null;
+        }
+        
+        GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
+        BindTexture(pigment, false, resolution);
+    }
+    
+    /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
+    {
+        if (// DrawMode() != 0 || /*tex == null ||*/
+                ambientOcclusion ) // || !textureon)
+        {
+            return; // false;
+        }
+
+        if (tex == null)
+        {
+            BindTexture(null,true,resolution);
+            return;
+        }
+        
+        String bump = Object3D.GetBump(tex);
+
+        usedtextures.put(bump, bump);
+        
+        if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
+        {
+        //    System.out.print("BIND  +++++++++++++++  pigment = " + pigment);
+        //    System.out.println("; bump = " + bump);
+        }
+        
+        if (bump.equals(""))
+        {
+            bump = null;
+        }
+        
+        GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
+        BindTexture(bump, true, resolution);
+        GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
+    }
+    
+    java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
+    
+    private boolean FileExists(String tex)
+    {
+        if (missingTextures.contains(tex))
+        {
+            return false;
+        }
+        
+        boolean fileExists = new File(tex).exists();
+        
+        if (!fileExists)
+        {
+            // If file exists, the "new File()" is not executed sgain
+            missingTextures.add(tex);
+        }
+        
+        return fileExists;
+    }
+    
+    CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
         
@@ -8075,15 +8229,17 @@
         {
             String texname = tex;
             
+            String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
+                
 //            String[] split = tex.split("Textures");
 //            if (split.length > 1)
 //                texname = "/Users/nbriere/Textures" + split[split.length-1];
 //            else
 //                if (!texname.startsWith("/"))
 //                    texname = "/Users/nbriere/Textures/" + texname;
-            if (!new File(tex).exists())
+            if (!FileExists(tex))
             {
-                    texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
+                    texname = fallbackTextureName;
             }
             
             if (CACHETEXTURE)
@@ -8153,7 +8309,7 @@
                                     }
                                 
                                     cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
-                                    if (!new File(cachename).exists())
+                                    if (!FileExists(cachename))
                                         cachename = texname;
                                     else
                                         processbump = false; // don't process bump map again
@@ -8175,7 +8331,7 @@
                                     }
                                 
                                     cachename = texname.substring(0, texname.length()-4)+ext+".png";
-                                    if (!new File(cachename).exists())
+                                    if (!FileExists(cachename))
                                         cachename = texname;
                                     else
                                         processbump = false; // don't process bump map again
@@ -8184,7 +8340,9 @@
                                 texturedata = GetFileTexture(cachename, processbump, resolution);                                
                                 
                                 
-                                if (texturedata != null)
+                                if (texturedata == null)
+                                    throw new Exception();
+                                    
                                     texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
         //texture = GetTexture(tex, bump);
                             }
@@ -8306,7 +8464,7 @@
         return texture;
     }
     
-    com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
+    com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture texture = GetCacheTexture(tex, bump, resolution);
                 
@@ -8324,14 +8482,14 @@
         return texture!=null?texture.texture:null;
     }
     
-    public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
+    public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture texture = GetCacheTexture(tex, bump, resolution);
                 
         return texture!=null?texture.texturedata:null;
     }
     
-    boolean BindTexture(String tex, boolean bump, int resolution)
+    boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
     {
         if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
         {
@@ -9308,8 +9466,8 @@
         assert (parentcam != renderCamera);
         
         if (renderCamera != lightCamera)
-        for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(matrix, parentcam.toParent, matrix);
+        //for (int count = parentcam.GetTransformCount(); --count>=0;)
+            LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
         
 //            LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
             
@@ -9324,8 +9482,8 @@
             LA.matCopy(renderCamera.fromScreen, matrix);
             
         if (renderCamera != lightCamera)
-        for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(parentcam.fromParent, matrix, matrix);
+        //for (int count = parentcam.GetTransformCount(); --count>=0;)
+            LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
 
 //            LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
             
@@ -10390,13 +10548,14 @@
             ambientOcclusion = false;
         }
 
-        if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
+        if (//Globals.lighttouched &&
+                DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
         {
             //if (RENDERSHADOW) // ?
             if (!IsFrozen())
             {
                 // dec 2012
-                if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
+                if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
                 {
             Globals.framecount++;
                     shadowbuffer.display();
@@ -10523,8 +10682,8 @@
             
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
-            for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(matrix, parentcam.toParent, matrix);
+            //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
             
             for (int j = 0; j < 4; j++)
             {
@@ -10538,8 +10697,8 @@
             
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
-            for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(parentcam.fromParent, matrix, matrix);
+            //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
         
             //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
             
@@ -10798,7 +10957,16 @@
             // Bump noise
             gl.glActiveTexture(GL.GL_TEXTURE6);
             //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
-            BindTexture(NOISE_TEXTURE, false, 2);
+            
+    try
+    {
+        BindTexture(NOISE_TEXTURE, false, 2);
+    }
+    catch (Exception e)
+    {
+        System.err.println("FAILED: " + NOISE_TEXTURE);
+    }
+           
 
             gl.glActiveTexture(GL.GL_TEXTURE0);
             gl.glEnable(GL.GL_TEXTURE_2D);
@@ -10923,8 +11091,8 @@
                 System.err.println("parentcam != renderCamera");
 
 //            if (cam != lightCamera)
-            for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
+            //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
         }
         
         LA.xformDir(lightposition, cam.toScreen, lightposition);
@@ -10945,8 +11113,8 @@
             if (true) // TODO
             {
                 if (cam != lightCamera)
-                for (int count = parentcam.GetTransformCount(); --count>=0;)
-                   LA.xformDir(light0, parentcam.toParent, light0); // may 2013
+                //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                   LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
             }
             
             LA.xformPos(light0, cam.toScreen, light0);
@@ -11291,6 +11459,24 @@
 
     static boolean zoomonce = false;
     
+    void CreateSelectedPoint()
+    {
+        if (selectedpoint == null)
+        {
+            debugpointG = new Sphere();
+            debugpointP = new Sphere();
+            debugpointC = new Sphere();
+            debugpointR = new Sphere();
+            
+            selectedpoint = new Superellipsoid();
+            
+            for (int i=0; i<8; i++)
+            {
+                debugpoints[i] = new Sphere();
+            }
+        }
+    }
+    
     void DrawObject(GL gl, boolean draw)
     {
         //System.out.println("DRAW OBJECT " + mouseDown);
@@ -11354,7 +11540,14 @@
 
                 usedtextures.clear();
             
-                BindTextures(DEFAULT_TEXTURES, 2);
+    try
+    {
+        BindTextures(DEFAULT_TEXTURES, 2);
+    }
+    catch (Exception e)
+    {
+        System.err.println("FAILED: " + DEFAULT_TEXTURES);
+    }
             }
             //System.out.println("--> " + stackdepth);
 //            GrafreeD.traceon();
@@ -11364,8 +11557,9 @@
             
             if (DrawMode() == DEFAULT)
             {
-                if (DEBUG)
+                if (Globals.DEBUG)
                 {
+                    CreateSelectedPoint();
                     float radius = 0.05f;
                     if (selectedpoint.radius != radius)
                     {
@@ -11445,7 +11639,14 @@
             if (checker != null && DrawMode() == DEFAULT)
             {
                 //BindTexture(IMMORTAL_TEXTURE);
-                BindTextures(checker.GetTextures(), checker.texres);
+    try
+    {
+        BindTextures(checker.GetTextures(), checker.texres);
+    }
+    catch (Exception e)
+    {
+        System.err.println("FAILED: " + checker.GetTextures());
+    }
                 // NEAREST
                 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
                 DrawChecker(gl);
@@ -11527,7 +11728,7 @@
             return;
         }
 
-        String string = obj.GetToolTip();
+        String string = obj.toString(); //.GetToolTip();
         
         GL gl = GetGL();
         
@@ -11844,8 +12045,8 @@
             //obj.TransformToWorld(light, light);
             for (int i = tp.size(); --i >= 0;)
             {
-                for (int count = tp.get(i).GetTransformCount(); --count>=0;)
-                    LA.xformPos(light, tp.get(i).toParent, light);
+                //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
+                    LA.xformPos(light, tp.get(i).GlobalTransform(), light);
             }
 
 
@@ -11862,8 +12063,8 @@
                 parentcam = cameras[0];
             }
             
-        for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.xformPos(light, parentcam.toParent, light); // may 2013
+        //for (int count = parentcam.GetTransformCount(); --count>=0;)
+            LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
 
             LA.xformPos(light, renderCamera.toScreen, light);
             
@@ -12477,8 +12678,8 @@
 
            // display shadow only (bump == 0)
          "SUB temp.x, half.x, shadow.x;" +
-         "MOV temp.y, -params6.x;" +
-         "SLT temp.z, temp.y, zero.x;" +
+         "MOV temp.y, -params5.z;" + // params6.x;" +
+         "SLT temp.z, temp.y, -one2048th.x;" +
          "SUB temp.y, one.x, temp.z;" +
          "MUL temp.x, temp.x, temp.y;" +
          "KIL temp.x;" +
@@ -12809,7 +13010,7 @@
             //once = true;
         }
 
-        System.out.print("Program #" + mode + "; length = " + program.length());
+        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);
 
@@ -12942,12 +13143,16 @@
 
                 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
                 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
+                
+                // Compare fragment depth in light space with shadowmap.
                 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
                 "SGE temp.y, temp.x, zero.x;" +
-                "SUB " + shadow + ".y, one.x, temp.y;" +
+                "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
+                
+                // Reverse comparison
                 "SUB temp.x, one.x, temp.x;" +
                 "MUL " + shadow + ".x, temp.x, temp.y;" +
-                "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
+                "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
                 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
 
                 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
@@ -12961,6 +13166,10 @@
                 // No shadow for backface
                 "DP3 temp.x, normal, lightd;" +
                 "SLT temp.x, temp.x, zero.x;" + // shadoweps
+                "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
+
+                // No shadow when out of frustrum
+                "SGE temp.x, " + depth + ".z, one.z;" +
                 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
                 "";
     }
@@ -13107,7 +13316,8 @@
     /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
     /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
     /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
-    Object3D.cVector2[] vector2buffer;
+    
+    //Object3D.cVector2[] vector2buffer;
 
     // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
     // OUT : diff, spec
@@ -13776,9 +13986,12 @@
     
     public void mouseDragged(MouseEvent e)
     {
+        Globals.MOUSEDRAGGED = true;
+        
         //System.out.println("mouseDragged: " + e);
         if (isRenderer)
             movingcamera = true;
+        
         //if (drawing)
         //return;
         if ((e.getModifiersEx() & CTRL) != 0
@@ -14328,7 +14541,9 @@
         ci.camera = renderCamera;
         if (!isRenderer)
         {
-            if (object.editWindow.copy.doEditClick(ci, 0))
+            ObjEditor editWindow = object.editWindow;
+            Object3D copy = editWindow.copy;
+            if (copy.doEditClick(ci, 0))
             {
                 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
             } else
@@ -14340,7 +14555,10 @@
 
     public void mouseReleased(MouseEvent e)
     {
+        Globals.MOUSEDRAGGED = false;
+        
         movingcamera = false;
+        X = Y = 0;
         //System.out.println("mouseReleased: " + e);
         clickEnd(e.getX(), e.getY(), e.getModifiersEx());
     }
@@ -14706,8 +14924,14 @@
                 RevertCamera();
                 repaint();
                 break;
-            case 'L':
             case 'l':
+                lightMode ^= true;
+                Globals.lighttouched = true;
+                manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
+                targetLookAt.set(manipCamera.lookAt);
+                repaint();
+                break;
+            case 'L':
                 if (lightMode)
                 {
                     lightMode = false;
@@ -14854,23 +15078,21 @@
                 kompactbit = 6;
                 break;
             case ' ':
-                lightMode ^= true;
-                Globals.lighttouched = true;
-                manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
-                targetLookAt.set(manipCamera.lookAt);
+                ObjEditor.theFrame.ToggleFullScreen();
                 repaint();
                 break;
             //case '`' :
             case ESC:
                 RENDERPROGRAM += 1;
                 RENDERPROGRAM %= 3;
+
                 repaint();
                 break;
             case 'Z':
                 //RESIZETEXTURE ^= true;
                 //break;
             case 'z':
-                RENDERSHADOW ^= true;
+                Globals.RENDERSHADOW ^= true;
                 Globals.lighttouched = true;
                 repaint();
                 break;
@@ -15349,7 +15571,9 @@
         info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
         //Image img = CreateImage(width, height);
         //System.out.println("width = " + width + "; height = " + height + "\n");
+        
         Graphics gr = g; // img.getGraphics();
+        
         if (!hasMarquee)
         {
             if (Xmin < Xmax) // !locked)
@@ -15447,14 +15671,33 @@
             if (!isRenderer)
             {
                 object.drawEditHandles(info, 0);
+                
+                if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
+                {
+                    switch (object.selection.get(0).hitSomething)
+                    {
+                        case Object3D.hitCenter: gr.setColor(Color.pink);
+                            gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                            break;
+                        case Object3D.hitRotate: gr.setColor(Color.yellow);
+                            gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                        break;
+                        case Object3D.hitScale: gr.setColor(Color.cyan);
+                            gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                        break;
+                    }
+                    
+                }
             }
         }
+        
         if (isRenderer)
         {
         //gr.setColor(Color.black);
         //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
         //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
         }
+        
         if (hasMarquee)
         {
             gr.setXORMode(Color.white);
@@ -15861,7 +16104,7 @@
     Object3D object;
     static Object3D trackedobject;
     Camera renderCamera; // Light or Eye (or Occlusion)
-    /*static*/ Camera manipCamera; // Light or Eye
+    /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
 	/*static*/ Camera eyeCamera;
     /*static*/ Camera lightCamera;
     int cameracount;
@@ -16146,16 +16389,16 @@
                 cStatic.objectstack[materialdepth++] = checker;
                 //System.out.println("material " + material);
                 //Applet3D.tracein(this, selected);
-                vector2buffer = checker.projectedVertices;
+                //vector2buffer = checker.projectedVertices;
 
         //checker.GetMaterial().Draw(this, false); // true);
-        DrawMaterial(checker.GetMaterial(), false); // true);
+        DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
 
                 materialdepth -= 1;
                 if (materialdepth > 0)
                 {
-                    vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
-                    DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
+                    //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
+                    DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
                 }
         //checker.GetMaterial().opacity = 1f;
         ////checker.GetMaterial().ambient = 1f;
@@ -16592,7 +16835,7 @@
                 gl.glDisable(gl.GL_CULL_FACE);
             }
 
-            if (!RENDERSHADOW)
+            if (!Globals.RENDERSHADOW)
                 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
             // SB gl.glPolygonOffset(2.5f, 10);
@@ -16602,7 +16845,7 @@
             //gl.glColorMask(false, false, false, false);
 
             //render_scene_from_light_view(gl, drawable, 0, 0);
-            if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
+            if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
             {
                 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
@@ -17018,23 +17261,15 @@
     int AAbuffersize = 0;
     
     //double[] selectedpoint = new double[3];
-    static Superellipsoid selectedpoint = new Superellipsoid();
+    static Superellipsoid selectedpoint;
     static Sphere previousselectedpoint = null;
-    static Sphere debugpointG = new Sphere();
-    static Sphere debugpointP = new Sphere();
-    static Sphere debugpointC = new Sphere();
-    static Sphere debugpointR = new Sphere();
+    static Sphere debugpointG;
+    static Sphere debugpointP;
+    static Sphere debugpointC;
+    static Sphere debugpointR;
     
     static Sphere debugpoints[] = new Sphere[8];
  
-    static
-    {
-        for (int i=0; i<8; i++)
-        {
-            debugpoints[i] = new Sphere();
-        }
-    }
-    
     static void InitPoints(float radius)
     {
         for (int i=0; i<8; i++)

--
Gitblit v1.6.2