From 57c5b6cd8d12ffdaa3e0b099451e3c031012750a Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 03 Oct 2019 20:34:32 -0400
Subject: [PATCH] Fix lighttouched

---
 CameraPane.java |  888 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 643 insertions(+), 245 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index e8611a1..b60cf14 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -1,4 +1,5 @@
 
+import com.bulletphysics.dynamics.RigidBody;
 import java.awt.*;
 import java.awt.event.*;
 import java.awt.image.*;
@@ -123,7 +124,7 @@
 static    boolean LOCALTRANSFORM = false;
 static    boolean FULLSCREEN = false;
 static    boolean SUPPORT = true;
-static    boolean INERTIA = true;
+static    boolean INERTIA = false; // true;
 static    boolean FAST = false;
 static    boolean SLOWPOSE = false;
 static    boolean FOOTCONTACT = true;
@@ -134,7 +135,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;
@@ -174,7 +175,7 @@
     boolean Udebug = false;
     boolean Vdebug = false;
     boolean NORMALdebug = false;
-    static boolean doublesided = false; // true; // reversed normals are awful for conformance
+    static boolean doublesided = true; // false; // reversed normals are awful for conformance
     boolean anisotropy = true;
     boolean softshadow = true; // slower but better false;
     boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
@@ -221,10 +222,10 @@
         cameras = new Camera[2];
         targetLookAts = new cVector[2];
 
-        SetCamera(cam);
+        SetCamera(cam, true);
 
         // Warning: not used.
-        SetLight(new Camera(new cVector(15, 10, -20)));
+        //SetLight(new Camera(new cVector(15, 10, -20)));
 
         object = o;
 
@@ -249,7 +250,7 @@
     
     public javax.media.opengl.GL GetGL0()
     {
-            return null;
+            return currentGL;
     }
     
     public int GenList()
@@ -542,7 +543,8 @@
                 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
                 LA.vecCross(obj.v0, obj.v1, obj.v2);
                 LA.vecNormalize(obj.v2);
-                gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
+                
+                SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
             }
 
             // P
@@ -564,7 +566,7 @@
                 y += ny * obj.NORMALPUSH;
                 z += nz * obj.NORMALPUSH;
                 
-                gl.glNormal3f(nx, ny, nz);
+                SetGLNormal(gl, nx, ny, nz);
             }
             gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
             SetColor(obj, pv);
@@ -596,7 +598,7 @@
                 y += ny * obj.NORMALPUSH;
                 z += nz * obj.NORMALPUSH;
                 
-                gl.glNormal3f(nx, ny, nz);
+                SetGLNormal(gl, nx, ny, nz);
             }
             //System.out.println("vertexq = " + qv.s + ", " + qv.t);
         //    boolean locked = false;
@@ -644,7 +646,7 @@
                 y += ny * obj.NORMALPUSH;
                 z += nz * obj.NORMALPUSH;
                 
-                gl.glNormal3f(nx, ny, nz);
+                SetGLNormal(gl, nx, ny, nz);
             }
             
         //    if ((dot&4) == 0)
@@ -880,7 +882,7 @@
 ////        tris.postdraw(this);
     }
 
-    static Camera localcamera = new Camera();
+    static Camera localAOcamera = new Camera();
     static cVector from = new cVector();
     static cVector to = new cVector();
     
@@ -889,7 +891,7 @@
                 CameraPane cp = this;
 
                 Camera keep = cp.RenderCamera();
-                cp.renderCamera = localcamera;
+                cp.renderCamera = localAOcamera;
 
                 if (br.trimmed)
                 {
@@ -907,7 +909,7 @@
                                 br.positions[i3 + 2] + br.normals[i3 + 2]);
                         LA.xformPos(from, transform, from);
                         LA.xformPos(to, transform, to); // RIGID ONLY
-                        localcamera.setAim(from, to);
+                        localAOcamera.setAim(from, to);
 
                         CameraPane.occlusionbuffer.display();
 
@@ -941,7 +943,7 @@
                         to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
                         LA.xformPos(from, transform, from);
                         LA.xformPos(to, transform, to); // RIGID ONLY
-                        localcamera.setAim(from, to);
+                        localAOcamera.setAim(from, to);
 
                         CameraPane.occlusionbuffer.display();
 
