commit 80ec6abfaf2712b1efba80fa29e85c89c7625569
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Dec 11 22:25:03 2020 +0100

    Fixes for the Rex Cube (mostly works now)

diff --git a/src/main/java/org/distorted/objects/FactoryCubit.java b/src/main/java/org/distorted/objects/FactoryCubit.java
index 1f519e51..c5702f54 100644
--- a/src/main/java/org/distorted/objects/FactoryCubit.java
+++ b/src/main/java/org/distorted/objects/FactoryCubit.java
@@ -38,7 +38,7 @@ class FactoryCubit
   static final float IVY_D = 0.003f;
   static final float IVY_C = 0.59f;
   static final float IVY_M = 0.35f;
-  static final float REX_D = 0.03f;
+  static final float REX_D = 0.003f;
 
   private static final float SQ2 = (float)Math.sqrt(2);
   private static final float SQ3 = (float)Math.sqrt(3);
@@ -195,21 +195,20 @@ class FactoryCubit
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'angle' of the point
-// (px,py) along axis Z. Center of rotation: (cx,cy).
+// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'radians' of the
+// point (px,py) along axis Z. Center of rotation: (cx,cy). Rotation is counterclockwise!
 // Write (rx,ry) to array[index] and array[index+1].
 
-  private void writeVertex( float cx, float cy, float px, float py, float angle, float[] array, int index)
+  private void writeVertex( float cx, float cy, float px, float py, float radians, float[] array, int index)
     {
     float vx = px-cx;
     float vy = py-cy;
 
-    double radAngle = Math.PI*angle/180;
-    float sinA = (float)Math.sin(radAngle);
-    float cosA = (float)Math.cos(radAngle);
+    float sinA = (float)Math.sin(radians);
+    float cosA = (float)Math.cos(radians);
 
-    float rvx = vx*cosA +vy*sinA;
-    float rvy =-vx*sinA +vy*cosA;
+    float rvx = vx*cosA - vy*sinA;
+    float rvy = vx*sinA + vy*cosA;
 
     array[index  ] = rvx + cx;
     array[index+1] = rvy + cy;
@@ -609,10 +608,9 @@ class FactoryCubit
 
     final float angle = (float)Math.PI/(6*REX_N);
     float[] vertices = new float[6*REX_N];
-    final float H = SQ2*(SQ3/3 - 0.5f);
     final float D = 0.5f - REX_D;
-    final float F = H*D;
-    final float B = (float)Math.sqrt(12/(H*H) - 0.75f) - 0.5f;
+    final float F = D*SQ2*(SQ3-1);
+    final float B = 2.5f;
 
     final float V1x = -F*0.5f;
     final float V1y = -F*SQ3/6;
@@ -622,21 +620,21 @@ class FactoryCubit
     final float V3y = -2*V1y;
 
     final float C1x = 0.0f;
-    final float C1y = -D*( (SQ3/6)*H - (float)Math.sqrt(4.0f-0.25f*H*H) );
-    final float C2x = B*V2x;
-    final float C2y = B*V2y;
-    final float C3x = B*V3x;
-    final float C3y = B*V3y;
+    final float C1y = -F*(1+2*SQ3/3);
+    final float C2x = B*V1x;
+    final float C2y = B*V1y;
+    final float C3x = B*V2x;
+    final float C3y = B*V2y;
 
     for(int i=0; i<REX_N; i++)
       {
-      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
+      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
       writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
       writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
       }
 
-    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
-    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
+    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
+    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
 
     meshes[0] = new MeshPolygon(vertices,bands0,1,1);
     meshes[0].setEffectAssociation(0,1,0);
@@ -654,26 +652,25 @@ class FactoryCubit
 
     final float angle = (float)Math.PI/(6*REX_N);
     float[] vertices = new float[8*REX_N];
-    final float H = SQ3/2 - 0.5f;
     final float D = 0.5f - REX_D;
-    final float F = H*D;
+    final float F = D*(SQ3-1);
 
     final float V1x = 0.0f;
     final float V1y = +F;
-    final float V2x = +F;
+    final float V2x = -F;
     final float V2y = 0.0f;
     final float V3x = 0.0f;
     final float V3y = -F;
-    final float V4x = -F;
+    final float V4x = +F;
     final float V4y = 0.0f;
 
-    final float C1x = -D;
+    final float C1x = +D;
     final float C1y = -D;
-    final float C2x = -D;
+    final float C2x = +D;
     final float C2y = +D;
-    final float C3x = +D;
+    final float C3x = -D;
     final float C3y = +D;
-    final float C4x = +D;
+    final float C4x = -D;
     final float C4y = -D;
 
     for(int i=0; i<REX_N; i++)
@@ -684,8 +681,8 @@ class FactoryCubit
       writeVertex(C4x,C4y,V4x,V4y, i*angle, vertices, 2*i + 6*REX_N);
       }
 
