commit 8da6b1c9c4a7c96c23fac5747080b13e92cadf35
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Oct 11 14:34:10 2021 +0200

    Changes to the Cube cubits; new cube meshes.

diff --git a/src/main/java/org/distorted/objectlib/main/Movement.java b/src/main/java/org/distorted/objectlib/main/Movement.java
index 5c4731f3..b06340ce 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement.java
@@ -105,7 +105,7 @@ public abstract class Movement
 
       for( int face=0; face<mNumFaceAxis; face++)
         {
-        convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]);
+        convertTo2Dcoords( mPoint, face, mCastedRotAxis[face][casted]);
         normalize2D(mCastedRotAxis[face][casted]);
 
         fx = mFaceAxis[face].get0();
@@ -176,8 +176,9 @@ public abstract class Movement
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private boolean faceIsVisible(Static3D faceAxis)
+  private boolean faceIsVisible(int index)
     {
+    Static3D faceAxis = mFaceAxis[index];
     float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2();
     return castCameraOnAxis > mDistanceCenterFace3D;
     }
@@ -190,8 +191,10 @@ public abstract class Movement
 //
 // output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)]
 
-  private void castTouchPointOntoFace(Static3D faceAxis, float[] output)
+  private void castTouchPointOntoFace(int index, float[] output)
     {
+    Static3D faceAxis = mFaceAxis[index];
+
     float d0 = mPoint[0]-mCamera[0];
     float d1 = mPoint[1]-mCamera[1];
     float d2 = mPoint[2]-mCamera[2];
@@ -222,8 +225,10 @@ public abstract class Movement
 // mean that the distance between the center of the Object and its faces is 0) - then we arbitrarily
 // decide that 2D Y = (0,0,-1) in the North Pole and (0,0,1) in the South Pole)
 
-  private void convertTo2Dcoords(float[] point3D, Static3D faceAxis, float[] output)
+  private void convertTo2Dcoords(float[] point3D, int index , float[] output)
     {
+    Static3D faceAxis = mFaceAxis[index];
+
     float y0,y1,y2; // base Y vector of the 2D coord system
     float a0 = faceAxis.get0();
     float a1 = faceAxis.get1();
@@ -421,10 +426,10 @@ public abstract class Movement
 
     for( mLastTouchedFace=0; mLastTouchedFace<mNumFaceAxis; mLastTouchedFace++)
       {
-      if( faceIsVisible(mFaceAxis[mLastTouchedFace]) )
+      if( faceIsVisible(mLastTouchedFace) )
         {
-        castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch);
-        convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mPoint2D);
+        castTouchPointOntoFace(mLastTouchedFace, mTouch);
+        convertTo2Dcoords(mTouch, mLastTouchedFace, mPoint2D);
         if( isInsideFace(mLastTouchedFace,mPoint2D) ) return true;
         }
       }
@@ -440,8 +445,8 @@ public abstract class Movement
     mPoint[1] = rotatedTouchPoint.get1()/objectRatio;
     mPoint[2] = rotatedTouchPoint.get2()/objectRatio;
 
-    castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch);
-    convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mMove2D);
+    castTouchPointOntoFace(mLastTouchedFace, mTouch);
+    convertTo2Dcoords(mTouch, mLastTouchedFace, mMove2D);
 
     mMove2D[0] -= mPoint2D[0];
     mMove2D[1] -= mPoint2D[1];
diff --git a/src/main/java/org/distorted/objectlib/main/Movement12.java b/src/main/java/org/distorted/objectlib/main/Movement12.java
index 8b8e1816..98fb4363 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement12.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement12.java
@@ -33,8 +33,8 @@ public class Movement12 extends Movement
   public static final float SIN54    = (SQ5+1)/4;
   public static final float COS54    = (float)(Math.sqrt(10-2*SQ5)/4);
 
