commit b32444ee24b5ad2a41ff6d9dd62fc6ddcacf943f
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Feb 21 22:12:06 2020 +0000

    More work on making new types of RubikObjects easily creatable.

diff --git a/src/main/java/org/distorted/object/Cubit.java b/src/main/java/org/distorted/object/Cubit.java
index e0871669..63ecea5a 100644
--- a/src/main/java/org/distorted/object/Cubit.java
+++ b/src/main/java/org/distorted/object/Cubit.java
@@ -26,7 +26,7 @@ import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.effect.MatrixEffectRotate;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedNode;
-import org.distorted.library.mesh.MeshCubes;
+import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.message.EffectListener;
 import org.distorted.library.type.Dynamic1D;
 import org.distorted.library.type.Static1D;
@@ -43,7 +43,7 @@ class Cubit
   private final Static3D mOrigPosition;
 
   private RubikObject mParent;
-  private MeshCubes mCube;
+  private MeshBase mMesh;
   private Static3D mRotationAxis;
   private MatrixEffectRotate mRotateEffect;
 
@@ -153,7 +153,7 @@ class Cubit
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  Cubit(RubikObject parent, MeshCubes mesh, Static3D position)
+  Cubit(RubikObject parent, MeshBase mesh, Static3D position)
     {
     float x = position.get0();
     float y = position.get1();
@@ -164,7 +164,7 @@ class Cubit
     Static3D vector = new Static3D(TS*(x-nc), TS*(y-nc), TS*(z-nc));
 
     mParent          = parent;
-    mCube            = mesh;
+    mMesh            = mesh;
     mOrigPosition    = new Static3D(x,y,z);
     mQuatScramble    = new Static4D(0,0,0,1);
     mRotationAngle   = new Dynamic1D();
@@ -182,7 +182,7 @@ class Cubit
     mEffect.apply(mParent.mScaleEffect);
     mEffect.apply(mParent.mMoveEffect);
 
-    mNode = new DistortedNode(mParent.mTexture,mEffect,mCube);
+    mNode = new DistortedNode(mParent.mTexture,mEffect,mMesh);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -267,7 +267,7 @@ class Cubit
 
   void releaseResources()
     {
-    mCube.markForDeletion();
+    mMesh.markForDeletion();
     mNode.markForDeletion();
     }
 
diff --git a/src/main/java/org/distorted/object/RubikCube.java b/src/main/java/org/distorted/object/RubikCube.java
index 015e7451..88a2c253 100644
--- a/src/main/java/org/distorted/object/RubikCube.java
+++ b/src/main/java/org/distorted/object/RubikCube.java
@@ -25,6 +25,7 @@ import android.graphics.Paint;
 
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshCubes;
 import org.distorted.library.mesh.MeshRectangles;
 import org.distorted.library.type.Static3D;
@@ -34,42 +35,6 @@ import org.distorted.library.type.Static4D;
 
 class RubikCube extends RubikObject
 {
-  private static final Static4D mapFront, mapBack, mapLeft, mapRight, mapTop, mapBottom, mapBlack;
-
-  static
-    {
-    // 3x2 bitmap = 6 squares:
-    //
-    // RED     GREEN   BLUE
-    // YELLOW  WHITE   BROWN
-
-    final float ze = 0.0f;
-    final float ot = 1.0f/3.0f;
-    final float tt = 2.0f/3.0f;
-    final float oh = 1.0f/2.0f;
-    final float of = 1.0f/40.0f;
-
-    mapFront = new Static4D(ze,oh, ze+ot,oh+oh);
-    mapBack  = new Static4D(tt,ze, tt+ot,ze+oh);
-    mapLeft  = new Static4D(ot,ze, ot+ot,ze+oh);
-    mapRight = new Static4D(ze,ze, ze+ot,ze+oh);
-    mapTop   = new Static4D(tt,oh, tt+ot,oh+oh);
-    mapBottom= new Static4D(ot,oh, ot+ot,oh+oh);
-
-    mapBlack = new Static4D(ze,ze, ze+of,ze+of);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or
-// render the inside)
-
-  int getNumCubits(int size)
-    {
-    return size>1 ? 6*size*size - 12*size + 8 : 1;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
   int[][] getCubitPositions(int size)
     {
     int[][] tmp = new int[getNumCubits(size)][3];
@@ -93,6 +58,15 @@ class RubikCube extends RubikObject
     return tmp;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or
+// render the inside)
+
+  int getNumCubits(int size)
+    {
+    return size>1 ? 6*size*size - 12*size + 8 : 1;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // All legal rotation quats of a RubikCube of any size must have all four of their components
 // equal to either 0, 1, -1, 0.5, -0.5 or +-sqrt(2)/2.
@@ -168,7 +142,34 @@ class RubikCube extends RubikObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  MeshCubes createMesh(int vertices,int x, int y, int z)
+  private static final Static4D mapFront, mapBack, mapLeft, mapRight, mapTop, mapBottom, mapBlack;
+
+  static
+    {
+    // 3x2 bitmap = 6 squares:
+    //
+    // RED     GREEN   BLUE
+    // YELLOW  WHITE   BROWN
+
+    final float ze = 0.0f;
+    final float ot = 1.0f/3.0f;
+    final float tt = 2.0f/3.0f;
+    final float oh = 1.0f/2.0f;
+    final float of = 1.0f/40.0f;
+
+    mapFront = new Static4D(ze,oh, ze+ot,oh+oh);
+    mapBack  = new Static4D(tt,ze, tt+ot,ze+oh);
+    mapLeft  = new Static4D(ot,ze, ot+ot,ze+oh);
+    mapRight = new Static4D(ze,ze, ze+ot,ze+oh);
+    mapTop   = new Static4D(tt,oh, tt+ot,oh+oh);
+    mapBottom= new Static4D(ot,oh, ot+ot,oh+oh);
+
+    mapBlack = new Static4D(ze,ze, ze+of,ze+of);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createCubitMesh(int vertices, int x, int y, int z)
     {
     Static4D tmpLeft  = (x==       0 ? mapLeft  :mapBlack);
     Static4D tmpRight = (x== mSize-1 ? mapRight :mapBlack);
diff --git a/src/main/java/org/distorted/object/RubikObject.java b/src/main/java/org/distorted/object/RubikObject.java
index 029a0d78..a70a6231 100644
--- a/src/main/java/org/distorted/object/RubikObject.java
+++ b/src/main/java/org/distorted/object/RubikObject.java
@@ -29,7 +29,7 @@ import org.distorted.library.effect.VertexEffectSink;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedNode;
 import org.distorted.library.main.DistortedTexture;
-import org.distorted.library.mesh.MeshCubes;
+import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshRectangles;
 import org.distorted.library.message.EffectListener;
 import org.distorted.library.type.Dynamic1D;
@@ -47,12 +47,12 @@ public abstract class RubikObject extends DistortedNode
 
   private static final int POST_ROTATION_MILLISEC = 500;
   private final int NUM_CUBITS;
-  private final int[][] CUBIT_POSITIONS;
   private int mRotRow;
   private Static3D mRotAxis;
   private Static3D mMove, mScale, mNodeMove, mNodeScale;
   private Static4D mQuatAccumulated;
   private DistortedTexture mNodeTexture;
+  private Cubit[] mCubits;
 
   int mSize;
 
@@ -65,8 +65,6 @@ public abstract class RubikObject extends DistortedNode
   MatrixEffectQuaternion mQuatCEffect;
   MatrixEffectQuaternion mQuatAEffect;
 
-  private Cubit[] mCubits;
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   RubikObject(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
@@ -75,7 +73,6 @@ public abstract class RubikObject extends DistortedNode
 
     LEGAL_QUATS = getLegalQuats();
     NUM_CUBITS  = getNumCubits(size);
-    CUBIT_POSITIONS = getCubitPositions(size);
 
     mNodeTexture = texture;
     mSize = size;
@@ -107,20 +104,19 @@ public abstract class RubikObject extends DistortedNode
     effects.apply(nodeScaleEffect);
     effects.apply(nodeMoveEffect);
 
-
     mCubits = new Cubit[NUM_CUBITS];
-
     mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE);
 
     int vertices = (int)(24.0f/mSize + 2.0f);
+    int[][] positions = getCubitPositions(size);
 
     for(int i=0; i<NUM_CUBITS; i++)
       {
-      int x = CUBIT_POSITIONS[i][0];
-      int y = CUBIT_POSITIONS[i][1];
-      int z = CUBIT_POSITIONS[i][2];
+      int x = positions[i][0];
+      int y = positions[i][1];
+      int z = positions[i][2];
 
-      mCubits[i] = new Cubit( this ,createMesh(vertices,x,y,z), new Static3D(x,y,z) );
+      mCubits[i] = new Cubit( this ,createCubitMesh(vertices,x,y,z), new Static3D(x,y,z) );
       attach(mCubits[i].mNode);
       }
     }
@@ -359,7 +355,7 @@ public abstract class RubikObject extends DistortedNode
   abstract int[][] getCubitPositions(int size);
   abstract float[] getLegalQuats();
   abstract boolean belongsToRotation(Static3D position, Static3D axis, int row);
-  abstract MeshCubes createMesh(int vertices,int x, int y, int z);
+  abstract MeshBase createCubitMesh(int vertices, int x, int y, int z);
 
   public abstract void createTexture();
   }
diff --git a/src/main/java/org/distorted/object/RubikObjectList.java b/src/main/java/org/distorted/object/RubikObjectList.java
index d03d1d10..a56f6d10 100644
--- a/src/main/java/org/distorted/object/RubikObjectList.java
+++ b/src/main/java/org/distorted/object/RubikObjectList.java
@@ -86,7 +86,7 @@ public enum RubikObjectList
     {
     DistortedTexture texture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE);
     DistortedEffects effects = new DistortedEffects();
-    MeshRectangles mesh      = new MeshRectangles(20,20);
+    MeshRectangles mesh      = new MeshRectangles(20,20);   // mesh of the node, not of the cubits
 
     return new RubikCube(mObjectSize, quatCur, quatAcc, texture, mesh, effects);
     }
