commit fcc0e034da329e141189ad6c10564ca33390e901
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Wed Sep 16 21:49:59 2020 +0100

    Correct the Dino mesh.

diff --git a/src/main/java/org/distorted/main/RubikActivity.java b/src/main/java/org/distorted/main/RubikActivity.java
index 2f82f593..da9675af 100644
--- a/src/main/java/org/distorted/main/RubikActivity.java
+++ b/src/main/java/org/distorted/main/RubikActivity.java
@@ -92,17 +92,17 @@ public class RubikActivity extends AppCompatActivity
 
       String[] PERMISSIONS_STORAGE =
         {
-        Manifest.permission.READ_EXTERNAL_STORAGE,
-        Manifest.permission.WRITE_EXTERNAL_STORAGE
+        android.Manifest.permission.READ_EXTERNAL_STORAGE,
+        android.Manifest.permission.WRITE_EXTERNAL_STORAGE
         };
 
-      int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+      int permission = androidx.core.app.ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
 
-      if (permission != PackageManager.PERMISSION_GRANTED)
+      if (permission != android.content.pm.PackageManager.PERMISSION_GRANTED)
         {
-        ActivityCompat.requestPermissions( this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE );
+        androidx.core.app.ActivityCompat.requestPermissions( this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE );
         }
- */
+*/
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/RubikDino.java b/src/main/java/org/distorted/objects/RubikDino.java
index 67b088d4..d01f61c7 100644
--- a/src/main/java/org/distorted/objects/RubikDino.java
+++ b/src/main/java/org/distorted/objects/RubikDino.java
@@ -23,10 +23,7 @@ import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 
-import org.distorted.library.effect.MatrixEffectMove;
 import org.distorted.library.effect.MatrixEffectQuaternion;
-import org.distorted.library.effect.MatrixEffectRotate;
-import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.effect.VertexEffectDeform;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
@@ -52,7 +49,6 @@ public class RubikDino extends RubikObject
 {
   private static final float SQ2 = (float)Math.sqrt(2);
   private static final float SQ3 = (float)Math.sqrt(3);
-  private static final float ANGLE_FACES = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
 
   // the four rotation axis of a RubikDino. Must be normalized.
   static final Static3D[] ROT_AXIS = new Static3D[]
@@ -112,9 +108,9 @@ public class RubikDino extends RubikObject
            new Static3D(-1.5f, 0.0f,-1.5f )
          };
 
-  private static final int[] mFaceMap = {2,4, 4,0, 3,4, 4,1,
-                                         0,2, 0,3, 1,3, 1,2,
-                                         2,5, 5,0, 3,5, 5,1 };
+  private static final int[] mFaceMap = {4,2, 0,4, 4,3, 1,4,
+                                         2,0, 3,0, 3,1, 2,1,
+                                         5,2, 0,5, 5,3, 1,5 };
 
   private static MeshBase mMesh;
 