@@ -1250,10 +1252,10 @@
                             {
                                 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
                                 {
-                                    gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+                                    SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
                                 } else
                                 {
-                                    gl.glNormal3f(0, 0, 1);
+                                    SetGLNormal(gl, 0, 0, 1);
                                 }
 
                                 if (c != null)
@@ -1277,10 +1279,10 @@
                             {
                                 if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
                                 {
-                                    gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+                                    SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
                                 } else
                                 {
-                                    gl.glNormal3f(0, 0, 1);
+                                    SetGLNormal(gl, 0, 0, 1);
                                 }
                                 if (c != null)
                                 {
@@ -1305,10 +1307,10 @@
                                 {
                                     if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
                                     {
-                                        gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+                                        SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
                                     } else
                                     {
-                                        gl.glNormal3f(0, 0, 1);
+                                        SetGLNormal(gl, 0, 0, 1);
                                     }
                                     if (c != null)
                                     {
@@ -1490,7 +1492,7 @@
     {
         if (!selectmode)
         {
-            gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
+            SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
             gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
             
             if (flipV)
@@ -1528,7 +1530,7 @@
                 }
             }
             float b = 0;
-            if (obj.support != null && obj.link2master)
+            if (obj.support != null && obj.Link2Support())
             {
                 b = 1;
             }
@@ -2063,7 +2065,7 @@
     
     static int camerachangeframe;
     
-    public boolean SetCamera(Camera cam)
+    public boolean SetCamera(Camera cam, boolean set)
     {
         // may 2014 if (cam == cameras[0] || cam == cameras[1])
         //    return false;
@@ -2081,7 +2083,8 @@
         
         camerachangeframe = Globals.framecount;
         
-        cam.hAspect = -1; // Read only
+        if (cam != null)
+            cam.hAspect = -1; // Read only
 
         cameras[0] = cam;
         targetLookAts[0] = new cVector(cam.lookAt);
@@ -2091,11 +2094,14 @@
             {
                 cameras[i] = new Camera(cam.viewCode);
             }
-
-            cameras[i].setAim(cam.location, cam.lookAt);
-            cameras[i].shaper_fovy = cam.shaper_fovy;
-            cameras[i].UP.set(cam.UP);
-            targetLookAts[i] = new cVector(cameras[i].lookAt);
+            
+            if (set)
+            {
+                cameras[i].setAim(cam.location, cam.lookAt);
+                cameras[i].shaper_fovy = cam.shaper_fovy;
+                cameras[i].UP.set(cam.UP);
+                targetLookAts[i] = new cVector(cameras[i].lookAt);
+            }
         }
         cameracount = 0;
         targetLookAt = targetLookAts[cameracount];
@@ -2104,7 +2110,7 @@
         // Start with free camera
         SwitchCameras(true);
         
-        pingthread.jump = true; // optional?
+//        pingthread.jump = true; // optional?
         
         if (TRACKONCE)
         {
@@ -2291,18 +2297,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();
     }
@@ -2394,7 +2388,8 @@
     {
         //System.out.println("PROTECTION = " + cam.hAspect);
         //assert (cam.hAspect == 0);
-        cam.hAspect = 0;
+        if (cam != null)
+            cam.hAspect = 0;
         lightCamera = cam;
     }
 
@@ -2473,6 +2468,18 @@
         byte[] bytes = bytebuf.array();
         
         return CreateBim(bytes, width, height);
+    }
+
+    private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
+    {
+        gl.glNormal3f(nx, ny, nz);
+
+        if (ny > 0.9 || ny < -0.9)
+            // Ground or ceiling
+            gl.glVertexAttrib3f(4, 1, 0, 0);
+        else
+            // Walls
+            gl.glVertexAttrib3f(4, 0, 1, 0);
     }
 
     /**/
@@ -3583,6 +3590,8 @@
            };
      /**/
         
+        static Object3D lastObject;
+        
         //com.sun.opengl.util.texture.Texture
         TextureData
                 GetFileTexture(String name, boolean bump, int resolution)
@@ -3619,6 +3628,8 @@
                 //    return null;
                     //if (i == 2)
                     //    return null;
+                    // TIFF issue sept 2019
+                    System.err.println("lastObject = " + lastObject);
                     e.printStackTrace();
                     name = name.split("\\.tif")[0] + ".jpg";
                 }
@@ -6951,30 +6962,30 @@
                     short residu = 0;
 
                 // wraparound workarounds
-                    short fuck = (short) (buffer[i] & 0xFF);
+                    short ww = (short) (buffer[i] & 0xFF);
                     /*
-                    residu += (fuck%2);
-                    if(fuck/2 < 256-residu/2)
+                    residu += (ww%2);
+                    if(ww/2 < 256-residu/2)
                     {
-                    fuck = (short)((fuck/2) + residu/2);
+                    ww = (short)((ww/2) + residu/2);
                     if(residu == 2)
                     residu = 0;
                     }
                     else
                     {
                     residu = 0;
-                    fuck /= 2;
+                    ww /= 2;
                     }
                      */
-                    if (i < imglength / 3 || rnd.nextFloat() < 0.5 || fuck >= 254)
+                    if (i < imglength / 3 || rnd.nextFloat() < 0.5 || ww >= 254)
                     {
-                        fuck /= 2;
+                        ww /= 2;
                     } else
                     {
-                        fuck = (short) ((fuck / 2) + fuck % 2);
+                        ww = (short) ((ww / 2) + ww % 2);
                     }
 
-                    buffer[i] = (byte) fuck;
+                    buffer[i] = (byte) ww;
                 }
             //System.out.print(bytes[i] + " ");
             //if(buffer[i] >= 0 && buffer[i]<=eps-1) buffer[i] = eps;
@@ -8441,12 +8452,12 @@
                         {
                 //            texturecache = textures.get(texname); // suspicious
                             if (texturecache == null)
-                                texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
+                                texturecache = new CacheTexture(GetResourceTexture("whitenoise.jpg", bump),resolution);
                             else
                                 new Exception().printStackTrace();
                         } else
                         {
-                        if (texname.startsWith("@"))
+                        if (texname.startsWith("@") && textureon)
                         {
                 //            texturecache = textures.get(texname); // suspicious
                             if (texturecache == null)
@@ -8629,7 +8640,9 @@
             {
                 tex.bw = texturecache.texturedata.getWidth();
                 tex.bh = texturecache.texturedata.getHeight();
-                tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
+                tex.bumpdata = //CompressJPEG(CreateBim(
+                        ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
+                        //, tex.bw, tex.bh), 0.5f);
             }
         }
     }
@@ -9827,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 ? 1.2 : 1),
                     ratio,
                     //near_plane, far_plane,
                     renderCamera.shaper_zNear * renderCamera.Distance(), renderCamera.shaper_zFar * renderCamera.Distance(),