-    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
-    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
+    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
+    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
 
     meshes[0] = new MeshPolygon(vertices,bands0,0,0);
     meshes[0].setEffectAssociation(0,1,0);
@@ -702,34 +699,36 @@ class FactoryCubit
     MeshBase[] meshes = new MeshBase[4];
 
     final float angle = (float)Math.PI/(6*REX_N);
-    float[] vertices = new float[4*REX_N + 4];
+    float[] vertices = new float[4*REX_N + 6];
     final float H = 1.0f - SQ3/2;
     final float D = 0.5f - REX_D;
-    final float F = H*D;
+    final float F = 0.5f*(0.5f - D*(SQ3-1));
 
     final float V1x = -D;
-    final float V1y = +D - D*SQ3/2;
+    final float V1y = +D + F - 0.5f;
     final float V2x = 0.0f;
-    final float V2y = D*(SQ3-1) - D*SQ3/2;
+    final float V2y = -F;
 
     final float C1x = -D;
-    final float C1y = -D - D*SQ3/2;
+    final float C1y = -D + F - 0.5f;
     final float C2x = +D;
     final float C2y = C1y;
 
     for(int i=0; i<REX_N; i++)
       {
-      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
-      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
+      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
+      writeVertex(C2x,C2y,V2x,V2y,-i*angle, vertices, 2*i + 2*REX_N);
       }
 
     vertices[4*REX_N  ] = +D;
-    vertices[4*REX_N+1] = +F + REX_D;
-    vertices[4*REX_N+2] = -D;
-    vertices[4*REX_N+3] = +F + REX_D;
+    vertices[4*REX_N+1] = +F-REX_D;
+    vertices[4*REX_N+2] = +D;
+    vertices[4*REX_N+3] = +F;
+    vertices[4*REX_N+4] = -D;
+    vertices[4*REX_N+5] = +F;
 
-    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
-    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
+    float[] bands0 = computeBands(+0.02f, 9,0.5f,0.5f,5);
+    float[] bands1 = computeBands( 0.00f,45,0.5f,0.0f,2);
 
     meshes[0] = new MeshPolygon(vertices,bands0,1,2);
     meshes[0].setEffectAssociation(0,1,0);
