commit 75173f8139d0704717c1a75af1680b39052b484e
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu Mar 24 23:54:35 2022 +0100

    Further progress with Bandaged 3x3: correct rotation of the collection of BandagedCubits.

diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java b/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
index 77f85342..6047a8e3 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
@@ -35,12 +35,6 @@ import org.distorted.library.type.Static4D;
 
 public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
 {
-   private final BandagedCreatorView mView;
-   private final DistortedScreen mScreen;
-   private final Static3D mScale;
-   private final BandagedCubit[] mCubits;
-   private float mScaleValue;
-
    static final int COLOR_DEFAULT = 0xffffff55;
    static final int COLOR_MARKED  = 0xffff0000;
 
@@ -77,8 +71,15 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
           { 0.0f, -1.0f, -1.0f },
         };
 
-   Static4D mQuat1, mQuat2;
-   int mScreenMin;
+   private final BandagedCreatorView mView;
+   private final DistortedScreen mScreen;
+   private final Static3D mScale;
+   private final BandagedCubit[] mCubits;
+   private final Static4D mQuat1, mQuat2;
+   private float mScaleValue;
+
+   private float mX, mY, mZ, mW;
+   private boolean mResetQuats, mSetQuat1;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -91,6 +92,9 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
 
      mView = v;
 
+     mResetQuats = false;
+     mSetQuat1   = false;
+
      mScreen = new DistortedScreen();
      mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
      mScale = new Static3D(1,1,1);
@@ -119,6 +123,35 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
      {
      long time = System.currentTimeMillis();
      mScreen.render(time);
+
+     if( mSetQuat1 )
+       {
+       mSetQuat1 = false;
+       mQuat1.set(mX,mY,mZ,mW);
+       }
+
+     if( mResetQuats )
+       {
+       mResetQuats = false;
+
+       float qx = mQuat1.get0();
+       float qy = mQuat1.get1();
+       float qz = mQuat1.get2();
+       float qw = mQuat1.get3();
+
+       float rx = mQuat2.get0();
+       float ry = mQuat2.get1();
+       float rz = mQuat2.get2();
+       float rw = mQuat2.get3();
+
+       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
+       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
+       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
+       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
+
+       mQuat1.set(0f, 0f, 0f, 1f);
+       mQuat2.set(tx, ty, tz, tw);
+       }
      }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -142,7 +175,6 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
           }
 
       mScale.set( mScaleValue,mScaleValue,mScaleValue );
-      mScreenMin = Math.min(width, height);
       mView.setScreenSize(width,height);
       mScreen.resize(width,height);
       }
@@ -213,4 +245,30 @@ public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, Distorte
          }
        }
      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public Static4D getQuat2()
+      {
+      return mQuat2;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void setQuat1(float x, float y, float z, float w)
+      {
+      mX = x;
+      mY = y;
+      mZ = z;
+      mW = w;
+
+      mSetQuat1 = true;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void resetQuats()
+      {
+      mResetQuats = true;
+      }
 }
diff --git a/src/main/java/org/distorted/bandaged/BandagedCreatorView.java b/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
index 8a90ff7f..0cf2caa5 100644
--- a/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
+++ b/src/main/java/org/distorted/bandaged/BandagedCreatorView.java
@@ -36,11 +36,12 @@ import org.distorted.library.main.DistortedScreen;
 public class BandagedCreatorView extends GLSurfaceView
 {
     private final static int DIRECTION_SENSITIVITY=  12;
-    private int mX, mY;
-    private int mTouchedIndex1, mTouchedIndex2;
+
     private BandagedCreatorRenderer mRenderer;
     private BandagedTouchControl mTouchControl;
-    private int mScreenWidth, mScreenHeight;
+    private int mScreenWidth, mScreenHeight, mScreenMin;
+    private int mTouchedIndex1, mTouchedIndex2;
+    private int mX, mY;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
@@ -92,35 +93,13 @@ public class BandagedCreatorView extends GLSurfaceView
         }
       }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    private void resetQuats()
-      {
-      float qx = mRenderer.mQuat1.get0();
-      float qy = mRenderer.mQuat1.get1();
-      float qz = mRenderer.mQuat1.get2();
-      float qw = mRenderer.mQuat1.get3();
-
-      float rx = mRenderer.mQuat2.get0();
-      float ry = mRenderer.mQuat2.get1();
-      float rz = mRenderer.mQuat2.get2();
-      float rw = mRenderer.mQuat2.get3();
-
-      float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-      float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-      float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-      float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-      mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
-      mRenderer.mQuat2.set(tx, ty, tz, tw);
-      }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     public void setScreenSize(int width, int height)
       {
       mScreenWidth = width;
       mScreenHeight= height;
+      mScreenMin   = Math.min(width, height);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -134,10 +113,10 @@ public class BandagedCreatorView extends GLSurfaceView
 
       switch(action)
          {
-         case MotionEvent.ACTION_DOWN: float x1 = (x -  mScreenWidth*0.5f)/mRenderer.mScreenMin;
-                                       float y1 = (mScreenHeight*0.5f - y)/mRenderer.mScreenMin;
+         case MotionEvent.ACTION_DOWN: float x1 = (x -  mScreenWidth*0.5f)/mScreenMin;
+                                       float y1 = (mScreenHeight*0.5f - y)/mScreenMin;
 
-                                       int index = mTouchControl.cubitTouched(x1,y1,mRenderer.mQuat2);
+                                       int index = mTouchControl.cubitTouched(x1,y1,mRenderer.getQuat2() );
 
                                        if( index<0 )
                                          {
@@ -180,17 +159,17 @@ public class BandagedCreatorView extends GLSurfaceView
                                            py /= plen;
                                            pz /= plen;
 
-                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
+                                           float cosA = (float)Math.cos(plen*3.14f/mScreenMin);
                                            float sinA = (float)Math.sqrt(1-cosA*cosA);
 
-                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
+                                           mRenderer.setQuat1(px*sinA, py*sinA, pz*sinA, cosA);
                                            }
                                          }
-                                       if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mRenderer.mScreenMin*mRenderer.mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
+                                       if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > mScreenMin*mScreenMin/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
                                          {
                                          mX = x;
                                          mY = y;
-                                         resetQuats();
+                                         mRenderer.resetQuats();
                                          }
                                        break;
 
@@ -208,7 +187,7 @@ public class BandagedCreatorView extends GLSurfaceView
                                        mX = -1;
                                        mY = -1;
 
-        	                             resetQuats();
+        	                             mRenderer.resetQuats();
                                        break;
          }
 