@@ -10699,7 +10715,7 @@
         if (patchMaterial.patchMaterial)
         {
             patchMaterial.patchMaterial = false;
-            patchMaterial.objectPanel.setSelectedIndex(1);
+            patchMaterial.objectTabbedPane.setSelectedIndex(1);
         }
         
         if (Grafreed.savesound && Grafreed.hassound)
@@ -10745,7 +10761,9 @@
         }
         /**/
 
-        if (selection)
+        boolean control = ((modifiers & CTRL) != 0);
+        
+        if (selection && (!Globals.isLIVE() || control))
         {
             selectbuffer.display();
             return;
@@ -10797,6 +10815,112 @@
 
         if (DrawMode() == DEFAULT)
         {
+            if (manipCamera == lightCamera)
+            {
+//                    switch (e.getKeyCode())
+//                    {
+//                        case DOWN_ARROW:
+//                            lightCamera.DECAL /= 2;
+//                            repaint();
+//                            break;
+//                        case UP_ARROW:
+//                            lightCamera.DECAL *= 2;
+//                            repaint();
+//                            break;
+//                        case LEFT_ARROW:
+//                            lightCamera.SCALE /= 2;
+//                            repaint();
+//                            break;
+//                        case RIGHT_ARROW:
+//                            lightCamera.SCALE *= 2;
+//                            repaint();
+//                            break;
+//                        default:
+//                            break;
+                if (keys[DOWN_ARROW])
+                {
+                    lightCamera.DECAL /= 2;
+                }
+
+                if (keys[UP_ARROW])
+                {
+                    lightCamera.DECAL *= 2;
+                }
+
+                if (keys[LEFT_ARROW])
+                {
+                    lightCamera.SCALE /= 2;
+                }
+
+                if (keys[RIGHT_ARROW])
+                {
+                    lightCamera.SCALE *= 2;
+                }
+            }
+            else
+            {
+                //pingthread.mute = true;
+        
+                boolean keyon = false;
+                
+                if (keys[DOWN_ARROW])
+                {
+                    speed = ++speedkey[DOWN_ARROW];
+                    if (speed > 20)
+                        speed = 20;
+                    GoDown(modifiers);
+                    keyon = true;
+                }
+                else
+                    speedkey[DOWN_ARROW] = 0;
+
+                if (keys[UP_ARROW])
+                {
+                    speed = ++speedkey[UP_ARROW];
+                    if (speed > 20)
+                        speed = 20;
+                    GoUp(modifiers);
+                    keyon = true;
+                }
+                else
+                    speedkey[UP_ARROW] = 0;
+
+                if (keys[LEFT_ARROW])
+                {
+                    speed = ++speedkey[LEFT_ARROW];
+                    if (speed > 20)
+                        speed = 20;
+                    GoLeft(modifiers);
+                    keyon = true;
+                }
+                else 
+                    speedkey[LEFT_ARROW] = 0;
+
+                if (keys[RIGHT_ARROW])
+                {
+                    speed = ++speedkey[RIGHT_ARROW];
+                    if (speed > 20)
+                        speed = 20;
+                    GoRight(modifiers);
+                    keyon = true;
+                }
+                else
+                    speedkey[RIGHT_ARROW] = 0;
+                
+                if (Globals.WALK && capsLocked)
+                {
+                    Walk();
+                    keyon = true;
+                }
+                
+                if (keyon)
+                {
+                    repaint();
+                }
+                
+                //pingthread.mute = false;
+            }
+            
             currentlydrawing = true;
         }
 
@@ -11321,9 +11445,9 @@
 
             gl.glMatrixMode(GL.GL_MODELVIEW);
 
-gl.glEnable(gl.GL_POLYGON_SMOOTH);
-gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
-gl.glEnable(gl.GL_MULTISAMPLE);
+//gl.glEnable(gl.GL_POLYGON_SMOOTH);
+//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
+//gl.glEnable(gl.GL_MULTISAMPLE);
         } else
         {
             //gl.glDisable(GL.GL_TEXTURE_2D);
@@ -11384,7 +11508,10 @@
                 //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 ? 1.2 : 1),
+                            ratio, cam.shaper_zNear * cam.Distance(), cam.shaper_zFar * cam.Distance());
                 }
             }
 
@@ -11740,8 +11867,11 @@
             repaint();
         }
         
-        if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
+        if (Globals.isLIVE() && DrawMode() == DEFAULT || pingthread.live) // may 2013
+        {
+            renderCamera.computeTransform();
             repaint();
+        }
         
         displaydone = true;
     }
@@ -11816,9 +11946,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;
         }
 
@@ -12501,8 +12645,9 @@
         String programmin =
                 // Min shader
                 "!!ARBfp1.0\n" +
-                "PARAM zero123      = { 0.0, 1.0, 2, 1.25 };" +
-                "PARAM pow2      = { 0.5, 0.25, 0.125, 0.0 };" +
+                "PARAM zero12t      = { 0.0, 1.0, 2, 1.25 };" +
+                "PARAM pow_2      = { 0.5, 0.25, 0.125, 0.0 };" +
+                "PARAM pow2      = { 2, 4, 8, 0.0 };" +
                 "PARAM one      = { 1.0, 1.0, 1.0, 1.0 };" +
                 "PARAM eps      = { 0.001, 0.001, 0.001, 1.0 };" +
                 "PARAM infinity  = { 100000000, 100000000, 100000000, 1.0 };" +
