commit 91eb2d457be961d4f76fcdef93059c8061d25d3b
Author: leszek <leszek@koltunski.pl>
Date:   Tue Feb 11 23:44:57 2025 +0100

    progress with GhostCube

diff --git a/src/main/java/org/distorted/objectlib/helpers/FactoryShape.java b/src/main/java/org/distorted/objectlib/helpers/FactoryShape.java
index 694b3d06..43e6bfd3 100644
--- a/src/main/java/org/distorted/objectlib/helpers/FactoryShape.java
+++ b/src/main/java/org/distorted/objectlib/helpers/FactoryShape.java
@@ -184,7 +184,7 @@ public class FactoryShape
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private static float[] crossProduct(float a1, float a2, float a3, float b1, float b2, float b3)
+  public static float[] crossProduct(float a1, float a2, float a3, float b1, float b2, float b3)
     {
     float[] ret = new float[3];
 
diff --git a/src/main/java/org/distorted/objectlib/objects/TwistyGhostCube.java b/src/main/java/org/distorted/objectlib/objects/TwistyGhostCube.java
index 7e388f2d..e5ce22f6 100644
--- a/src/main/java/org/distorted/objectlib/objects/TwistyGhostCube.java
+++ b/src/main/java/org/distorted/objectlib/objects/TwistyGhostCube.java
@@ -43,9 +43,11 @@ public class TwistyGhostCube extends ShapeHexahedron
            new Static3D(0,0,1)
          };
 
-  private static final int[]    FACE_COLORS = new int[] { ShapeColors.COLOR_DYELLO };
-  private static final float[]  GHOST_VEC   = {0,0,0};//{ 0.10f, 0.25f, 0.40f };
-  private static final Static4D GHOST_QUAT  = new Static4D(0,0,0,1);
+  private static final int[]   FACE_COLORS = new int[] { ShapeColors.COLOR_DYELLO };
+  private static final float[] GHOST_VEC   = { 0.10f, 0.25f, 0.40f };
+  private static final float[] PLANES_ROT_AXIS = { 1,0,0 };
+  private static final int     PLANES_ROT_ANGLE= 20;
+
 
   private int[][] mEdges;
   private float[][] mCuts;
@@ -58,6 +60,7 @@ public class TwistyGhostCube extends ShapeHexahedron
   private float[][] mCutPlanes;
   private float[][] mPotentialVertices;
   private Static3D[] mFaceAxis, mRotAxis;
+  private Static4D mPlanesRotQuat;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -111,12 +114,30 @@ public class TwistyGhostCube extends ShapeHexahedron
     return new int[] { (1+numL[0])/2, (1+numL[1])/2, (1+numL[2])/2 };
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void makePlanesRotQuat()
+    {
+    if( mPlanesRotQuat==null )
+      {
+      double rotAngle = PLANES_ROT_ANGLE*Math.PI/180;
+      float cosA = (float)Math.cos(rotAngle/2);
+      float sinA = (float)Math.sin(rotAngle/2);
+      float x = PLANES_ROT_AXIS[0];
+      float y = PLANES_ROT_AXIS[1];
+      float z = PLANES_ROT_AXIS[2];
+
+      mPlanesRotQuat = new Static4D(x*sinA, y*sinA, z*sinA, cosA);
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   public float[][] getCubitPositions()
     {
     if( mPositions==null )
       {
+      makePlanesRotQuat();
       int[] numLayers = getNumLayers();
       int numL = numLayers[0];
       int numCubits = getNumCubitVariants();
@@ -130,7 +151,7 @@ public class TwistyGhostCube extends ShapeHexahedron
           for( int z=0; z<numL; z++)
             if( x==0 || x==numL-1 || y==0 || y==numL-1 || z==0 || z==numL-1 )
               {
-              QuatHelper.rotateVectorByQuat(tmp, x-diff, y-diff, z-diff, 1, GHOST_QUAT);
+              QuatHelper.rotateVectorByQuat(tmp, x-diff, y-diff, z-diff, 1, mPlanesRotQuat);
               mPositions[currPos++] = new float[] {tmp[0],tmp[1],tmp[2]};
               }
       }
@@ -333,19 +354,15 @@ public class TwistyGhostCube extends ShapeHexahedron
     float[] v1 = verts[wall[1]];
     float[] v2 = verts[wall[2]];
 
-    float ax = v0[0]-v1[0];
-    float ay = v0[1]-v1[1];
-    float az = v0[2]-v1[2];
-
-    float bx = v1[0]-v2[0];
-    float by = v1[1]-v2[1];
-    float bz = v1[2]-v2[2];
+    float ax = v1[0]-v2[0];
+    float ay = v1[1]-v2[1];
+    float az = v1[2]-v2[2];
 
-    float vx = ay*bz - az*by;
-    float vy = az*bx - ax*bz;
-    float vz = ax*by - ay*bx;
+    float bx = v0[0]-v1[0];
+    float by = v0[1]-v1[1];
+    float bz = v0[2]-v1[2];
 
-    return new float[] {vx,vy,vz};
+    return FactoryShape.crossProduct(ax,ay,az,bx,by,bz);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -398,7 +415,7 @@ public class TwistyGhostCube extends ShapeHexahedron
     float[][] centers  = computeVertexEffectCenter(variant);
     float[][] pos      = getCubitPositions();
     int[] cornerIndices= FactoryShape.computeVertexEffectsIndices(vertices, pos[variant], getFaceAxis(), getDist() );
-    float[][] corners  = { {0.05f,015f} };
+    float[][] corners  = { {0.015f,0.12f} };
     int[] centerIndices= new int[centers.length];
     for(int c=0; c<centers.length; c++) centerIndices[c] = c;
 
@@ -426,6 +443,7 @@ public class TwistyGhostCube extends ShapeHexahedron
     {
     if( mFaceAxis==null )
       {
+      makePlanesRotQuat();
       Static3D[] axis = TouchControlHexahedron.FACE_AXIS;
       int len = axis.length;
       mFaceAxis = new Static3D[len];
@@ -434,7 +452,7 @@ public class TwistyGhostCube extends ShapeHexahedron
       for(int a=0; a<len; a++)
         {
         Static3D ax = axis[a];
-        QuatHelper.rotateVectorByInvertedQuat( tmp, ax.get0(), ax.get1(), ax.get2(), 0, GHOST_QUAT);
+        QuatHelper.rotateVectorByInvertedQuat( tmp, ax.get0(), ax.get1(), ax.get2(), 0, mPlanesRotQuat);
         mFaceAxis[a] = new Static3D(tmp[0],tmp[1],tmp[2]);
         }
       }
@@ -478,6 +496,7 @@ public class TwistyGhostCube extends ShapeHexahedron
     {
     if( mRotAxis==null )
       {
+      makePlanesRotQuat();
       Static3D[] axis = ROT_AXIS;
       int len = axis.length;
       mRotAxis = new Static3D[len];
@@ -486,7 +505,7 @@ public class TwistyGhostCube extends ShapeHexahedron
       for(int a=0; a<len; a++)
         {
         Static3D ax = axis[a];
-        QuatHelper.rotateVectorByQuat( tmp, ax.get0(), ax.get1(), ax.get2(), 0, GHOST_QUAT);
+        QuatHelper.rotateVectorByQuat( tmp, ax.get0(), ax.get1(), ax.get2(), 0, mPlanesRotQuat);
         mRotAxis[a] = new Static3D(tmp[0],tmp[1],tmp[2]);
         }
       }
