commit 3a1efb3246dbbd6b71f0258169422cfd7423330c
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Nov 12 02:17:26 2021 +0100

    Bugfixes for the ShapeChanging touch control.
    Still doesn't work but doesn't crash anymore :)

diff --git a/src/main/java/org/distorted/objectlib/main/TwistyObject.java b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
index a2dcd144..148e9c0c 100644
--- a/src/main/java/org/distorted/objectlib/main/TwistyObject.java
+++ b/src/main/java/org/distorted/objectlib/main/TwistyObject.java
@@ -19,6 +19,11 @@
 
 package org.distorted.objectlib.main;
 
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Random;
+
 import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -51,23 +56,9 @@ import org.distorted.objectlib.helpers.ObjectShape;
 import org.distorted.objectlib.helpers.ObjectSticker;
 import org.distorted.objectlib.helpers.ScrambleState;
 import org.distorted.objectlib.json.JsonReader;
-import org.distorted.objectlib.touchcontrol.TouchControl;
-import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
-import org.distorted.objectlib.touchcontrol.TouchControlDodecahedron;
-import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
-import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
-import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
+import org.distorted.objectlib.touchcontrol.*;
 
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Random;
-
-import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
-import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
-import static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
-import static org.distorted.objectlib.touchcontrol.TouchControl.TC_DODECAHEDRON;
-import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID;
+import static org.distorted.objectlib.touchcontrol.TouchControl.*;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -1351,6 +1342,8 @@ public abstract class TwistyObject
         case TC_CUBOID      : int[] numLayers = getNumLayers();
                               mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
                               break;
+        case TC_CHANGING    : mTouchControl = new TouchControlShapeChanging(this);
+                              break;
         }
       }
     return mTouchControl;
diff --git a/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java b/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
index 4a48ff95..b9d3b931 100644
--- a/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
+++ b/src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
@@ -19,6 +19,7 @@
 
 package org.distorted.objectlib.objects;
 
+import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CHANGING;
 import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID;
 import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
 
@@ -644,7 +645,7 @@ public class TwistyCuboid extends ShapeHexahedron
 
   public int getMovementType()
     {
-    return TC_CUBOID;
+    return TC_CHANGING;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
index f85e6581..28b6ec15 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControl.java
@@ -38,6 +38,7 @@ public abstract class TouchControl
   public static final int TC_OCTAHEDRON   = 8;
   public static final int TC_DODECAHEDRON =12;
   public static final int TC_CUBOID       = 0;
+  public static final int TC_CHANGING     = 1;
 
   float mObjectRatio;
 
diff --git a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
index a1c63686..a2ab8646 100644
--- a/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
+++ b/src/main/java/org/distorted/objectlib/touchcontrol/TouchControlShapeChanging.java
@@ -26,7 +26,7 @@ import org.distorted.objectlib.main.TwistyObject;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-public abstract class TouchControlShapeChanging extends TouchControl
+public class TouchControlShapeChanging extends TouchControl
   {
   private static final float NOT_TOUCHED = -1000000.0f;
   private static final float[] mTmp = new float[4];
@@ -49,11 +49,11 @@ public abstract class TouchControlShapeChanging extends TouchControl
 
       // assuming the first three vertices are linearly independent
       float a1 = vertices[0][0] - vertices[1][0];
-      float a2 = vertices[0][1] - vertices[1][2];
-      float a3 = vertices[0][2] - vertices[1][3];
+      float a2 = vertices[0][1] - vertices[1][1];
+      float a3 = vertices[0][2] - vertices[1][2];
       float b1 = vertices[1][0] - vertices[2][0];
-      float b2 = vertices[1][1] - vertices[2][2];
-      float b3 = vertices[1][2] - vertices[2][3];
+      float b2 = vertices[1][1] - vertices[2][1];
+      float b3 = vertices[1][2] - vertices[2][2];
 
       float vx = a2*b3-a3*b2;
       float vy = a3*b1-a1*b3;
@@ -92,11 +92,11 @@ public abstract class TouchControlShapeChanging extends TouchControl
   private boolean mPreparationDone;
   private FaceInfo[][] mInfos;
   private int mTouchedCubit;
-  private int mTouchedSide;
+  private int mTouchedFace;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  TouchControlShapeChanging(TwistyObject object)
+  public TouchControlShapeChanging(TwistyObject object)
     {
     mPoint = new float[3];
     mCamera= new float[3];
@@ -133,9 +133,9 @@ public abstract class TouchControlShapeChanging extends TouchControl
     for(int i=0; i<numFaces; i++)
       {
       int numVerts = indices[i].length;
-      float[][] verts = new float[numVerts][3];
+      float[][] verts = new float[numVerts][4];
 
-      for(int j=0; j<numFaces; j++)
+      for(int j=0; j<numVerts; j++)
         {
         int index = indices[i][j];
         float x = vertices[index][0];
@@ -148,6 +148,7 @@ public abstract class TouchControlShapeChanging extends TouchControl
         verts[j][0] = tmp.get0() + avgX;
         verts[j][1] = tmp.get1() + avgY;
         verts[j][2] = tmp.get2() + avgZ;
+        verts[j][3] = 1.0f;
         }
 
       infos[i] = new FaceInfo(verts);
@@ -351,7 +352,7 @@ public abstract class TouchControlShapeChanging extends TouchControl
 
     float closestSoFar = NOT_TOUCHED;
     mTouchedCubit = -1;
-    mTouchedSide  = -1;
+    mTouchedFace  = -1;
 
     for(int i=0; i<mNumCubits; i++)
       {
@@ -364,12 +365,17 @@ public abstract class TouchControlShapeChanging extends TouchControl
         if( dist!=NOT_TOUCHED )
           {
           mTouchedCubit = i;
-          mTouchedSide  = j;
+          mTouchedFace  = j;
           }
         closestSoFar = dist;
         }
       }
 
+    if( closestSoFar!=NOT_TOUCHED )
+      {
+      android.util.Log.e("D", "cubit="+mTouchedCubit+" face="+mTouchedFace);
+      }
+
     return closestSoFar!=NOT_TOUCHED;
     }
 
@@ -411,4 +417,11 @@ public abstract class TouchControlShapeChanging extends TouchControl
     {
     return null;
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public float returnRotationFactor(int[] numLayers, int row)
+    {
+    return 1.0f;
+    }
   }