@@ -12517,10 +12662,11 @@
                 "TEMP eye;" +
                 "TEMP pos;" +
                 
-                "MAD normal, fragment.color, zero123.z, -zero123.y;" +
+                "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
                 Normalize("normal") +
                 "MOV light, state.light[0].position;" +
                 "DP3 ndotl.x, light, normal;" +
+                "MAX ndotl.x, ndotl.x, zero12t.x;" +
 
                 // shadow
                 "MOV pos, fragment.texcoord[1];" +
@@ -12536,7 +12682,7 @@
                 "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
                 
                 // Backlit
-                "MOV pos.w, zero123.y;" +
+                "MOV pos.w, zero12t.y;" + // one
                 "DP4 eye.x, pos, light2cam0;" +
                 "DP4 eye.y, pos, light2cam1;" +
                 "DP4 eye.z, pos, light2cam2;" +
@@ -12544,24 +12690,28 @@
                 
                 "DP3 ndotl.y, -eye, normal;" +
                 //"MUL ndotl.y, ndotl.y, pow2.x;" +
-                "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
-                "SUB ndotl.y, zero123.y, ndotl.y;" +
+                "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
+                "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
+                //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
                 //"SUB ndotl.y, zero123.y, ndotl.y;" +
                 //"MUL ndotl.y, ndotl.y, pow2.z;" +
+                "ADD ndotl.y, ndotl.y, one.x;" +
+                "MUL ndotl.y, ndotl.y, pow_2.x;" +
                 
                 //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
                 //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
                 
                 // Pigment
                 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
-                "LRP temp, zero123.w, temp, one;" + // texture proportion
-                "MUL temp, temp, ndotl.x;" +
-                
-                "MUL temp, temp, zero123.z;" +
+                "LRP temp, zero12t.w, temp, one;" + // texture proportion
+                "MUL temp, temp, zero12t.w;" + // Times x
                 
                 //"MUL temp, temp, ndotl.y;" +
+                "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
                 
-                "MOV temp.w, zero123.y;" + // reset alpha
+                "MUL temp, temp, ndotl.x;" + // lambert
+                
+                "MOV temp.w, zero12t.y;" + // reset alpha
                 "MOV result.color, temp;" +
                 "END";
         
@@ -12933,24 +13083,34 @@
                 "ADD temp.x, temp.x, one.x;" +
                 "MUL normal, normal, temp.xxxx;":""
               ) +
-                 /**/
-////      Normalize("normal") +
-////      "MAX normal.z, eps.x, normal.z;" +
-//                Normalize("normal") +
-                "MOV normald, normal;" +
-                "MOV normals, normal;" +
+                /**/
+                
+                "MOV temp, fragment.texcoord[4];" +
                 
                 // UV base		
                 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
                 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
                 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
-                "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
-                "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
-                "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
+                "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
+                "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
+                "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
+                Normalize("UP") +
+                
                 "XPD V, normal, UP;" +
                 Normalize("V") +
                 "XPD U, V, normal;" +
                 Normalize("U") +
+                
+                "MOV temp, fragment.texcoord[0];" +
+                
+//                "MAD normal, -temp.x, U, normal;" +
+//                "MAD normal, -temp.y, V, normal;" +
+//                Normalize("normal") +
+                
+////      "MAX normal.z, eps.x, normal.z;" +
+//                Normalize("normal") +
+                "MOV normald, normal;" +
+                "MOV normals, normal;" +
                 
 // parallax mapping
 
@@ -12964,22 +13124,24 @@
                 "RCP temp2.w, temp2.w;" +
                 
                 "SUB temp2.w, temp2.w, half;" +
-//                "SGE temp.x, temp2.w, eps.x;" +
-//                "MUL temp2.w, temp2.w, temp.x;" +
+                // "SGE temp.x, temp2.w, eps.x;" +
+                // "MUL temp2.w, temp2.w, temp.x;" +
                 
-                //"MOV texSamp, U;" +
+                // "MOV texSamp, U;" +
                 
                 "MUL temp2.z, temp2.z, temp2.w;" +
                 "MUL temp2.z, temp2.z, params7.z;" + // parallax
                 
                 "MUL temp2, temp2, temp2.z;" +
                 
-                "MOV temp, fragment.texcoord[0];" +
-                
                 "SUB temp, temp, temp2;" +
                 
-                "TEX texSamp, temp, texture[0], 2D;" +
-                "POW texSamp.a, texSamp.a, params6.w;" + // punch through
+                "TEX temp, temp, texture[0], 2D;" +
+                "POW temp.a, temp.a, params6.w;" + // punch through
+                
+                "ADD texSamp, temp, texSamp;" +
+                "MUL texSamp.xyz, half, texSamp;" +
+                
                 "MOV alpha, texSamp.aaaa;" +
                 
 // parallax mapping
@@ -13936,7 +14098,7 @@
                 "PARAM p[4]    = { state.matrix.projection };     # modelview projection matrix\n" +
                 "PARAM zero    = { 0.0, 0.0, 0.0, 1.0 };" +
                 "PARAM half    = { 0.5, 0.5, 0.5, 1.0 };" +
