From 15123b19e7bc8da2869429b07f0fbaa0598e945e Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 20 Jun 2019 20:56:08 -0400
Subject: [PATCH] Rewind all.

---
 ObjEditor.java     |   16 +++-
 CameraPane.java    |   12 +++
 GroupEditor.java   |   40 +++++++++++++
 matrix/Matrix.java |    4 
 Object3D.java      |   54 ++++++++++++++++-
 5 files changed, 112 insertions(+), 14 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index 99e2648..aef9761 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -464,10 +464,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);
@@ -1192,10 +1194,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]);
 
@@ -1215,10 +1219,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]);
 
@@ -1246,8 +1252,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;
                             }
diff --git a/GroupEditor.java b/GroupEditor.java
index 4f34e39..bae9769 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -470,6 +470,14 @@
 		markleavesItem.addActionListener(this);
 		unmarkleavesItem = menu.add(new MenuItem("Unmark Leaves"));
 		unmarkleavesItem.addActionListener(this);
+		rewindleavesItem = menu.add(new MenuItem("Rewind Leaves"));
+		rewindleavesItem.addActionListener(this);
+		unrewindleavesItem = menu.add(new MenuItem("Unrewind Leaves"));
+		unrewindleavesItem.addActionListener(this);
+		randomleavesItem = menu.add(new MenuItem("Random Leaves"));
+		randomleavesItem.addActionListener(this);
+		unrandomleavesItem = menu.add(new MenuItem("Unrandom Leaves"));
+		unrandomleavesItem.addActionListener(this);
 		menu.add("-");
 		flipVItem = menu.add(new MenuItem("Flip V"));
 		flipVItem.addActionListener(this);
@@ -2609,6 +2617,22 @@
                 {
 			MarkLeaves(false);
 		} else
+		if (source == rewindleavesItem)
+                {
+			RewindLeaves(true);
+		} else
+		if (source == unrewindleavesItem)
+                {
+			RewindLeaves(false);
+		} else
+		if (source == randomleavesItem)
+                {
+			RandomLeaves(true);
+		} else
+		if (source == unrandomleavesItem)
+                {
+			RandomLeaves(false);
+		} else
 		if (source == flipVItem)
                 {
 			FlipV(true);
@@ -4146,6 +4170,18 @@
 		refreshContents();
 	}
 	
