commit ab0c28f0762227bb366a4ad2472e6935bc2c2b09
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Sep 25 19:10:29 2020 +0100

    Progress with the Skewb Diamond - it is rendered correctly now.

diff --git a/src/main/java/org/distorted/objects/ObjectList.java b/src/main/java/org/distorted/objects/ObjectList.java
index aaf111f0..20d393c4 100644
--- a/src/main/java/org/distorted/objects/ObjectList.java
+++ b/src/main/java/org/distorted/objects/ObjectList.java
@@ -473,12 +473,12 @@ public enum ObjectList
 
     switch(ordinal())
       {
-      case 0: return new TwistyCube(size, quat, texture, mesh, effects, moves, res, scrWidth);
-      case 1: return new TwistyPyraminx(size, quat, texture, mesh, effects, moves, res, scrWidth);
-      case 2: return new TwistyDiamond(size, quat, texture, mesh, effects, moves, res, scrWidth);
-      case 3: return new TwistyDino6(size, quat, texture, mesh, effects, moves, res, scrWidth);
-      case 4: return new TwistyDino4(size, quat, texture, mesh, effects, moves, res, scrWidth);
-      case 5: return new TwistySkewb(size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 0: return new TwistyCube      (size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 1: return new TwistyPyraminx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 2: return new TwistyDiamond   (size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 3: return new TwistyDino6     (size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 4: return new TwistyDino4     (size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 5: return new TwistySkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
       case 6: return new TwistyHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
       }
 
diff --git a/src/main/java/org/distorted/objects/TwistyDiamond.java b/src/main/java/org/distorted/objects/TwistyDiamond.java
index 597df701..9147d808 100644
--- a/src/main/java/org/distorted/objects/TwistyDiamond.java
+++ b/src/main/java/org/distorted/objects/TwistyDiamond.java
@@ -24,10 +24,18 @@ import android.graphics.Canvas;
 import android.graphics.Paint;
 
 import org.distorted.library.effect.MatrixEffectQuaternion;
+import org.distorted.library.effect.VertexEffectDeform;
+import org.distorted.library.effect.VertexEffectMove;
+import org.distorted.library.effect.VertexEffectRotate;
+import org.distorted.library.effect.VertexEffectScale;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshBase;
+import org.distorted.library.mesh.MeshJoined;
+import org.distorted.library.mesh.MeshPolygon;
 import org.distorted.library.mesh.MeshSquare;
+import org.distorted.library.mesh.MeshTriangle;
+import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static3D;
 import org.distorted.library.type.Static4D;
 
@@ -71,11 +79,14 @@ public class TwistyDiamond extends TwistyObject
            COLOR_PINK  , COLOR_VIOLET
          };
 
-  // All legal rotation quats of a Diamond
+  // All legal rotation quats of a Diamond: unit + three 180 deg turns + 8 generators
   private static final Static4D[] QUATS = new Static4D[]
          {
            new Static4D(  0.0f,  0.0f,   0.0f,  1.0f ),
            new Static4D(  0.0f,  1.0f,   0.0f,  0.0f ),
+           new Static4D(+SQ2/2,  0.0f, -SQ2/2,  0.0f ),
+           new Static4D(-SQ2/2,  0.0f, -SQ2/2,  0.0f ),
+
            new Static4D(+SQ2/2,  0.5f,   0.0f,  0.5f ),
            new Static4D(-SQ2/2,  0.5f,   0.0f,  0.5f ),
            new Static4D(  0.0f,  0.5f, +SQ2/2,  0.5f ),
@@ -83,9 +94,7 @@ public class TwistyDiamond extends TwistyObject
            new Static4D(+SQ2/2,  0.5f,   0.0f, -0.5f ),
            new Static4D(-SQ2/2,  0.5f,   0.0f, -0.5f ),
            new Static4D(  0.0f,  0.5f, +SQ2/2, -0.5f ),
-           new Static4D(  0.0f,  0.5f, -SQ2/2, -0.5f ),
-           new Static4D(+SQ2/2,  0.0f, -SQ2/2,  0.0f ),
-           new Static4D(-SQ2/2,  0.0f, -SQ2/2,  0.0f )
+           new Static4D(  0.0f,  0.5f, -SQ2/2, -0.5f )
          };
 
   private static final float DIST = 0.50f;
@@ -144,21 +153,243 @@ public class TwistyDiamond extends TwistyObject
 
   private void createOctaMesh()
     {
+    int association = 1;
+
+    float C = 0.06f;
+    float D = 0.02f;
+    float E = SQ3/2;
+    float F = 0.5f;
+
+    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
+
+    float[] bands = new float[] { 1.0f    , 0,
+                                  1.0f  -C, D*0.50f,
+                                  1.0f-2*C, D*0.80f,
+                                  1.0f-4*C, D*1.00f,
+                                  0.5f    , D*1.20f,
+                                  0.0f    , D*1.25f };
 
+    MeshBase[] meshes = new MeshPolygon[FACES_PER_CUBIT];
+    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
+    meshes[0].setEffectAssociation(0,association,0);
+
+    for(int i=1; i<FACES_PER_CUBIT; i++)
+      {
+      association <<= 1;
+      meshes[i] = meshes[0].copy(true);
+      meshes[i].setEffectAssociation(0,association,0);
+      }
+
+    mOctaMesh = new MeshJoined(meshes);
+
+    float d1 = SQ2/2;
+    float d2 =-0.06f;
+    float d3 = 0.20f;
+
+    Static3D a0 = new Static3D(     0, 1,     0 );
+    Static3D a1 = new Static3D( SQ2/2, 0, SQ2/2 );
+    Static3D a2 = new Static3D(-SQ2/2, 0, SQ2/2 );
+
+    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
+    Static1D angle1= new Static1D( 90);
+    Static1D angle2= new Static1D(180);
+    Static1D angle3= new Static1D(270);
+
+    Static3D move1 = new Static3D(0,SQ2/2-SQ3/3,0);
+
+    Static3D axisX = new Static3D(1,0,0);
+    Static3D axisY = new Static3D(0,1,0);
+
+    Static3D cent0 = new Static3D(0,0,0);
+    Static3D cent1 = new Static3D(0,SQ2/2,0);
+
+    Static3D flipY = new Static3D( 1,-1, 1);
+
+    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
+    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
+    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
+    Static3D dCen3 = new Static3D(-d1*a0.get0(),-d1*a0.get1(),-d1*a0.get2() );
+    Static3D dCen4 = new Static3D(-d1*a1.get0(),-d1*a2.get1(),-d1*a2.get2() );
+    Static3D dCen5 = new Static3D(-d1*a2.get0(),-d1*a1.get1(),-d1*a1.get2() );
+
+    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
+    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
+    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
+    Static3D dVec3 = new Static3D(-d2*a0.get0(),-d2*a0.get1(),-d2*a0.get2() );
+    Static3D dVec4 = new Static3D(-d2*a1.get0(),-d2*a1.get1(),-d2*a1.get2() );
+    Static3D dVec5 = new Static3D(-d2*a2.get0(),-d2*a2.get1(),-d2*a2.get2() );
+
+    Static4D dReg  = new Static4D(0,0,0,d3);
+    Static1D dRad  = new Static1D(1);
+
+    VertexEffectMove   effect0 = new VertexEffectMove(move1);
+    VertexEffectRotate effect1 = new VertexEffectRotate(alpha , axisX, cent1);
+    VertexEffectRotate effect2 = new VertexEffectRotate(angle1, axisY, cent0);
+    VertexEffectRotate effect3 = new VertexEffectRotate(angle2, axisY, cent0);
+    VertexEffectRotate effect4 = new VertexEffectRotate(angle3, axisY, cent0);
+    VertexEffectScale  effect5 = new VertexEffectScale(flipY);
+
+    VertexEffectDeform  effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
+    VertexEffectDeform  effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
+    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
+    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
+    VertexEffectDeform  effect10= new VertexEffectDeform(dVec4, dRad, dCen4, dReg);
+    VertexEffectDeform  effect11= new VertexEffectDeform(dVec5, dRad, dCen5, dReg);
+
+    effect0.setMeshAssociation (255,-1); // apply to all meshes
+    effect1.setMeshAssociation (255,-1); // apply to all meshes
+    effect2.setMeshAssociation ( 34,-1); // apply to meshes 1 & 5
+    effect3.setMeshAssociation ( 68,-1); // apply to meshes 2 & 6
+    effect4.setMeshAssociation (136,-1); // apply to meshes 3 & 7
+    effect5.setMeshAssociation (240,-1); // apply to meshes 4,5,6,7
+    effect6.setMeshAssociation (255,-1); // apply to all meshes
+    effect7.setMeshAssociation (255,-1); // apply to all meshes
+    effect8.setMeshAssociation (255,-1); // apply to all meshes
+    effect9.setMeshAssociation (255,-1); // apply to all meshes
+    effect10.setMeshAssociation(255,-1); // apply to all meshes
+    effect11.setMeshAssociation(255,-1); // apply to all meshes
+
+    mOctaMesh.apply(effect0);
+    mOctaMesh.apply(effect1);
+    mOctaMesh.apply(effect2);
+    mOctaMesh.apply(effect3);
+    mOctaMesh.apply(effect4);
+    mOctaMesh.apply(effect5);
+    mOctaMesh.apply(effect6);
+    mOctaMesh.apply(effect7);
+    mOctaMesh.apply(effect8);
+    mOctaMesh.apply(effect9);
+    mOctaMesh.apply(effect10);
+    mOctaMesh.apply(effect11);
+
+    mOctaMesh.mergeEffComponents();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void createTetraMesh()
     {
+    int association = 1;
+
+    float C = 0.06f;
+    float D = 0.035f;
+    float E = SQ3/2;
+    float F = 0.5f;
+
+    float[] vertices = { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
 
+    float[] bands = new float[] { 1.0f    , 0,
+                                  1.0f  -C, D*0.50f,
+                                  1.0f-2*C, D*0.80f,
+                                  1.0f-4*C, D*1.00f,
+                                  0.5f    , D*1.20f,
+                                  0.0f    , D*1.25f };
+
+    MeshBase[] meshes = new MeshBase[FACES_PER_CUBIT];
+    meshes[0] = new MeshPolygon(vertices, bands, 2,2);
+    meshes[0].setEffectAssociation(0,association,0);
+
+    for(int i=1; i<4; i++)
+      {
+      association <<= 1;
+      meshes[i] = meshes[0].copy(true);
+      meshes[i].setEffectAssociation(0,association,0);
+      }
+
+    for(int i=4; i<FACES_PER_CUBIT; i++)
+      {
+      association <<= 1;
+      meshes[i] = new MeshTriangle(1);
+      meshes[i].setEffectAssociation(0,association,0);
+      }
+
+    mTetraMesh = new MeshJoined(meshes);
+
+    Static3D flipZ = new Static3D( 1, 1,-1);
+
+    Static1D alpha = new Static1D((float)(-(180/Math.PI)*Math.asin(SQ3/3)));
+    Static1D angle1= new Static1D( 90);
+    Static1D angle2= new Static1D(180);
+    Static3D move1 = new Static3D(0,SQ2/4-SQ3/6,0);
+
+    Static3D axisX = new Static3D(1,0,0);
+    Static3D axisY = new Static3D(0,1,0);
+    Static3D axisZ = new Static3D(0,0,1);
+
+    Static3D cent0 = new Static3D(0,0,0);
+    Static3D cent1 = new Static3D(0,SQ2/4,0);
+
+    float d1 =-1.00f;
+    float d2 = 0.10f;
+    float d3 = 0.15f;
+
+    float vx = 0.5f   ;
+    float vy = (SQ2/4);
+
+    Static3D a0 = new Static3D(+vx,-vy, 0 );
+    Static3D a1 = new Static3D(-vx,-vy, 0 );
+    Static3D a2 = new Static3D(  0, vy,-vx);
+    Static3D a3 = new Static3D(  0, vy,+vx);
+
+    Static4D dReg  = new Static4D(0,0,0,d3);
+    Static1D dRad  = new Static1D(1);
+
+    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
+    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
+    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
+    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
+
+    Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
+    Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
+    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
+    Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
+
+    VertexEffectRotate effect0 = new VertexEffectRotate(angle2, axisZ, cent0);
+    VertexEffectMove   effect1 = new VertexEffectMove(move1);
+    VertexEffectRotate effect2 = new VertexEffectRotate(alpha , axisX, cent1);
+    VertexEffectScale  effect3 = new VertexEffectScale(flipZ);
+    VertexEffectRotate effect4 = new VertexEffectRotate(angle1, axisY, cent0);
+    VertexEffectRotate effect5 = new VertexEffectRotate(angle2, axisZ, cent0);
+
+    VertexEffectDeform  effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
+    VertexEffectDeform  effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
+    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
+    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
+
+    VertexEffectScale  effect10 = new VertexEffectScale(0.1f);
+
+    effect0.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect1.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect2.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect3.setMeshAssociation(10,-1); // meshes 1 & 3
+    effect4.setMeshAssociation(12,-1); // meshes 2 & 3
+    effect5.setMeshAssociation(12,-1); // meshes 2 & 3
+    effect6.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect7.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect8.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect9.setMeshAssociation(15,-1); // meshes 0,1,2,3
+    effect10.setMeshAssociation(240,-1); // meshes 4,5,6,7
+
+    mTetraMesh.apply(effect0);
+    mTetraMesh.apply(effect1);
+    mTetraMesh.apply(effect2);
+    mTetraMesh.apply(effect3);
+    mTetraMesh.apply(effect4);
+    mTetraMesh.apply(effect5);
+    mTetraMesh.apply(effect6);
+    mTetraMesh.apply(effect7);
+    mTetraMesh.apply(effect8);
+    mTetraMesh.apply(effect9);
+    mTetraMesh.apply(effect10);
+
+    mTetraMesh.mergeEffComponents();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   float getScreenRatio()
     {
-    return 1.0f;
+    return 0.65f;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -223,13 +454,13 @@ public class TwistyDiamond extends TwistyObject
       case  4:
       case  5:
       case  6: return QUATS[0];                          // unit quat
-      case  7: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along Y
+      case  7: return new Static4D(0,-SQ2/2,0,SQ2/2);    //  90 along Y
       case  8: return QUATS[1];                          // 180 along Y
-      case  9: return new Static4D(-SQ2/2,0,0,SQ2/2);    //  90 along Y
-      case 10: return new Static4D(     0,0,1,    0);    // 180 along Z
-      case 11: return new Static4D(0, SQ2/2,SQ2/2,0);    //
+      case  9: return new Static4D(0,+SQ2/2,0,SQ2/2);    //  90 along Y
+      case 10: return new Static4D(0,     0,1,    0);    // 180 along Z
+      case 11: return new Static4D(SQ2/2, 0,SQ2/2,0);    //
       case 12: return new Static4D(     1,0,0,    0);    // 180 along X
-      case 13: return new Static4D(0,-SQ2/2,SQ2/2,0);    //
+      case 13: return new Static4D(-SQ2/2,0,SQ2/2,0);    //
       }
 
     return null;
@@ -388,13 +619,25 @@ public class TwistyDiamond extends TwistyObject
 
   public boolean isSolved()
     {
-
-
-    return false;
+    int q = CUBITS[0].mQuatIndex;
+
+    return ( CUBITS[ 1].mQuatIndex == q &&
+             CUBITS[ 2].mQuatIndex == q &&
+             CUBITS[ 3].mQuatIndex == q &&
+             CUBITS[ 4].mQuatIndex == q &&
+             CUBITS[ 5].mQuatIndex == q &&
+             CUBITS[ 6].mQuatIndex == q &&
+             CUBITS[ 7].mQuatIndex == q &&
+             CUBITS[ 8].mQuatIndex == q &&
+             CUBITS[ 9].mQuatIndex == q &&
+             CUBITS[10].mQuatIndex == q &&
+             CUBITS[11].mQuatIndex == q &&
+             CUBITS[12].mQuatIndex == q &&
+             CUBITS[13].mQuatIndex == q  );
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// only needed for solvers - there are no Diamond solvers ATM)
+// only needed for solvers - there are no Diamond solvers ATM
 
   public String retObjectString()
     {
diff --git a/src/main/java/org/distorted/objects/TwistyObject.java b/src/main/java/org/distorted/objects/TwistyObject.java
index b4eec3ff..59cf3cec 100644
--- a/src/main/java/org/distorted/objects/TwistyObject.java
+++ b/src/main/java/org/distorted/objects/TwistyObject.java
@@ -68,7 +68,7 @@ public abstract class TwistyObject extends DistortedNode
   private static final float MAX_SIZE_CHANGE = 1.3f;
   private static final float MIN_SIZE_CHANGE = 0.8f;
 
-  private static boolean mCreateFromDMesh = true;
+  private static boolean mCreateFromDMesh = false;
 
   private static final Static3D CENTER = new Static3D(0,0,0);
   static final int INTERIOR_COLOR = 0xff000000;