-                "PARAM one     = { 1.0, 1.0, 1.0, 0.0 };" +
+                "PARAM one     = { 1.0, 1.0, 1.0, 1.0 };" +
                 "PARAM two     = { 2.0, 2.0, 2.0, 1.0 };" +
                 "PARAM third   = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
                 //"PARAM v256    = { 256.0, 256.0, 256.0, 1.0 };" +
@@ -13997,7 +14159,7 @@
                 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
                 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
                 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
-                //"MOV result.texcoord, vertex.texcoord;" +
+                //"MOV result.texcoord, vertex.fogcoord;" +
                 "MOV result.texcoord, temp;" +
                 // border fade
                 "MOV result.texcoord[3], vertex.texcoord;" +
@@ -14044,7 +14206,9 @@
 
                 //"ADD temp.z, temp.z, one;" +
 
-                "MOV result.color, temp;"
+                "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
+                
+                "MOV result.color, temp;" // Normal
                 : "MOV result.color, vertex.color;") +
                 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
                 : "") +
@@ -14179,6 +14343,7 @@
     public void mouseClicked(MouseEvent e)
     {
         System.out.println("mouseClicked: " + e);
+        System.exit(0);
     }
 
     public void mousePressed(MouseEvent e)
@@ -14217,10 +14382,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;
@@ -14261,7 +14428,7 @@
         //}
         
         SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
-        drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
+        drag(anchorX, anchorY + e.getUnitsToScroll()*8, e.getModifiers(), e.getModifiersEx());
         anchorX = ax;
         anchorY = ay;
         prevX = px;
@@ -14356,8 +14523,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();
     }
@@ -14452,8 +14620,8 @@
         
         //if (drawing)
         //return;
-        if ((e.getModifiersEx() & CTRL) != 0
-            || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
+        if ((e.getModifiersEx() & CTRL) != 0 ||
+            (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
         {
             //System.out.println("mouseDragged: " + e);
             clickEnd(e.getX(), e.getY(), e.getModifiersEx());
@@ -14477,9 +14645,17 @@
             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 = false;
         
 //        void JumpToTarget()
 //        {
@@ -14495,6 +14671,95 @@
         // only one thread!? synchronized
                 void StepToTarget(boolean jump)
         {
+            RigidBody.pos.x = 0;
+            RigidBody.pos.y = 0;
+            RigidBody.pos.z = 0;
+            if (RigidBody.justclicked)
+            {
+//                RigidBody.pos.x = (float)manipCamera.lookAt.x;
+//                RigidBody.pos.y = (float)manipCamera.lookAt.y;
+//                RigidBody.pos.z = (float)manipCamera.lookAt.z;
+                                 //       System.err.println("selected point = " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][1]) + " " + Trunk(selectedpoint.toParent[3][2]));
+                CreateSelectedPoint();
+                
+                RigidBody.pos.x = (float)selectedpoint.toParent[3][0];
+                RigidBody.pos.y = (float)selectedpoint.toParent[3][1];
+                RigidBody.pos.z = (float)selectedpoint.toParent[3][2];
+
+                RigidBody.wind.set(RigidBody.pos);
+                RigidBody.wind.x -= (float)manipCamera.location.x;
+                RigidBody.wind.y -= (float)manipCamera.location.y;
+                RigidBody.wind.z -= (float)manipCamera.location.z;
+                RigidBody.wind.normalize();
+            }
+                    
+            if (mute)
+                return;
+            
+            if (capsLocked && manipCamera.viewCode == 0)
+            {
+                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
             
@@ -14532,7 +14797,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)
@@ -14567,7 +14832,10 @@
                 if (tmp.dot(tmp) < 0.00001)
                 {
                     zoomonce = false;
+                    live = false;
                 }
+                else
+                    live = true;
                 
                 tmp.mul(step > step2 ? step : step2);
             }
@@ -14594,7 +14862,7 @@
             {
                 if (LOOKAT)
                     manipCamera.lookAt.add(tmp);
-                if (OEIL)
+                if (OEIL && !capsLocked)
                     manipCamera.location.add(tmp);
                 
                 {
@@ -14609,7 +14877,10 @@
                     lightCamera.computeTransform();
                     }
                 }
-                manipCamera.computeTransform();
+                if (tmp.x != 0 || tmp.y != 0 || tmp.z != 0)
+                {
+                    manipCamera.computeTransform();
+                }
             }
 // ??????            mouseDown = true;
             //System.out.println("----------------   ----------      Paint " + tmp.length2());
@@ -14702,11 +14973,32 @@
             }
         }
         }
+    
     PingThread pingthread = new PingThread();
-    int delta = 5;
-    int speed = 5;
+    int delta = 1;
+    int speed = 1;
+    int walk = 8;
     boolean autorepeat = false;
 