+	void RewindLeaves(boolean hide)
+	{
+		group.selection.RewindLeaves(hide);
+		refreshContents();
+	}
+	
+	void RandomLeaves(boolean hide)
+	{
+		group.selection.RandomLeaves(hide);
+		refreshContents();
+	}
+	
 	void SetTexRes(int tr)
 	{
 		group.selection.SetTexRes(tr);
@@ -5283,6 +5319,10 @@
 	private MenuItem showleavesItem;
 	private MenuItem markleavesItem;
 	private MenuItem unmarkleavesItem;
+	private MenuItem rewindleavesItem;
+	private MenuItem unrewindleavesItem;
+	private MenuItem randomleavesItem;
+	private MenuItem unrandomleavesItem;
         
 	private MenuItem flipVItem;
 	private MenuItem unflipVItem;
diff --git a/ObjEditor.java b/ObjEditor.java
index 9cf4839..877fe87 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -168,6 +168,7 @@
 //        objEditor.ctrlPanel.remove(remarkButton);
         
         objEditor.ctrlPanel.remove(setupPanel);
+        objEditor.ctrlPanel.remove(setupPanel2);
         objEditor.ctrlPanel.remove(commandsPanel);
         objEditor.ctrlPanel.remove(pushPanel);
         //objEditor.ctrlPanel.remove(fillPanel);
@@ -747,6 +748,7 @@
     
     cGridBag namePanel;
     cGridBag setupPanel;
+    cGridBag setupPanel2;
     cGridBag commandsPanel;
     cGridBag pushPanel;
     cGridBag fillPanel;
@@ -939,22 +941,26 @@
         markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
         markCB.setToolTipText("Set the animation target transform");
         
-        rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
+            setupPanel2 = new cGridBag().setVertical(false);
+            
+        rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
         rewindCB.setToolTipText("Rewind animation");
         
-        randomCB = AddCheckBox(setupPanel, "Random", copy.random);
-        randomCB.setToolTipText("Option for switch node");
+        randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
+        randomCB.setToolTipText("Rewind or Go back and forth randomly");
 
         if (Globals.ADVANCED)
         {
-                link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
+                link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
                 link2masterCB.setToolTipText("Attach to support");
-                speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
+                speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
                 speedupCB.setToolTipText("Option motion capture");
         }
         
         oe.ctrlPanel.add(setupPanel);
         oe.ctrlPanel.Return();
+        oe.ctrlPanel.add(setupPanel2);
+        oe.ctrlPanel.Return();
         
             commandsPanel = new cGridBag().setVertical(false);
         
diff --git a/Object3D.java b/Object3D.java
index d6e0e59..7b52765 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -893,7 +893,8 @@
             
             boolean changedir = random && Math.random() < 0.01; // && !link2master;
 
-            if (transformcount*factor > maxcount || (step == 1 && changedir))
+            if (transformcount*factor >= maxcount && (rewind || random) ||
+                    (step == 1 && changedir))
             {
                 countdown = 1;
                 delay = speedup?8:1;
@@ -3503,7 +3504,8 @@
         if (blockloop)
             return;
         
-        if (marked || (bRep != null && material != null)) // borderline...
+        if (//marked || // does not make sense
+                (bRep != null || material != null)) // borderline...
             live = h;
         
         for (int i = 0; i < Size(); i++)
@@ -3524,7 +3526,8 @@
             return;
         
         //if (bRep != null)
-        if (marked || (bRep != null && material != null)) // borderline...
+        if (//marked || // does not make sense
+                (bRep != null || material != null)) // borderline...
             link2master = h;
         
         for (int i = 0; i < Size(); i++)
@@ -3544,7 +3547,8 @@
         if (blockloop)
             return;
         
-        if (marked || (bRep != null && material != null)) // borderline...
+        if (//marked || // does not make sense
+                (bRep != null || material != null)) // borderline...
             hide = h;
         
         for (int i = 0; i < Size(); i++)
@@ -3564,7 +3568,7 @@
         if (blockloop)
             return;
         
-        if (bRep != null && material != null) // borderline...
+        if (bRep != null || material != null) // borderline...
             marked = h;
         
         for (int i = 0; i < Size(); i++)
@@ -3579,6 +3583,46 @@
         }
     }
     
+    void RewindLeaves(boolean h)
+    {
+        if (blockloop)
+            return;
+        
+        if (bRep != null || material != null) // borderline...
+            rewind = h;
+        
+        for (int i = 0; i < Size(); i++)
+        {
+            Object3D child = (Object3D) get(i); // reserve(i);
+            if (child == null)
+                continue;
+            blockloop = true;
+            child.RewindLeaves(h);
+            blockloop = false;
+         //   release(i);
+        }
+    }
+    
+    void RandomLeaves(boolean h)
+    {
+        if (blockloop)
+            return;
+        
+        if (bRep != null || material != null) // borderline...
+            random = h;
+        
+        for (int i = 0; i < Size(); i++)
+        {
+            Object3D child = (Object3D) get(i); // reserve(i);
+            if (child == null)
+                continue;
+            blockloop = true;
+            child.RandomLeaves(h);
+            blockloop = false;
+         //   release(i);
+        }
+    }
+    
     void SetTexRes(int tr)
     {
         texres = tr;
diff --git a/matrix/Matrix.java b/matrix/Matrix.java
index 2349c20..bf40583 100644
--- a/matrix/Matrix.java
+++ b/matrix/Matrix.java
@@ -678,14 +678,14 @@
         {
             for (int j = 0; j < nr; j++)
             {
-                boolean zero = Math.abs(A[i][j]) < 1E-8;
+                boolean zero = Math.abs(A[i][j]) < 1E-12;
 
                 if (!zero)
                 {
                     if (i != j)
                         return false;
                     
-                    boolean un = Math.abs(A[i][j] - 1) < 1E-8;
+                    boolean un = Math.abs(A[i][j] - 1) < 1E-12;
                     
                     if (!un)
                         return false;

--
Gitblit v1.6.2