-  public static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
-  public static final float DIST2D = (SIN54/COS54)/2;
+  public  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
+  private static final float DIST2D = (SIN54/COS54)/2;
 
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
diff --git a/src/main/java/org/distorted/objectlib/main/Movement4.java b/src/main/java/org/distorted/objectlib/main/Movement4.java
index 77b616f7..c5b9e802 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement4.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement4.java
@@ -26,8 +26,8 @@ import org.distorted.library.type.Static3D;
 
 public class Movement4 extends Movement
 {
-  public static final float DIST3D = SQ6/12;
-  public static final float DIST2D = SQ3/6;
+  private static final float DIST3D = SQ6/12;
+  private static final float DIST2D = SQ3/6;
 
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
diff --git a/src/main/java/org/distorted/objectlib/main/Movement6.java b/src/main/java/org/distorted/objectlib/main/Movement6.java
index ed728783..3acfaf4f 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement6.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement6.java
@@ -26,8 +26,8 @@ import org.distorted.library.type.Static3D;
 
 public class Movement6 extends Movement
 {
-  public static final float DIST3D = 0.5f;
-  public static final float DIST2D = 0.5f;
+  private static final float DIST3D = 0.5f;
+  private static final float DIST2D = 0.5f;
 
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
diff --git a/src/main/java/org/distorted/objectlib/main/Movement8.java b/src/main/java/org/distorted/objectlib/main/Movement8.java
index 19d047c9..e868af1e 100644
--- a/src/main/java/org/distorted/objectlib/main/Movement8.java
+++ b/src/main/java/org/distorted/objectlib/main/Movement8.java
@@ -26,8 +26,8 @@ import org.distorted.library.type.Static3D;
 
 public class Movement8 extends Movement
 {
-  public static final float DIST3D = SQ6/6;
-  public static final float DIST2D = SQ3/6;
+  private static final float DIST3D = SQ6/6;
+  private static final float DIST2D = SQ3/6;
 
   public static final Static3D[] FACE_AXIS = new Static3D[]
          {
diff --git a/src/main/java/org/distorted/objectlib/objects/TwistyCube.java b/src/main/java/org/distorted/objectlib/objects/TwistyCube.java
index ee64fddc..8a157c08 100644
--- a/src/main/java/org/distorted/objectlib/objects/TwistyCube.java
+++ b/src/main/java/org/distorted/objectlib/objects/TwistyCube.java
@@ -186,6 +186,13 @@ public class TwistyCube extends Twisty6
     return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status], mQuats);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private int getNumCornersAndEdges(int numLayers)
+    {
+    return numLayers==1 ? 1 : 12*(numLayers-2) + 8;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   protected ObjectShape getObjectShape(int cubit, int numLayers)
@@ -233,11 +240,102 @@ public class TwistyCube extends Twisty6
     return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  protected float[][] getCubitPositions(int numLayers)
+    {
+    if( numLayers==1 ) return new float[][] {{ 0.0f, 0.0f, 0.0f }};
+
+    int numCubits = getNumCornersAndEdges(numLayers) + 6*(numLayers-2)*(numLayers-2);
+    float[][] tmp = new float[numCubits][];
+
+    final float LEN = 0.5f*(numLayers-1);
+    int currentPosition = 0;
+
+    tmp[currentPosition++] = new float[] {-LEN,-LEN,-LEN};
+    tmp[currentPosition++] = new float[] {-LEN,-LEN,+LEN};
+    tmp[currentPosition++] = new float[] {-LEN,+LEN,-LEN};
+    tmp[currentPosition++] = new float[] {-LEN,+LEN,+LEN};
+    tmp[currentPosition++] = new float[] {+LEN,-LEN,-LEN};
+    tmp[currentPosition++] = new float[] {+LEN,-LEN,+LEN};
+    tmp[currentPosition++] = new float[] {+LEN,+LEN,-LEN};
+    tmp[currentPosition++] = new float[] {+LEN,+LEN,+LEN};
+
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] { i-LEN,  -LEN,  -LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] { i-LEN,  -LEN,  +LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] { i-LEN,  +LEN,  -LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] { i-LEN,  +LEN,  +LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  -LEN, i-LEN,  -LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  -LEN, i-LEN,  +LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  +LEN, i-LEN,  -LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  +LEN, i-LEN,  +LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  -LEN,  -LEN, i-LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  -LEN,  +LEN, i-LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  +LEN,  -LEN, i-LEN };
+    for(int i=1; i<numLayers-1; i++)
+      tmp[currentPosition++] = new float[] {  +LEN,  +LEN, i-LEN };
+
+    for(int y=1; y<numLayers-1; y++)
+      for(int z=1; z<numLayers-1; z++)
+        tmp[currentPosition++] = new float[] {+LEN,y-LEN,z-LEN};
+
+    for(int y=1; y<numLayers-1; y++)
+      for(int z=1; z<numLayers-1; z++)
+        tmp[currentPosition++] = new float[] {-LEN,y-LEN,z-LEN};
+
+    for(int x=1; x<numLayers-1; x++)
+      for(int z=1; z<numLayers-1; z++)
+        tmp[currentPosition++] = new float[] {x-LEN,+LEN,z-LEN};
+
+    for(int x=1; x<numLayers-1; x++)
+      for(int z=1; z<numLayers-1; z++)
+        tmp[currentPosition++] = new float[] {x-LEN,-LEN,z-LEN};
+
+    for(int x=1; x<numLayers-1; x++)
+      for(int y=1; y<numLayers-1; y++)
+        tmp[currentPosition++] = new float[] {x-LEN,y-LEN,+LEN};
+
+    for(int x=1; x<numLayers-1; x++)
+      for(int y=1; y<numLayers-1; y++)
+        tmp[currentPosition++] = new float[] {x-LEN,y-LEN,-LEN};
+
+    return tmp;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   protected Static4D getQuat(int cubit, int numLayers)
     {
     if( mQuats ==null ) initializeQuats();
+
+    int num = cubit - getNumCornersAndEdges(numLayers);
+
+    if( num>=0 )
+      {
+      int face = num/((numLayers-2)*(numLayers-2));
+
+      switch(face)
+        {
+        case 0: return mQuats[13];
+        case 1: return mQuats[12];
+        case 2: return mQuats[ 8];
+        case 3: return mQuats[ 9];
+        case 4: return mQuats[ 0];
+        case 5: return mQuats[ 1];
+        }
+      }
+
     return mQuats[0];
     }
 
@@ -245,14 +343,31 @@ public class TwistyCube extends Twisty6
 
   protected int getNumCubitVariants(int numLayers)
     {
-    return 1;
+    return numLayers>2 ? 2:1;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   protected int getCubitVariant(int cubit, int numLayers)
     {
-    return 0;
+    return cubit < getNumCornersAndEdges(numLayers) ? 0 : 1;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  protected int getFaceColor(int cubit, int cubitface, int numLayers)
+    {
+    int cornersAndEdges = getNumCornersAndEdges(numLayers);
+
+    if( cubit<cornersAndEdges )
+      {
+      return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numLayers-1)):1) ? cubitface : NUM_TEXTURES;
+      }
+    else
+      {
+      int numCentersPerFace = (numLayers-2)*(numLayers-2);
+      return cubitface == 4 ? (cubit-cornersAndEdges)/numCentersPerFace : NUM_TEXTURES;
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -284,27 +399,6 @@ public class TwistyCube extends Twisty6
     return mStickers[face/NUM_FACE_COLORS];
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  protected float[][] getCubitPositions(int numLayers)
-    {
-    int numCubits = numLayers>1 ? 6*numLayers*numLayers - 12*numLayers + 8 : 1;
-    float[][] tmp = new float[numCubits][];
-
-    float diff = 0.5f*(numLayers-1);
-    int currentPosition = 0;
-
-    for(int x = 0; x<numLayers; x++)
-      for(int y = 0; y<numLayers; y++)
-        for(int z = 0; z<numLayers; z++)
-          if( x==0 || x==numLayers-1 || y==0 || y==numLayers-1 || z==0 || z==numLayers-1 )
-            {
-            tmp[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
-            }
-
-    return tmp;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   protected Static4D[] getQuats()
@@ -370,13 +464,6 @@ public class TwistyCube extends Twisty6
     return 6;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  protected int getFaceColor(int cubit, int cubitface, int numLayers)
-    {
-    return CUBITS[cubit].getRotRow(cubitface/2) == (cubitface%2==0 ? (1<<(numLayers-1)):1) ? cubitface : NUM_TEXTURES;
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // PUBLIC API
 
diff --git a/src/main/res/raw/cube3.dmesh b/src/main/res/raw/cube3.dmesh
index ed588f7f..0399aa3b 100644
Binary files a/src/main/res/raw/cube3.dmesh and b/src/main/res/raw/cube3.dmesh differ
diff --git a/src/main/res/raw/cube4.dmesh b/src/main/res/raw/cube4.dmesh
index 935b0f80..1449030c 100644
Binary files a/src/main/res/raw/cube4.dmesh and b/src/main/res/raw/cube4.dmesh differ
diff --git a/src/main/res/raw/cube5.dmesh b/src/main/res/raw/cube5.dmesh
index e8bb1492..939a54c5 100644
Binary files a/src/main/res/raw/cube5.dmesh and b/src/main/res/raw/cube5.dmesh differ