+    void Walk()
+    {
+        manipCamera.BackForth(0, walk, 1000);
+        
+        targetLookAt.set(manipCamera.lookAt);
+    }
+    
+    void ViewAngle(float dy)
+    {
+        double factor = Math.exp(-dy/300.0); // (1 + dy/100);
+                    
+        if (manipCamera.shaper_fovy * factor > 1 &&
+            manipCamera.shaper_fovy * factor < 150)
+        {
+            manipCamera.shaper_fovy *= factor;
+            //System.out.println("fovy = " + shaper_fovy);
+        }
+    }
+    
     void GoDown(int mod)
     {
         MODIFIERS |= COMMAND;
@@ -14714,21 +15006,30 @@
         /**/
         if((mod&SHIFT) == SHIFT)
         {
+//            if (isVR)
+//                manipCamera.RotateInterest(0, speed);
+//            else
             if (isVR)
-                manipCamera.RotateInterest(0, -speed);
+                ViewAngle(-speed*delta);
+            else
+                manipCamera.Translate(0, -speed*delta, getWidth());
+        }
+        else
+        {
+            if (isVR)
+                manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
             else
                 manipCamera.RotatePosition(0, -speed);
         }
-        else
-            manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
+        
         /**/
-        if ((mod & SHIFT) == SHIFT)
-        {
-            mouseMode = mouseMode; // VR??
-        } else
-        {
-            mouseMode |= BACKFORTH;
-        }
+//        if ((mod & SHIFT) == SHIFT)
+//        {
+//            mouseMode = mouseMode; // VR??
+//        } else
+//        {
+//            mouseMode |= BACKFORTH;
+//        }
 
         targetLookAt.set(manipCamera.lookAt);
         
@@ -14738,27 +15039,38 @@
 
     void GoUp(int mod)
     {
+                RigidBody.justclicked = true;
+        
         MODIFIERS |= COMMAND;
         /**/
         boolean isVR = (mouseMode&VR)!=0;
         
         if((mod&SHIFT) == SHIFT)
         {
+//            if (isVR)
+//                manipCamera.RotateInterest(0, -speed);
+//            else
             if (isVR)
-                manipCamera.RotateInterest(0, speed);
+                ViewAngle(speed*delta);
+            else
+                manipCamera.Translate(0, speed*delta, getWidth());
+        }
+        else
+        {
+            if (isVR)
+                manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
             else
                 manipCamera.RotatePosition(0, speed);
         }
-        else
-            manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
+        
         /**/
-        if ((mod & SHIFT) == SHIFT)
-        {
-            mouseMode = mouseMode;
-        } else
-        {
-            mouseMode |= BACKFORTH;
-        }
+//        if ((mod & SHIFT) == SHIFT)
+//        {
+//            mouseMode = mouseMode;
+//        } else
+//        {
+//            mouseMode |= BACKFORTH;
+//        }
 
         targetLookAt.set(manipCamera.lookAt);
         
@@ -14771,23 +15083,27 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-            manipCamera.Translate(speed*delta, 0, getWidth());
+            manipCamera.Translate(speed, 0, getWidth());
         else
         {
             if ((mouseMode&VR)!=0)
-                manipCamera.RotateInterest(-speed, 0);
+                manipCamera.RotateInterest(-speed*manipCamera.shaper_fovy/90, 0);
             else
-                manipCamera.RotatePosition(speed, 0);
+                manipCamera.RotatePosition(speed*manipCamera.shaper_fovy/90, 0);
         }
+        
         /**/
-        if ((mod & SHIFT) == SHIFT)
-        {
-            mouseMode = mouseMode;
-        } else
-        {
-            mouseMode |= ROTATE;
-        } // TRANSLATE;
+//        if ((mod & SHIFT) == SHIFT)
+//        {
+//            mouseMode = mouseMode;
+//        } else
+//        {
+//            mouseMode |= ROTATE;
+//        } // TRANSLATE;
 
+        //System.err.println("lookAt = " + manipCamera.lookAt);
+        //System.err.println("location = " + manipCamera.location);
+        
         targetLookAt.set(manipCamera.lookAt);
         
         prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
@@ -14799,23 +15115,23 @@
         MODIFIERS |= COMMAND;
         /**/
         if((mod&SHIFT) == SHIFT)
-            manipCamera.Translate(-speed*delta, 0, getWidth());
+            manipCamera.Translate(-speed, 0, getWidth());
         else
         {
             if ((mouseMode&VR)!=0)
-                manipCamera.RotateInterest(speed, 0);
+                manipCamera.RotateInterest(speed*manipCamera.shaper_fovy/90, 0);
             else
-                manipCamera.RotatePosition(-speed, 0);
+                manipCamera.RotatePosition(-speed*manipCamera.shaper_fovy/90, 0);
         }
         
         /**/
-        if ((mod & SHIFT) == SHIFT)
-        {
-            mouseMode = mouseMode;
-        } else
-        {
-            mouseMode |= ROTATE;
-        } // TRANSLATE;
+//        if ((mod & SHIFT) == SHIFT)
+//        {
+//            mouseMode = mouseMode;
+//        } else
+//        {
+//            mouseMode |= ROTATE;
+//        } // TRANSLATE;
 
         targetLookAt.set(manipCamera.lookAt);
         
@@ -14952,6 +15268,11 @@
                 if ((mouseMode & ZOOM) != 0)
                 {
                     //if ((mouseMode & BACKFORTH) != 0)
+                    if ((modifiersex & SHIFT) == SHIFT)
+                    {
+                        ViewAngle(dy);
+                    }
+                    else
                     if ((mouseMode & VR) != 0)
                         manipCamera.BackForth(dx, dy, getWidth());
                     else
@@ -15022,6 +15343,9 @@
         
     public void mouseMoved(MouseEvent e)
     {
+//object.editWindow.frame.
+        setCursor(Cursor.getDefaultCursor());
+
         //System.out.println("mouseMoved: " + e);
         if (isRenderer)
             return;
@@ -15050,6 +15374,12 @@
 
     public void mouseReleased(MouseEvent e)
     {
+        if (isRenderer && !movingcamera)
+        {
+            RigidBody.justclicked = true;
+            System.out.println("justclicked: " + e);
+        }
+        
         Globals.MOUSEDRAGGED = false;
         
         movingcamera = false;
@@ -15206,8 +15536,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;
         }
@@ -15219,7 +15551,8 @@
         {
             mouseMode |= SELECT;
         }
-        if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
+        if (//(modifiersex & SHIFT) == SHIFT ||
+                forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
         {
             mouseMode &= ~VR;
             mouseMode |= TRANSLATE;
@@ -15263,8 +15596,18 @@
     float SATPOW = 1; // 2; // 0.5f;
     float BRIPOW = 1; // 0.5f; // 0.5f;
     
+static BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
+
+// Create a new blank cursor.
+static Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
+    cursorImg, new Point(0, 0), "blank cursor");
+    
     public void keyPressed(int key)
     {
+// Set the blank cursor to the JFrame.
+//object.editWindow.frame.
+        setCursor(blankCursor);
+
         if (key >= '0' && key <= '5')
             clampbit = (key-'0');
         
@@ -15423,8 +15766,8 @@
                 RevertCamera();
                 repaint();
                 break;
-            case 'l':
-            //case 'L':
+            //case 'l':
+            case 'L':
                 if (lightMode)
                 {
                     lightMode = false;
@@ -15454,7 +15797,8 @@
                 break;
             case 'm':
             {
-                PrintMemory();
+                //PrintMemory();
+                ToggleImageFlip();
                 break;
             }
             case 'M':
@@ -15481,9 +15825,9 @@
                 repaint();
                 break;
             case 'O':
-                Globals.drawMode = OCCLUSION; // WARNING
-                repaint();
-                break;
+                // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
+                //repaint();
+                //break;
             case 'o':
                 OCCLUSION_CULLING ^= true;
                 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
@@ -15575,7 +15919,21 @@
 //                kompactbit = 6;
 //                break;
             case ' ':
+                capsLocked ^= true;
+                repaint();
+                break;
+            case 'l':
                 lightMode ^= true;
+                if (lightMode)
+                {
+                    keepshadow = Globals.RENDERSHADOW;
+                    Globals.RENDERSHADOW = false;
+                }
+                else
+                {
+                    Globals.RENDERSHADOW = keepshadow;
+                }
+        
                 Globals.lighttouched = true;
                 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
                 targetLookAt.set(manipCamera.lookAt);
@@ -15583,6 +15941,10 @@
                 break;
             //case '`' :
             case ESC:
+                if (FULLSCREEN)
+                    object.editWindow.ToggleFullScreen();
+                break;
+            case 'p':
                 RENDERPROGRAM += 1;
                 RENDERPROGRAM %= 3;
 
@@ -15621,6 +15983,10 @@
             case ENTER:
                 // object.editWindow.ScreenFit(); // Edit();
                 ToggleLive();
+                if (capsLocked)
+                {
+                    Globals.WALK ^= true;
+                }
                 break;
             case DELETE:
                 ClearSelection();
@@ -15657,17 +16023,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);
@@ -15683,7 +16055,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);
@@ -15721,98 +16095,113 @@
         }
     }
 
+    boolean keys[] = new boolean[256];
+    int speedkey[] = new int[256];
+    int modifiers = 0;
+    
     public void processKeyEvent(KeyEvent e)
     {
         switch (e.getID())
         {
             case KeyEvent.KEY_PRESSED:
-                if (!autorepeat)
-                {
-                    //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode()));
-                    keyPressed(e.getKeyChar(), e.getModifiersEx());
-                }
-                if (manipCamera == lightCamera)
-                {
-                    switch (e.getKeyCode())
-                    {
-                        case DOWN_ARROW:
-                            lightCamera.DECAL /= 2;
-                            repaint();
-                            break;
-                        case UP_ARROW:
-                            lightCamera.DECAL *= 2;
-                            repaint();
-                            break;
-                        case LEFT_ARROW:
-                            lightCamera.SCALE /= 2;
-                            repaint();
-                            break;
-                        case RIGHT_ARROW:
-                            lightCamera.SCALE *= 2;
-                            repaint();
-                            break;
-                        default:
-                            break;
-                    }
-                    
-                    System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE);
-                } else
-                {
-                    if (true) // !autorepeat)
-                    {
-                        boolean reset = true;
-
-                        switch (e.getKeyCode())
-                        {
-                            case DOWN_ARROW:
-                                GoDown(e.getModifiersEx());
-                                repaint();
-                                break;
-                            case UP_ARROW:
-                                GoUp(e.getModifiersEx());
-                                repaint();
-                                break;
-                            case LEFT_ARROW:
-                                GoLeft(e.getModifiersEx());
-                                repaint();
-                                break;
-                            case RIGHT_ARROW:
-                                GoRight(e.getModifiersEx());
-                                repaint();
-                                break;
-                            default:
-                                reset = false;
-                                break;
-                        }
-
-                        if (reset)
-                        {
-                            autorepeat = true;
-
-                            targetLookAt.set(manipCamera.lookAt);
-                        }
-                    }
-                }
+                keys[e.getKeyCode()] = true;
+                modifiers = e.getModifiersEx();
+                keyPressed(e.getKeyChar(), modifiers);
+                //Globals.theRenderer.keyPressed(e.getKeyChar());
+                repaint();
                 break;
-            case KeyEvent.KEY_TYPED:
-                break;
+//                if (!autorepeat)
+//                {
+//                    //System.out.println("processKeyEvent: " + KeyEvent.getKeyText(e.getKeyCode()));
+//                    keyPressed(e.getKeyChar(), e.getModifiersEx());
+//                }
+//                if (manipCamera == lightCamera)
+//                {
+//                    switch (e.getKeyCode())
+//                    {
+//                        case DOWN_ARROW:
+//                            lightCamera.DECAL /= 2;
+//                            repaint();
+//                            break;
+//                        case UP_ARROW:
+//                            lightCamera.DECAL *= 2;
+//                            repaint();
+//                            break;
+//                        case LEFT_ARROW:
+//                            lightCamera.SCALE /= 2;
+//                            repaint();
+//                            break;
+//                        case RIGHT_ARROW:
+//                            lightCamera.SCALE *= 2;
+//                            repaint();
+//                            break;
+//                        default:
+//                            break;
+//                    }
+//                    
+//                    System.out.println("DECAL = " + lightCamera.DECAL + "; SCALE = " + lightCamera.SCALE);
+//                } else
+//                {
+//                    if (true) // !autorepeat)
+//                    {
+//                        boolean reset = true;
+//
+//                        switch (e.getKeyCode())
+//                        {
+//                            case DOWN_ARROW:
+//                                GoDown(e.getModifiersEx());
+//                                repaint();
+//                                break;
+//                            case UP_ARROW:
+//                                GoUp(e.getModifiersEx());
+//                                repaint();
+//                                break;
+//                            case LEFT_ARROW:
+//                                GoLeft(e.getModifiersEx());
+//                                repaint();
+//                                break;
+//                            case RIGHT_ARROW:
+//                                GoRight(e.getModifiersEx());
+//                                repaint();
+//                                break;
+//                            default:
+//                                reset = false;
+//                                break;
+//                        }
+//
+//                        if (reset)
+//                        {
+//                            autorepeat = true;
+//
+//                            targetLookAt.set(manipCamera.lookAt);
+//                        }
+//                    }
+//                }
+//                break;
+//            case KeyEvent.KEY_TYPED:
+//                break;
             case KeyEvent.KEY_RELEASED:
-            {
-                switch (e.getKeyCode())
-                {
-                    case DOWN_ARROW:
-                    case UP_ARROW:
-                    case LEFT_ARROW:
-                    case RIGHT_ARROW:
-                        MODIFIERS &= ~COMMAND;
-                        autorepeat = false;
-                        break;
-                    default:
-                        break;
-                }
+                keys[e.getKeyCode()] = false;
+                modifiers = e.getModifiersEx();
                 keyReleased(e.getKeyChar(), e.getModifiersEx());
+                repaint();
                 break;
-            }
+//            {
+//                switch (e.getKeyCode())
+//                {
+//                    case DOWN_ARROW:
+//                    case UP_ARROW:
+//                    case LEFT_ARROW:
+//                    case RIGHT_ARROW:
+//                        MODIFIERS &= ~COMMAND;
+//                        autorepeat = false;
+//                        break;
+//                    default:
+//                        break;
+//                }
+//                keyReleased(e.getKeyChar(), e.getModifiersEx());
+//                break;
+//            }
             default:
                 break;
         }
@@ -16388,7 +16777,8 @@
 
     public boolean mouseDrag(Event evt, int x, int y)
     {
-        //System.out.println("mouseDrag: " + evt);
+        System.out.println("mouseDrag: " + evt);
+        System.exit(0);
 		/*
         drag = true;
         //System.out.println("Mouse DRAG");
@@ -16507,6 +16897,7 @@
     public boolean mouseUp(Event evt, int x, int y)
     {
         System.out.println("mouseUp: " + evt);
+        System.exit(0);
         /*
         locked = false;
         if (isRenderer)
@@ -16777,7 +17168,7 @@
             return;
         }
 
-        if (WIREFRAME)
+        //if (WIREFRAME)
             gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL);
         
         gl.glDisable(gl.GL_CULL_FACE);
@@ -16877,6 +17268,8 @@
 
         if (WIREFRAME)
             gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE);
+        else
+            gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL);
     }
 
     private void DrawChecker(GL gl)
@@ -16925,7 +17318,7 @@
             gl.glScalef(1.0f, -1.0f, 1.0f);
         }
 
-        gl.glNormal3f(0.0f, 0.0f, 1.0f);
+        SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
             
         float step = 2; // 0.1666f; //0.25f;
         float stepv = 2; // step * 1652 / 998;
@@ -17214,7 +17607,7 @@
 
             float depth = depths[y * TEX_SIZE + x];
 
-            if (pointselection && mouseMode == SELECT && depth != 0 && depth != 1)
+            if (pointselection && (mouseMode & SELECT) == SELECT && depth != 0 && depth != 1)
             {
                 pointselection = false;
                 
@@ -17878,6 +18271,11 @@
     static boolean DEBUG_SELECTION = false;
     boolean OCCLUSION_CULLING = false; //true;
     public boolean lightMode = false;
+    
+    private boolean keepshadow;
+    
+    static public boolean capsLocked = false; // VR
+    
     static public int indexcount = 0;
     /*static*/ cColor vertexOcclusion = new cColor();
     //private int selection_view = -1;

--
Gitblit v1.6.2