commit 52375039f54ee08779943a44c0b9ecc3edbb6659
Author: leszek <leszek@koltunski.pl>
Date:   Fri Mar 29 23:59:34 2024 +0100

    improvement

diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
index 1f9cb847..207fee69 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
@@ -9,6 +9,7 @@
 
 package org.distorted.objectlib.touchcontrol;
 
+import org.distorted.library.helpers.QuatHelper;
 import org.distorted.library.type.Static4D;
 import org.distorted.objectlib.main.TwistyObject;
 
@@ -204,6 +205,30 @@ public abstract class TouchControl
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// cast the 3D axis we are currently rotating along (which is already casted to the surface of the
+// currently touched face AND converted into a 4D vector - fourth 0) to a 2D in-screen-surface axis
+
+  void getCastedRotAxis(float[] output, Static4D quat, float x, float y, float z, float w)
+    {
+    Static4D result = QuatHelper.rotateVectorByQuat(x,y,z,w, quat);
+
+    float cx = result.get0();
+    float cy = result.get1();
+    float len= (float)Math.sqrt(cx*cx+cy*cy);
+
+    if( len!=0 )
+      {
+      output[0] = cx/len;
+      output[1] = cy/len;
+      }
+    else
+      {
+      output[0] = 1;
+      output[1] = 0;
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public abstract boolean objectTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera);
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBall.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBall.java
index 5bf81cb7..16e50cdd 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBall.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlBall.java
@@ -336,22 +336,7 @@ public class TouchControlBall extends TouchControl
   public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
     {
     Static3D a = mRotAxis[axisIndex];
-    Static4D result = QuatHelper.rotateVectorByQuat(a.get0(),a.get1(),a.get2(),0,quat);
-
-    float cx = result.get0();
-    float cy = result.get1();
-    float len= (float)Math.sqrt(cx*cx+cy*cy);
-
-    if( len!=0 )
-      {
-      output[0] = cx/len;
-      output[1] = cy/len;
-      }
-    else
-      {
-      output[0] = 1;
-      output[1] = 0;
-      }
+    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),0);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
index cf776a73..97492a3e 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
@@ -97,7 +97,6 @@ public class TouchControlShapeChanging extends TouchControl
   // end FaceInfo
 
   private final float[] mTouch, mLastT;
-  private final Static4D mTmpAxis;
   private int mNumCubits;
   private int[] mNumFaces;
   private boolean mPreparationDone;
@@ -123,7 +122,6 @@ public class TouchControlShapeChanging extends TouchControl
     mLastT = new float[3];
     mObject= object;
     mPreparationDone = false;
-    mTmpAxis = new Static4D(0,0,0,0);
     mGhostAxisEnabled = -1;
 
     if( object!=null )
@@ -717,29 +715,8 @@ public class TouchControlShapeChanging extends TouchControl
 
   public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
     {
-    Static3D rotAxis = mRotAxis[axisIndex];
-    float rx = rotAxis.get0();
-    float ry = rotAxis.get1();
-    float rz = rotAxis.get2();
-
-    mTmpAxis.set(rx,ry,rz,0);
-    Static4D result = QuatHelper.rotateVectorByQuat(mTmpAxis, quat);
-
-    float cx =result.get0();
-    float cy =result.get1();
-
-    float len = (float)Math.sqrt(cx*cx+cy*cy);
-
-    if( len!=0 )
-      {
-      output[0] = cx/len;
-      output[1] = cy/len;
-      }
-    else
-      {
-      output[0] = 1;
-      output[1] = 0;
-      }
+    Static3D a = mRotAxis[axisIndex];
+    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),0);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java
index 97bdfb98..f168f4af 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeConstant.java
@@ -350,19 +350,8 @@ public abstract class TouchControlShapeConstant extends TouchControl
 
   public void getCastedRotAxis(float[] output, Static4D quat, int axisIndex)
     {
-    Static4D axis = mCastedRotAxis4D[mLastTouchedFace][axisIndex];
-    Static4D result = QuatHelper.rotateVectorByQuat(axis, quat);
-
-    output[0] =result.get0();
-    output[1] =result.get1();
-
-    float len = (float)Math.sqrt(output[0]*output[0] + output[1]*output[1]);
-
-    if( len!=0 )
-      {
-      output[0] /= len;
-      output[1] /= len;
-      }
+    Static4D a = mCastedRotAxis4D[mLastTouchedFace][axisIndex];
+    getCastedRotAxis(output,quat,a.get0(),a.get1(),a.get2(),a.get3());
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
