From f2b6a33fdf84a06b958f9cb9d667a2eff3063d8b Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Wed, 24 Jul 2019 23:50:40 -0400
Subject: [PATCH] Camera global inverse.

---
 CameraPane.java |   96 ++++++++++++++++++++++++++---------------------
 1 files changed, 53 insertions(+), 43 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index 69d4882..07290d0 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -9699,7 +9699,7 @@
         
         if (renderCamera != lightCamera)
         //for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
+            LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
         
 //            LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
             
@@ -9715,7 +9715,7 @@
             
         if (renderCamera != lightCamera)
         //for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
+            LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
 
 //            LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
             
@@ -10916,7 +10916,7 @@
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
             //for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
+                LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
             
             for (int j = 0; j < 4; j++)
             {
@@ -10931,7 +10931,7 @@
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
             //for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
+                LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
         
             //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
             
@@ -14255,14 +14255,15 @@
             drag = false;
             //System.out.println("Mouse DOWN");
             editObj = false;
-            ClickInfo info = new ClickInfo();
-            info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
-            info.pane = this;
-            info.camera = renderCamera;
-            info.x = x;
-            info.y = y;
-            info.modifiers = modifiersex;
-            editObj = object.doEditClick(info, 0);
+            //ClickInfo info = new ClickInfo();
+            object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
+            object.clickInfo.pane = this;
+            object.clickInfo.camera = renderCamera;
+            object.clickInfo.x = x;
+            object.clickInfo.y = y;
+            object.clickInfo.modifiers = modifiersex;
+            editObj = object.doEditClick(//info,
+                    0);
             if (!editObj)
             {
                 hasMarquee = true;
@@ -14662,15 +14663,16 @@
             if (editObj)
             {
                 drag = true;
-                ClickInfo info = new ClickInfo();
-                info.bounds.setBounds(0, 0,
+                //ClickInfo info = new ClickInfo();
+                object.clickInfo.bounds.setBounds(0, 0,
                         (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
-                info.pane = this;
-                info.camera = renderCamera;
-                info.x = x;
-                info.y = y;
-                object.GetWindow().copy
-                        .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
+                object.clickInfo.pane = this;
+                object.clickInfo.camera = renderCamera;
+                object.clickInfo.x = x;
+                object.clickInfo.y = y;
+                object //.GetWindow().copy
+                        .doEditDrag(//info,
+                                (modifiers & MouseEvent.BUTTON3_MASK) != 0);
             } else
             {
                 if (x < startX)
@@ -14819,24 +14821,27 @@
         }
     }
 
+//        ClickInfo clickInfo = new ClickInfo();
+        
     public void mouseMoved(MouseEvent e)
     {
         //System.out.println("mouseMoved: " + e);
         if (isRenderer)
             return;
         
-        ClickInfo ci = new ClickInfo();
-        ci.x = e.getX();
-        ci.y = e.getY();
-        ci.modifiers = e.getModifiersEx();
-        ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
-        ci.pane = this;
-        ci.camera = renderCamera;
+        // Mouse cursor feedback
+        object.clickInfo.x = e.getX();
+        object.clickInfo.y = e.getY();
+        object.clickInfo.modifiers = e.getModifiersEx();
+        object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
+        object.clickInfo.pane = this;
+        object.clickInfo.camera = renderCamera;
         if (!isRenderer)
         {
             //ObjEditor editWindow = object.editWindow;
             //Object3D copy = editWindow.copy;
-            if (object.doEditClick(ci, 0))
+            if (object.doEditClick(//clickInfo,
+                                0))
             {
                 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
             } else
@@ -15862,8 +15867,6 @@
 
         int width = getBounds().width;
         int height = getBounds().height;
-        ClickInfo info = new ClickInfo();
-        info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
         //Image img = CreateImage(width, height);
         //System.out.println("width = " + width + "; height = " + height + "\n");
         
@@ -15940,31 +15943,37 @@
         }
         if (object != null && !hasMarquee)
         {
+            if (object.clickInfo == null)
+                object.clickInfo = new ClickInfo();
+            ClickInfo info = object.clickInfo;
+            //ClickInfo info = new ClickInfo();
+            info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
+        
             if (isRenderer)
             {
-                info.flags++;
+                object.clickInfo.flags++;
                 double frameAspect = (double) width / (double) height;
                 if (frameAspect > renderCamera.aspect)
                 {
                     int desired = (int) ((double) height * renderCamera.aspect);
-                    info.bounds.width -= width - desired;
-                    info.bounds.x += (width - desired) / 2;
+                    object.clickInfo.bounds.width -= width - desired;
+                    object.clickInfo.bounds.x += (width - desired) / 2;
                 } else
                 {
                     int desired = (int) ((double) width / renderCamera.aspect);
-                    info.bounds.height -= height - desired;
-                    info.bounds.y += (height - desired) / 2;
+                    object.clickInfo.bounds.height -= height - desired;
+                    object.clickInfo.bounds.y += (height - desired) / 2;
                 }
             }
             
-            info.g = gr;
-            info.camera = renderCamera;
+            object.clickInfo.g = gr;
+            object.clickInfo.camera = renderCamera;
             /* 
             // Memory intensive (brep.verticescopy)
             if (!(object instanceof Composite))
             object.draw(info, 0, false); // SLOW : 
              */
-            if (!isRenderer)
+            if (!isRenderer) // && drag)
             {
                 Grafreed.Assert(object != null);
                 Grafreed.Assert(object.selection != null);
@@ -15972,9 +15981,9 @@
                 {
                     int hitSomething = object.selection.get(0).hitSomething;
 
-                    info.DX = 0;
-                    info.DY = 0;
-                    info.W = 1;
+                    object.clickInfo.DX = 0;
+                    object.clickInfo.DY = 0;
+                    object.clickInfo.W = 1;
                     if (hitSomething == Object3D.hitCenter)
                     {
                         info.DX = X;
@@ -15986,7 +15995,8 @@
                             info.DY -= info.bounds.height/2;
                     }
 
-                    object.drawEditHandles(info, 0);
+                    object.drawEditHandles(//info,
+                                            0);
 
                     if (drag && (X != 0 || Y != 0))
                     {
@@ -15999,7 +16009,7 @@
                                 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
                             break;
                             case Object3D.hitScale: gr.setColor(Color.cyan);
-                                gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
+                                gr.drawLine(X, Y, 0, 0);
                             break;
                         }
 

--
Gitblit v1.6.2