@@ -1174,9 +1173,8 @@ class FactoryCubit
 
   VertexEffect[] createVertexEffectsRexEdge()
     {
-    final float H = 1.0f - SQ3/2;
     final float D = 0.5f - REX_D;
-    final float F = H*D;
+    final float F = 0.5f*(0.5f - D*(SQ3-1));
 
     Static3D move  = new Static3D(0.0f,   -F, 0.0f);
     Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
@@ -1204,7 +1202,7 @@ class FactoryCubit
     {
     Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
     Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
-    Static1D angle = new Static1D(45);
+    Static1D angle = new Static1D(225);
 
     VertexEffect[] effect = new VertexEffect[1];
     effect[0] = new VertexEffectRotate(angle, axisZ, center);
diff --git a/src/main/java/org/distorted/objects/MovementRex.java b/src/main/java/org/distorted/objects/MovementRex.java
index 9ce8dbc4..5072c550 100644
--- a/src/main/java/org/distorted/objects/MovementRex.java
+++ b/src/main/java/org/distorted/objects/MovementRex.java
@@ -25,8 +25,8 @@ import org.distorted.library.type.Static3D;
 
 class MovementRex extends Movement
 {
-  static final float DIST3D = 0.5f;
-  static final float DIST2D = 0.5f;
+  static final float DIST3D = 0.166f;
+  static final float DIST2D = 0.166f;
 
   static final Static3D[] FACE_AXIS = new Static3D[]
          {
diff --git a/src/main/java/org/distorted/objects/TwistyDino.java b/src/main/java/org/distorted/objects/TwistyDino.java
index 5c5f3c52..3ce62dd4 100644
--- a/src/main/java/org/distorted/objects/TwistyDino.java
+++ b/src/main/java/org/distorted/objects/TwistyDino.java
@@ -165,12 +165,7 @@ public abstract class TwistyDino extends TwistyObject
 
   float[] getCuts(int size)
     {
-    float[] cuts = new float[2];
-
-    cuts[0] = -SQ3/3;
-    cuts[1] = +SQ3/3;
-
-    return cuts;
+    return new float[] { -SQ3/3, +SQ3/3 };
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/objects/TwistyRex.java b/src/main/java/org/distorted/objects/TwistyRex.java
index d1838f67..c316a1e9 100644
--- a/src/main/java/org/distorted/objects/TwistyRex.java
+++ b/src/main/java/org/distorted/objects/TwistyRex.java
@@ -118,12 +118,12 @@ public class TwistyRex extends TwistyObject
            {  4, 1, 18,18 },
            {  0, 2, 18,18 },
            {  3, 0, 18,18 },
-           {  1, 3, 18,18 },
-           {  3, 2, 18,18 },
-           {  5, 2, 18,18 },
-           {  5, 0, 18,18 },
+           {  3, 1, 18,18 },
+           {  1, 2, 18,18 },
+           {  2, 5, 18,18 },
+           {  0, 5, 18,18 },
            {  5, 3, 18,18 },
-           {  5, 1, 18,18 },
+           {  1, 5, 18,18 },
          };
 
   private static MeshBase mCornerMesh, mFaceMesh, mEdgeMesh;
@@ -140,7 +140,7 @@ public class TwistyRex extends TwistyObject
 
   float getScreenRatio()
     {
-    return 1.0f;
+    return 1.5f;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -262,16 +262,16 @@ public class TwistyRex extends TwistyObject
     {
     switch(cubit)
       {
-      case  0: return QUATS[5];
-      case  1: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
-      case  2: return QUATS[8];
-      case  3: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
+      case  0: return new Static4D(+SQ2/2,     0,+SQ2/2,     0);
+      case  1: return QUATS[5];
+      case  2: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
+      case  3: return QUATS[8];
       case  4: return QUATS[6];
-      case  5: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
+      case  5: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
       case  6: return QUATS[11];
-      case  7: return new Static4D(-SQ2/2,     0,+SQ2/2,     0);
-      case  8: return QUATS[10];
-      case  9: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
+      case  7: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
+      case  8: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
+      case  9: return QUATS[10];
       case 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
       case 11: return QUATS[4];
       case 12: return QUATS[9];
@@ -282,13 +282,13 @@ public class TwistyRex extends TwistyObject
       case 17: return QUATS[0];
       case 18: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
       case 19: return QUATS[3];
-      case 20: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
-      case 21: return QUATS[2];
-      case 22: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
-      case 23: return QUATS[1];
+      case 20: return QUATS[1];
+      case 21: return new Static4D(+SQ2/2,-SQ2/2,     0,     0);
+      case 22: return QUATS[2];
+      case 23: return new Static4D(+SQ2/2,+SQ2/2,     0,     0);
 
-      case 24: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
-      case 25: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
+      case 24: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
+      case 25: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
       case 26: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
       case 27: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
       case 28: return QUATS[0];
@@ -298,10 +298,10 @@ public class TwistyRex extends TwistyObject
       case 31: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
       case 32: return QUATS[3];
       case 33: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
-      case 34: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
+      case 34: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
       case 35: return QUATS[7];
       case 36: return QUATS[9];
-      case 37: return new Static4D(     0,-SQ2/2,     0, SQ2/2);
+      case 37: return new Static4D(     0,+SQ2/2,     0, SQ2/2);
       case 38: return new Static4D(+SQ2/2,     0,     0, SQ2/2);
       case 39: return QUATS[8];
       case 40: return QUATS[1];