@@ -128,121 +124,130 @@ public class RubikDino extends RubikObject
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private MeshBase createTetrahedronMesh()
+  private void createBasicMesh()
     {
+    final float ANGLE = (float)((180/Math.PI)*(Math.atan(SQ2)));
+
     final int MESHES=4;
 
-    int association = 1;
+    float D = 0.02f;
+    float E = 0.5f*SQ2;
+    float F = 0.5f;
 
-    float D = 0.005f;
-    float E = 0.5f - D*SQ2;
-    float F = 0.5f - D*SQ2*SQ3;
-    float[] bands = { 1.0f    ,-D,
-                      1.0f-D/2,-D*0.55f,
-                      1.0f-D  ,-D*0.25f,
-                      1.0f-2*D,+D*0.25f,
-                      0.50f, 0.040f,
-                      0.0f, 0.045f };
+    float[] bands0 = { 1.0f    , 0,
+                       1.0f-2*D, D*0.25f,
+                       1.0f-4*D, D*0.35f,
+                       1.0f-8*D, D*0.6f,
+                       0.60f   , D*1.0f,
+                       0.30f   , D*1.375f,
+                       0.0f    , D*1.4f };
 
-    float[] vertices = { -F,-E, +F,-E, 0.0f,E-D*SQ2};
+    float[] vertices0 = { -F,F/3, 0,-2*F/3, +F,F/3 };
 
     MeshBase[] meshes = new MeshPolygon[MESHES];
-    meshes[0] = new MeshPolygon(vertices, bands, 2, 3);
-    meshes[0].setEffectAssociation(0,association,0);
+    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
+    meshes[0].setEffectAssociation(0,1,0);
+    meshes[1] = meshes[0].copy(true);
+    meshes[1].setEffectAssociation(0,2,0);
 
-    for(int i=1; i<MESHES; i++)
-      {
-      association <<= 1;
-      meshes[i] = meshes[0].copy(true);
-      meshes[i].setEffectAssociation(0,association,0);
-      }
+    float[] bands1 = { 1.0f    , 0,
+                       0.50f   , 0.10f,
+                       0.0f    , 0.20f };
+
+    float[] vertices1 = { -E/2,-E*(SQ3/6), E/2,-E*(SQ3/6), 0,E*(SQ3/3) };
 
-    MeshBase result = new MeshJoined(meshes);
+    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
+    meshes[2].setEffectAssociation(0,4,0);
+    meshes[3] = meshes[2].copy(true);
+    meshes[3].setEffectAssociation(0,8,0);
 
-    Static3D a0 = new Static3D(         0,        1,       0 );
-    Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
-    Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
-    Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
+    mMesh = new MeshJoined(meshes);
 
-    float tetraHeight = SQ2*SQ3/3;
-    float d1 = 0.75f*tetraHeight;
-    float d2 =-0.10f*tetraHeight;
-    float d3 =-0.05f*tetraHeight;
-    float d4 = 0.15f*tetraHeight;
+    Static3D a0 = new Static3D(     0,-3*F,    0 );
+    Static3D a1 = new Static3D(     0,   0, -3*F );
+    Static3D a2 = new Static3D(  -3*F,   0,    0 );
+    Static3D a3 = new Static3D(  +3*F,   0,    0 );
+
+    Static3D v0 = new Static3D(     0,-3*F/2, 3*F/2 );
+    Static3D v1 = new Static3D(     0, 3*F/2,-3*F/2 );
+    Static3D v2 = new Static3D(  -3*F, 3*F/2, 3*F/2 );
+    Static3D v3 = new Static3D(  +3*F, 3*F/2, 3*F/2 );
+
+    float d1 = 1.0f;
+    float d2 =-0.10f;
+    float d3 =-0.10f;
+    float d4 = 0.40f;
 
     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( d3*a0.get0(), d3*a0.get1(), d3*a0.get2() );
-    Static3D dVec1 = new Static3D( d3*a1.get0(), d3*a1.get1(), d3*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() );
+    Static3D dVec0 = new Static3D( d3*v0.get0(), d3*v0.get1(), d3*v0.get2() );
+    Static3D dVec1 = new Static3D( d3*v1.get0(), d3*v1.get1(), d3*v1.get2() );
+    Static3D dVec2 = new Static3D( d2*v2.get0(), d2*v2.get1(), d2*v2.get2() );
+    Static3D dVec3 = new Static3D( d2*v3.get0(), d2*v3.get1(), d2*v3.get2() );
 
     Static4D dReg  = new Static4D(0,0,0,d4);
     Static1D dRad  = new Static1D(1);
 
-    Static1D angle  = new Static1D(ANGLE_FACES);
-    Static3D axis1  = new Static3D(  -1, 0,      0);
-    Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
-    Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
-    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
-    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
-
-    VertexEffectScale   effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
-    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
-    VertexEffectMove    effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
-    VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
-    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
-    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
-    VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
-
-    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
-    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
-    VertexEffectDeform  effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
-    VertexEffectDeform  effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
-
-    effect4.setMeshAssociation(14,-1);  // apply to mesh[1], [2] and [3]
-    effect5.setMeshAssociation( 2,-1);  // apply only to mesh[1]
-    effect6.setMeshAssociation( 4,-1);  // apply only to mesh[2]
-    effect7.setMeshAssociation( 8,-1);  // apply only to mesh[3]
-
-    result.apply(effect1);
-    result.apply(effect2);
-    result.apply(effect3);
-    result.apply(effect4);
-    result.apply(effect5);
-    result.apply(effect6);
-    result.apply(effect7);
-    result.apply(effect8);
-    result.apply(effect9);
-    result.apply(effect10);
-    result.apply(effect11);
-
-    result.mergeEffComponents();
-
-    return result;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void createBasicMesh()
-    {
-    mMesh = createTetrahedronMesh();
-
-    Static3D axis = new Static3D(1,0,0);
-    Static3D cent = new Static3D(0,0,0);
-
-    MatrixEffectMove   moveEffect = new MatrixEffectMove  ( new Static3D(0.0f,SQ3*SQ2/12,SQ3/6) );
-    MatrixEffectRotate rot1Effect = new MatrixEffectRotate( new Static1D(180+ANGLE_FACES/2), axis, cent);
-    MatrixEffectScale  scalEffect = new MatrixEffectScale ( new Static3D(3.0f, 3*SQ2/2, 1.5f) );
-    MatrixEffectRotate rot2Effect = new MatrixEffectRotate( new Static1D(-45), axis, cent);
-
-    mMesh.apply(moveEffect, 0xffffffff, 0);
-    mMesh.apply(rot1Effect, 0xffffffff, 0);
-    mMesh.apply(scalEffect, 0xffffffff, 0);
-    mMesh.apply(rot2Effect, 0xffffffff, 0);
+    Static1D angle1 = new Static1D(+ANGLE);
+    Static1D angle2 = new Static1D(-ANGLE);
+
+    Static3D axisX  = new Static3D(1,0,0);
+    Static3D axisY  = new Static3D(0,1,0);
+    Static3D axisZ  = new Static3D(0,-1,1);
+
+    Static3D center0= new Static3D(0,0,0);
+    Static3D center1= new Static3D(0,-3*F,0);
+
+    VertexEffectScale   effect0 = new VertexEffectScale ( new Static3D(3,3,3) );
+    VertexEffectMove    effect1 = new VertexEffectMove  ( new Static3D(0,-F,0) );
+    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), axisX, center0 );
+    VertexEffectScale   effect3 = new VertexEffectScale ( new Static3D(1,-1,1) );
+    VertexEffectMove    effect4 = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
+    VertexEffectRotate  effect5 = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
+    VertexEffectScale   effect6 = new VertexEffectScale ( new Static3D(-1,1,1) );
+    VertexEffectRotate  effect7 = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
+    VertexEffectRotate  effect8 = new VertexEffectRotate( angle1           , axisZ, center1 );
+    VertexEffectRotate  effect9 = new VertexEffectRotate( angle2           , axisZ, center1 );
+
+    VertexEffectDeform  effect10= new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
+    VertexEffectDeform  effect11= new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
+    VertexEffectDeform  effect12= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
+    VertexEffectDeform  effect13= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
+
+    effect0.setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
+    effect1.setMeshAssociation( 3,-1);  // apply to meshes 0,1
+    effect2.setMeshAssociation( 2,-1);  // apply to mesh 1
+    effect3.setMeshAssociation( 2,-1);  // apply to mesh 0
+    effect4.setMeshAssociation(12,-1);  // apply to meshes 2,3
+    effect5.setMeshAssociation(12,-1);  // apply to meshes 2,3
+    effect6.setMeshAssociation( 8,-1);  // apply to mesh 3
+    effect7.setMeshAssociation(12,-1);  // apply to meshes 2,3
+    effect8.setMeshAssociation( 4,-1);  // apply to mesh 2
+    effect9.setMeshAssociation( 8,-1);  // apply to mesh 3
+    effect10.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+    effect11.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+    effect12.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+    effect13.setMeshAssociation(15,-1); // apply to meshes 0,1,2,3
+
+    mMesh.apply(effect0);
+    mMesh.apply(effect1);
+    mMesh.apply(effect2);
+    mMesh.apply(effect3);
+    mMesh.apply(effect4);
+    mMesh.apply(effect5);
+    mMesh.apply(effect6);
+    mMesh.apply(effect7);
+    mMesh.apply(effect8);
+    mMesh.apply(effect9);
+    mMesh.apply(effect10);
+    mMesh.apply(effect11);
+    mMesh.apply(effect12);
+    mMesh.apply(effect13);
+
+    mMesh.mergeEffComponents();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -316,16 +321,10 @@ public class RubikDino extends RubikObject
 
   void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
     {
-    float STROKE = 0.046f*side;
-    float OFF = STROKE/2 -1;
-    float OFF2 = 0.5f*side + OFF;
-    float HEIGHT = side - OFF;
-    float RADIUS = side/12.0f;
-    float ARC1_H = 0.2f*side;
-    float ARC1_W = side*0.5f;
-    float ARC2_W = 0.153f*side;
-    float ARC2_H = 0.905f*side;
-    float ARC3_W = side-ARC2_W;
+    float STROKE = 0.04f*side;
+    float L= left;
+    float H= 0.333f*side;
+    float LEN = 0.5f*side;
 
     paint.setAntiAlias(true);
     paint.setStrokeWidth(STROKE);
@@ -337,13 +336,23 @@ public class RubikDino extends RubikObject
     paint.setColor(INTERIOR_COLOR);
     paint.setStyle(Paint.Style.STROKE);
 
-    canvas.drawLine(           left, HEIGHT,  side       +left, HEIGHT, paint);
-    canvas.drawLine(      OFF +left, side  ,       OFF2  +left,      0, paint);
-    canvas.drawLine((side-OFF)+left, side  , (side-OFF2) +left,      0, paint);
+    canvas.drawLine( L      , H,  L+2*LEN, H    , paint);
+    canvas.drawLine( L      , H,  L+  LEN, H+LEN, paint);
+    canvas.drawLine( L+2*LEN, H,  L+  LEN, H+LEN, paint);
+
+    float S1 = 0.150f*side;
+    float S2 = 0.090f*side;
+    float X  = 0.7f*S2;
+    float Y  = 0.2f*S1;
+
+    float LA = left+0.500f*side;
+    float RA = left;
+    float TA = 0.333f*side;
+    float BA = 0.833f*side;
 
-    canvas.drawArc( ARC1_W-RADIUS+left, ARC1_H-RADIUS, ARC1_W+RADIUS+left, ARC1_H+RADIUS, 225, 90, false, paint);
-    canvas.drawArc( ARC2_W-RADIUS+left, ARC2_H-RADIUS, ARC2_W+RADIUS+left, ARC2_H+RADIUS, 105, 90, false, paint);
-    canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint);
+    canvas.drawArc( RA+X        , TA     , RA+X+S2  , TA+S2, 135,135, false, paint);
+    canvas.drawArc( RA+side-S2-X, TA     , RA+side-X, TA+S2, 270,135, false, paint);
+    canvas.drawArc( LA-S1/2     , BA-S1-Y, LA+S1/2  , BA-Y ,  45, 90, false, paint);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/res/raw/dino.dmesh b/src/main/res/raw/dino.dmesh
index 09aa2c19..b14b436d 100644
Binary files a/src/main/res/raw/dino.dmesh and b/src/main/res/raw/dino.dmesh differ
