commit 59b87d56141b7a67c9cc665b4a60dbb34ddcc375
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Dec 11 00:12:19 2020 +0100

    Adding Rex Cube - take 1 (doesn't work yet)

diff --git a/src/main/java/org/distorted/objects/FactoryCubit.java b/src/main/java/org/distorted/objects/FactoryCubit.java
index 71c659e6..8521327f 100644
--- a/src/main/java/org/distorted/objects/FactoryCubit.java
+++ b/src/main/java/org/distorted/objects/FactoryCubit.java
@@ -38,12 +38,14 @@ 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;
 
   private static final float SQ2 = (float)Math.sqrt(2);
   private static final float SQ3 = (float)Math.sqrt(3);
   private static final float SQ6 = (float)Math.sqrt(6);
 
   private static final int IVY_N = 8;
+  private static final int REX_N = 5;
   private static final Static1D RADIUS = new Static1D(1);
   private static FactoryCubit mThis;
 
@@ -192,6 +194,27 @@ 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).
+// 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)
+    {
+    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 rvx = vx*cosA +vy*sinA;
+    float rvy =-vx*sinA +vy*cosA;
+
+    array[index  ] = rvx + cx;
+    array[index+1] = rvy + cy;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   MeshBase createFacesCube(int sizeIndex)
@@ -578,6 +601,148 @@ class FactoryCubit
     return new MeshJoined(meshes);
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createFacesRexCorner()
+    {
+    MeshBase[] meshes = new MeshBase[2];
+
+    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 V1x = -F*0.5f;
+    final float V1y = -F*SQ3/6;
+    final float V2x = -V1x;
+    final float V2y = V1y;
+    final float V3x = 0.0f;
+    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;
+
+    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(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);
+
+    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
+    meshes[0].setEffectAssociation(0,1,0);
+    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
+    meshes[1].setEffectAssociation(0,2,0);
+
+    return new MeshJoined(meshes);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createFacesRexFace()
+    {
+    MeshBase[] meshes = new MeshBase[2];
+
+    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 V1x = 0.0f;
+    final float V1y = +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 V4y = 0.0f;
+
+    final float C1x = -D;
+    final float C1y = -D;
+    final float C2x = -D;
+    final float C2y = +D;
+    final float C3x = +D;
+    final float C3y = +D;
+    final float C4x = +D;
+    final float C4y = -D;
+
+    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(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
+      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);
+
+    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
+    meshes[0].setEffectAssociation(0,1,0);
+    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
+    meshes[1].setEffectAssociation(0,2,0);
+
+    return new MeshJoined(meshes);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createFacesRexEdge()
+    {
+    MeshBase[] meshes = new MeshBase[4];
+
+    final float angle = (float)Math.PI/(6*REX_N);
+    float[] vertices = new float[4*REX_N + 4];
+    final float H = 1.0f - SQ3/2;
+    final float D = 0.5f - REX_D;
+    final float F = H*D;
+
+    final float V1x = -D;
+    final float V1y = +D - D*SQ3/2;
+    final float V2x = 0.0f;
+    final float V2y = D*(SQ3-1) - D*SQ3/2;
+
+    final float C1x = -D;
+    final float C1y = -D - D*SQ3/2;
+    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);
+      }
+
+    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;
+
+    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
+    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
+
+    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
+    meshes[0].setEffectAssociation(0,1,0);
+    meshes[1] = meshes[0].copy(true);
+    meshes[1].setEffectAssociation(0,2,0);
+    meshes[2] = new MeshPolygon(vertices,bands1,0,0);
+    meshes[2].setEffectAssociation(0,4,0);
+    meshes[3] = meshes[2].copy(true);
+    meshes[3].setEffectAssociation(0,8,0);
+
+    return new MeshJoined(meshes);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // EFFECTS
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1005,6 +1170,52 @@ class FactoryCubit
     return effect;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  VertexEffect[] createVertexEffectsRexEdge()
+    {
+    final float H = 1.0f - SQ3/2;
+    final float D = 0.5f - REX_D;
+    final float F = H*D;
+
+    Static3D move  = new Static3D(0.0f, 0.5f - F, 0.0f);
+    Static3D center= new Static3D(0.0f, F, 0.0f);
+    Static3D axisX = new Static3D(1.0f, 0.0f, 0.0f);
+    Static3D axisY = new Static3D(0.0f, 1.0f, 0.0f);
+
+    Static1D angle180 = new Static1D(180);
+    Static1D angle90  = new Static1D( 90);
+
+    VertexEffect[] effect = new VertexEffect[3];
+
+    effect[0] = new VertexEffectRotate(angle180, axisY, center);
+    effect[1] = new VertexEffectRotate(angle90 , axisX, center);
+    effect[2] = new VertexEffectMove(move);
+
+    effect[0].setMeshAssociation(10,-1);  // meshes 1 & 3
+    effect[1].setMeshAssociation(10,-1);  // meshes 1 & 3
+
+    return effect;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  VertexEffect[] createVertexEffectsRexCorner()
+    {
+    float F = SQ3/6*(1.0f-2*REX_D);
+    Static3D move  = new Static3D(F,F,0.0f);
+    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);
+
+    VertexEffect[] effect = new VertexEffect[2];
+
+    effect[0] = new VertexEffectRotate(angle, axisZ, center);
+    effect[1] = new VertexEffectMove(move);
+
+    return effect;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // OBJECTS
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1298,6 +1509,58 @@ class FactoryCubit
     mesh.addEmptyTexComponent();
     mesh.addEmptyTexComponent();
 
+    return mesh;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createRexCornerMesh()
+    {
+    MeshBase mesh = createFacesRexCorner();
+    VertexEffect[] effects = createVertexEffectsRexCorner();
+    for( VertexEffect effect : effects ) mesh.apply(effect);
+
+    Static3D center = new Static3D(0.0f,0.0f,-0.25f);
+    Static3D[] vertices = new Static3D[1];
+    vertices[0] = new Static3D(+0.25f,+0.25f,+0.0f);
+    roundCorners(mesh,center,vertices,0.03f,0.10f);
+
+    mesh.mergeEffComponents();
+    mesh.addEmptyTexComponent();
+    mesh.addEmptyTexComponent();
+
+    return mesh;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createRexFaceMesh()
+    {
+    MeshBase mesh = createFacesRexFace();
+
+    mesh.mergeEffComponents();
+    mesh.addEmptyTexComponent();
+    mesh.addEmptyTexComponent();
+
+    return mesh;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createRexEdgeMesh()
+    {
+    MeshBase mesh = createFacesRexEdge();
+    VertexEffect[] effects = createVertexEffectsRexEdge();
+    for( VertexEffect effect : effects ) mesh.apply(effect);
+
+    Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
+    Static3D[] vertices = new Static3D[2];
+    vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
+    vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
+    roundCorners(mesh,center,vertices,0.03f,0.10f);
+
+    mesh.mergeEffComponents();
+
     return mesh;
     }
   }
diff --git a/src/main/java/org/distorted/objects/FactorySticker.java b/src/main/java/org/distorted/objects/FactorySticker.java
index 2920a3ab..849e57e1 100644
--- a/src/main/java/org/distorted/objects/FactorySticker.java
+++ b/src/main/java/org/distorted/objects/FactorySticker.java
@@ -239,4 +239,34 @@ class FactorySticker
     canvas.drawArc( left+cx3-halfR, top+cy3-halfR, left+cx3+halfR, top+cy3+halfR, 180, 90, false, paint);
     canvas.drawArc( left+cx4-halfR, top+cy4-halfR, left+cx4+halfR, top+cy4+halfR,   0, 90, false, paint);
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
+
+  void drawRexCornerSticker(Canvas canvas, Paint paint, int left, int top, int color, float stroke, float radius)
+    {
+    paint.setColor(color);
+    paint.setStyle(Paint.Style.FILL);
+    canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
+
+  void drawRexFaceSticker(Canvas canvas, Paint paint, int left, int top, int color, float stroke, float radius)
+    {
+    paint.setColor(color);
+    paint.setStyle(Paint.Style.FILL);
+    canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// TODO
+
+  void drawRexEdgeSticker(Canvas canvas, Paint paint, int left, int top, int color, float stroke, float radius)
+    {
+    paint.setColor(color);
+    paint.setStyle(Paint.Style.FILL);
+    canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint);
+    }
   }
diff --git a/src/main/java/org/distorted/objects/MovementRex.java b/src/main/java/org/distorted/objects/MovementRex.java
new file mode 100644
index 00000000..9ce8dbc4
--- /dev/null
+++ b/src/main/java/org/distorted/objects/MovementRex.java
@@ -0,0 +1,144 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2020 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Magic Cube.                                                              //
+//                                                                                               //
+// Magic Cube is free software: you can redistribute it and/or modify                            //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Magic Cube is distributed in the hope that it will be useful,                                 //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.objects;
+
+import org.distorted.library.type.Static3D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class MovementRex extends Movement
+{
+  static final float DIST3D = 0.5f;
+  static final float DIST2D = 0.5f;
+
+  static final Static3D[] FACE_AXIS = new Static3D[]
+         {
+           new Static3D(1,0,0), new Static3D(-1,0,0),
+           new Static3D(0,1,0), new Static3D(0,-1,0),
+           new Static3D(0,0,1), new Static3D(0,0,-1)
+         };
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MovementRex()
+    {
+    super(TwistyRex.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int computeRowFromOffset(int face, int size, float offset)
+    {
+    return offset<DIST2D ? 0:2;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public float returnRotationFactor(int size, int row)
+    {
+    return 1.0f;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// _____________
+// |  \  0  /  |
+// |   \   /   |
+// | 3 |   | 1 |
+// |   /   \   |
+// |  /  2  \  |
+// -------------
+
+  private int getQuarter(float[] touchPoint)
+    {
+    boolean p0 = touchPoint[1] >= touchPoint[0];
+    boolean p1 = touchPoint[1] >=-touchPoint[0];
+
+    if( p0 )  return p1 ? 0:3;
+    else      return p1 ? 1:2;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  boolean isInsideFace(int face, float[] p)
+    {
+    return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D );
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
+    {
+    enabled[0] = 2;
+
+    int quarter = getQuarter(touchPoint);
+
+    switch(face)
+      {
+      case 0: switch(quarter)
+                {
+                case 0: enabled[1]=0; enabled[2]=1; break;
+                case 1: enabled[1]=3; enabled[2]=1; break;
+                case 2: enabled[1]=2; enabled[2]=3; break;
+                case 3: enabled[1]=0; enabled[2]=2; break;
+                }
+              break;
+      case 1: switch(quarter)
+                {
+                case 0: enabled[1]=2; enabled[2]=3; break;
+                case 1: enabled[1]=3; enabled[2]=1; break;
+                case 2: enabled[1]=0; enabled[2]=1; break;
+                case 3: enabled[1]=0; enabled[2]=2; break;
+                }
+              break;
+      case 2: switch(quarter)
+                {
+                case 0: enabled[1]=1; enabled[2]=2; break;
+                case 1: enabled[1]=0; enabled[2]=1; break;
+                case 2: enabled[1]=0; enabled[2]=3; break;
+                case 3: enabled[1]=2; enabled[2]=3; break;
+                }
+              break;
+      case 3: switch(quarter)
+                {
+                case 0: enabled[1]=1; enabled[2]=2; break;
+                case 1: enabled[1]=2; enabled[2]=3; break;
+                case 2: enabled[1]=0; enabled[2]=3; break;
+                case 3: enabled[1]=0; enabled[2]=1; break;
+                }
+              break;
+      case 4: switch(quarter)
+                {
+                case 0: enabled[1]=0; enabled[2]=3; break;
+                case 1: enabled[1]=0; enabled[2]=2; break;
+                case 2: enabled[1]=1; enabled[2]=2; break;
+                case 3: enabled[1]=1; enabled[2]=3; break;
+                }
+              break;
+      case 5: switch(quarter)
+                {
+                case 0: enabled[1]=1; enabled[2]=2; break;
+                case 1: enabled[1]=0; enabled[2]=2; break;
+                case 2: enabled[1]=0; enabled[2]=3; break;
+                case 3: enabled[1]=1; enabled[2]=3; break;
+                }
+              break;
+      }
+    }
+}
diff --git a/src/main/java/org/distorted/objects/ObjectList.java b/src/main/java/org/distorted/objects/ObjectList.java
index 7540ffaa..f4abaf32 100644
--- a/src/main/java/org/distorted/objects/ObjectList.java
+++ b/src/main/java/org/distorted/objects/ObjectList.java
@@ -120,6 +120,15 @@ public enum ObjectList
          new MovementIvy(),
          3
        ),
+
+   REX (
+         new int[][] {
+                       {3 , 16, R.raw.ivy, R.drawable.ui_small_ivy, R.drawable.ui_medium_ivy, R.drawable.ui_big_ivy, R.drawable.ui_huge_ivy} ,
+                     },
+         TwistyRex.class,
+         new MovementRex(),
+         3
+       ),
   ;
 
   public static final int NUM_OBJECTS = values().length;
@@ -501,6 +510,7 @@ public enum ObjectList
       case 6: return new TwistyHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
       case 7: return new TwistySkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
       case 8: return new TwistyIvy       (size, quat, texture, mesh, effects, moves, res, scrWidth);
+      case 9: return new TwistyRex       (size, quat, texture, mesh, effects, moves, res, scrWidth);
       }
 
     return null;
diff --git a/src/main/java/org/distorted/objects/TwistyObject.java b/src/main/java/org/distorted/objects/TwistyObject.java
index f1f3bcdf..e1d28e68 100644
--- a/src/main/java/org/distorted/objects/TwistyObject.java
+++ b/src/main/java/org/distorted/objects/TwistyObject.java
@@ -78,7 +78,7 @@ public abstract class TwistyObject extends DistortedNode
   private static final float MAX_SIZE_CHANGE = 1.35f;
   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);
   private static final int POST_ROTATION_MILLISEC = 500;
diff --git a/src/main/java/org/distorted/objects/TwistyRex.java b/src/main/java/org/distorted/objects/TwistyRex.java
new file mode 100644
index 00000000..0a8f37c2
--- /dev/null
+++ b/src/main/java/org/distorted/objects/TwistyRex.java
@@ -0,0 +1,517 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2020 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Magic Cube.                                                              //
+//                                                                                               //
+// Magic Cube is free software: you can redistribute it and/or modify                            //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Magic Cube is distributed in the hope that it will be useful,                                 //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.objects;
+
+import android.content.res.Resources;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+
+import org.distorted.library.effect.MatrixEffectQuaternion;
+import org.distorted.library.main.DistortedEffects;
+import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.mesh.MeshBase;
+import org.distorted.library.mesh.MeshSquare;
+import org.distorted.library.type.Static3D;
+import org.distorted.library.type.Static4D;
+import org.distorted.main.R;
+import org.distorted.main.RubikSurfaceView;
+
+import java.util.Random;
+
+import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class TwistyRex extends TwistyObject
+{
+  private static final int FACES_PER_CUBIT =4;
+
+  // the four rotation axis of a RubikRex. Must be normalized.
+  static final Static3D[] ROT_AXIS = new Static3D[]
+         {
+           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
+           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
+           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
+           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
+         };
+
+  private static final int[] FACE_COLORS = new int[]
+         {
+           COLOR_YELLOW, COLOR_WHITE,
+           COLOR_BLUE  , COLOR_GREEN,
+           COLOR_RED   , COLOR_BROWN
+         };
+
+  // All legal rotation quats of a RubikRex
+  private static final Static4D[] QUATS = new Static4D[]
+         {
+           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
+           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
+           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
+           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
+
+           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
+           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
+           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
+           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
+           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
+           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
+           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
+           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f )
+         };
+
+  private static final int[][] mFaceMap =
+         {
+           {  0, 18,18,18 },
+           {  0, 18,18,18 },
+           {  0, 18,18,18 },
+           {  0, 18,18,18 },
+           {  1, 18,18,18 },
+           {  1, 18,18,18 },
+           {  1, 18,18,18 },
+           {  1, 18,18,18 },
+           {  2, 18,18,18 },
+           {  2, 18,18,18 },
+           {  2, 18,18,18 },
+           {  2, 18,18,18 },
+           {  3, 18,18,18 },
+           {  3, 18,18,18 },
+           {  3, 18,18,18 },
+           {  3, 18,18,18 },
+           {  4, 18,18,18 },
+           {  4, 18,18,18 },
+           {  4, 18,18,18 },
+           {  4, 18,18,18 },
+           {  5, 18,18,18 },
+           {  5, 18,18,18 },
+           {  5, 18,18,18 },
+           {  5, 18,18,18 },
+
+           {  6, 18,18,18 },
+           {  7, 18,18,18 },
+           {  8, 18,18,18 },
+           {  9, 18,18,18 },
+           { 10, 18,18,18 },
+           { 11, 18,18,18 },
+
+           {  4, 2, 18,18 },
+           {  4, 0, 18,18 },
+           {  4, 3, 18,18 },
+           {  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 },
+           {  5, 3, 18,18 },
+           {  5, 1, 18,18 },
+         };
+
+  private static MeshBase mCornerMesh, mFaceMesh, mEdgeMesh;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  TwistyRex(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
+            DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
+    {
+    super(size, size, 60, quat, texture, mesh, effects, moves, ObjectList.REX, res, scrWidth);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  float getScreenRatio()
+    {
+    return 1.0f;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  Static4D[] getQuats()
+    {
+    return QUATS;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getNumFaces()
+    {
+    return FACE_COLORS.length;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  boolean shouldResetTextureMaps()
+    {
+    return false;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getNumStickerTypes()
+    {
+    return 3;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  float[] getCuts(int numLayers)
+    {
+    float C = SQ3*0.15f;   // bit less than 1/6 of the length of the main diagonal
+
+    return new float[] {-C,+C};
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getNumCubitFaces()
+    {
+    return FACES_PER_CUBIT;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  Static3D[] getCubitPositions(int numLayers)
+    {
+    final float DIST = 0.50f;
+    final float E    = SQ3/3;
+
+    final Static3D[] CENTERS = new Static3D[42];
+
+    CENTERS[ 0] = new Static3D( +DIST  , +DIST*E, +DIST*E);
+    CENTERS[ 1] = new Static3D( +DIST  , +DIST*E, -DIST*E);
+    CENTERS[ 2] = new Static3D( +DIST  , -DIST*E, -DIST*E);
+    CENTERS[ 3] = new Static3D( +DIST  , -DIST*E, +DIST*E);
+    CENTERS[ 4] = new Static3D( -DIST  , +DIST*E, +DIST*E);
+    CENTERS[ 5] = new Static3D( -DIST  , +DIST*E, -DIST*E);
+    CENTERS[ 6] = new Static3D( -DIST  , -DIST*E, -DIST*E);
+    CENTERS[ 7] = new Static3D( -DIST  , -DIST*E, +DIST*E);
+    CENTERS[ 8] = new Static3D( +DIST*E, +DIST  , +DIST*E);
+    CENTERS[ 9] = new Static3D( +DIST*E, +DIST  , -DIST*E);
+    CENTERS[10] = new Static3D( -DIST*E, +DIST  , -DIST*E);
+    CENTERS[11] = new Static3D( -DIST*E, +DIST  , +DIST*E);
+    CENTERS[12] = new Static3D( +DIST*E, -DIST  , +DIST*E);
+    CENTERS[13] = new Static3D( +DIST*E, -DIST  , -DIST*E);
+    CENTERS[14] = new Static3D( -DIST*E, -DIST  , -DIST*E);
+    CENTERS[15] = new Static3D( -DIST*E, -DIST  , +DIST*E);
+    CENTERS[16] = new Static3D( +DIST*E, +DIST*E, +DIST  );
+    CENTERS[17] = new Static3D( +DIST*E, -DIST*E, +DIST  );
+    CENTERS[18] = new Static3D( -DIST*E, -DIST*E, +DIST  );
+    CENTERS[19] = new Static3D( -DIST*E, +DIST*E, +DIST  );
+    CENTERS[20] = new Static3D( +DIST*E, +DIST*E, -DIST  );
+    CENTERS[21] = new Static3D( +DIST*E, -DIST*E, -DIST  );
+    CENTERS[22] = new Static3D( -DIST*E, -DIST*E, -DIST  );
+    CENTERS[23] = new Static3D( -DIST*E, +DIST*E, -DIST  );
+
+    CENTERS[24] = new Static3D( +DIST  , +0.00f , +0.00f );
+    CENTERS[25] = new Static3D( -DIST  , +0.00f , +0.00f );
+    CENTERS[26] = new Static3D( +0.00f , +DIST  , +0.00f );
+    CENTERS[27] = new Static3D( +0.00f , -DIST  , +0.00f );
+    CENTERS[28] = new Static3D( +0.00f , +0.00f , +DIST  );
+    CENTERS[29] = new Static3D( +0.00f , +0.00f , -DIST  );
+
+    CENTERS[30] = new Static3D( +0.00f , +DIST  , +DIST  );
+    CENTERS[31] = new Static3D( +DIST  , +0.00f , +DIST  );
+    CENTERS[32] = new Static3D( +0.00f , -DIST  , +DIST  );
+    CENTERS[33] = new Static3D( -DIST  , +0.00f , +DIST  );
+    CENTERS[34] = new Static3D( +DIST  , +DIST  , +0.00f );
+    CENTERS[35] = new Static3D( +DIST  , -DIST  , +0.00f );
+    CENTERS[36] = new Static3D( -DIST  , -DIST  , +0.00f );
+    CENTERS[37] = new Static3D( -DIST  , +DIST  , +0.00f );
+    CENTERS[38] = new Static3D( +0.00f , +DIST  , -DIST  );
+    CENTERS[39] = new Static3D( +DIST  , +0.00f , -DIST  );
+    CENTERS[40] = new Static3D( +0.00f , -DIST  , -DIST  );
+    CENTERS[41] = new Static3D( -DIST  , +0.00f , -DIST  );
+
+    return CENTERS;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 1  +90 ( 1, 0, 0) = Static4D(+SQ2/2,     0,     0, SQ2/2);
+// 2  -90 ( 1, 0, 0) = Static4D(-SQ2/2,     0,     0, SQ2/2);
+// 3  +90 ( 0, 1, 0) = Static4D(     0,+SQ2/2,     0, SQ2/2);
+// 4  -90 ( 0, 1, 0) = Static4D(     0,-SQ2/2,     0, SQ2/2);
+// 5  +90 ( 0, 0, 1) = Static4D(     0,     0,+SQ2/2, SQ2/2);
+// 6  -90 ( 0, 0, 1) = Static4D(     0,     0,-SQ2/2, SQ2/2);
+// 7  180 ( 1, 0, 1) = Static4D(+SQ2/2,     0,+SQ2/2,     0);
+// 8  180 (-1, 0, 1) = Static4D(-SQ2/2,     0,+SQ2/2,     0);
+// 9  180 ( 0, 1, 1) = Static4D(     0,+SQ2/2,+SQ2/2,     0);
+//10  180 ( 0,-1, 1) = Static4D(     0,-SQ2/2,+SQ2/2,     0);
+//11  180 ( 1, 1, 0) = Static4D(+SQ2/2,+SQ2/2,     0,     0);
+//12  180 ( 1,-1, 0) = Static4D(+SQ2/2,-SQ2/2,     0,     0);
+
+  private Static4D getQuat(int cubit)
+    {
+    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  4: return QUATS[6];
+      case  5: return new Static4D(     0,     0,+SQ2/2, SQ2/2);
+      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 10: return new Static4D(     0,+SQ2/2,+SQ2/2,     0);
+      case 11: return QUATS[4];
+      case 12: return QUATS[9];
+      case 13: return new Static4D(-SQ2/2,     0,     0, SQ2/2);
+      case 14: return QUATS[7];
+      case 15: return new Static4D(     0,-SQ2/2,+SQ2/2,     0);
+      case 16: return new Static4D(     0,     0,-SQ2/2, SQ2/2);
+      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 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];
+      case 29: return QUATS[1];
+
+      case 30: return QUATS[0];
+      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 35: return QUATS[7];
+      case 36: return QUATS[9];
+      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];
+      case 41: return QUATS[6];
+      }
+
+    return QUATS[0];
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  MeshBase createCubitMesh(int cubit)
+    {
+    MeshBase mesh;
+
+    if( cubit<12 )
+      {
+      if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createRexCornerMesh();
+      mesh = mCornerMesh.copy(true);
+      }
+    else if( cubit<18 )
+      {
+      if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createRexFaceMesh();
+      mesh = mFaceMesh.copy(true);
+      }
+    else
+      {
+      if( mEdgeMesh==null ) mEdgeMesh = FactoryCubit.getInstance().createRexEdgeMesh();
+      mesh = mEdgeMesh.copy(true);
+      }
+
+    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
+    mesh.apply(quat,0xffffffff,0);
+
+    return mesh;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  int getFaceColor(int cubit, int cubitface, int numLayers)
+    {
+    return mFaceMap[cubit][cubitface];
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
+    {
+    int COLORS = FACE_COLORS.length;
+    FactorySticker factory = FactorySticker.getInstance();
+    float S = 0.08f;
+    float R = 0.12f;
+
+    if( face<COLORS )
+      {
+      factory.drawRexCornerSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S, R);
+      }
+    else if( face<2*COLORS )
+      {
+      factory.drawRexFaceSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S, R);
+      }
+    else
+      {
+      factory.drawRexEdgeSticker(canvas, paint, left, top, FACE_COLORS[face%COLORS], S, R);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  float returnMultiplier()
+    {
+    return 2.0f;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  float[] getRowChances()
+    {
+    return new float[] { 0.5f, 0.5f, 1.0f };
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+
+  public Static3D[] getRotationAxis()
+    {
+    return ROT_AXIS;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getBasicAngle()
+    {
+    return 3;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
+    {
+    int numAxis = ROTATION_AXIS.length;
+
+    if( oldRotAxis == START_AXIS )
+      {
+      return rnd.nextInt(numAxis);
+      }
+    else
+      {
+      int newVector = rnd.nextInt(numAxis-1);
+      return (newVector>=oldRotAxis ? newVector+1 : newVector);
+      }
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
+    {
+    float rowFloat = rnd.nextFloat();
+
+    for(int row=0; row<mRowChances.length; row++)
+      {
+      if( rowFloat<=mRowChances[row] ) return row;
+      }
+
+    return 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// remember about the double cover or unit quaternions!
+
+  private int mulQuat(int q1, int q2)
+    {
+    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
+
+    float rX = result.get0();
+    float rY = result.get1();
+    float rZ = result.get2();
+    float rW = result.get3();
+
+    final float MAX_ERROR = 0.1f;
+    float dX,dY,dZ,dW;
+
+    for(int i=0; i<QUATS.length; i++)
+      {
+      dX = QUATS[i].get0() - rX;
+      dY = QUATS[i].get1() - rY;
+      dZ = QUATS[i].get2() - rZ;
+      dW = QUATS[i].get3() - rW;
+
+      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
+          dY<MAX_ERROR && dY>-MAX_ERROR &&
+          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
+          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
+
+      dX = QUATS[i].get0() + rX;
+      dY = QUATS[i].get1() + rY;
+      dZ = QUATS[i].get2() + rZ;
+      dW = QUATS[i].get3() + rW;
+
+      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
+          dY<MAX_ERROR && dY>-MAX_ERROR &&
+          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
+          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
+      }
+
+    return -1;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// The Rex is solved if and only if:
+//
+// TODO
+
+  public boolean isSolved()
+    {
+    int q = CUBITS[0].mQuatIndex;
+
+    for(int i=1; i<42; i++)
+      {
+      if( CUBITS[i].mQuatIndex != q) return false;
+      }
+
+    return true;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// only needed for solvers - there are no Rex solvers ATM)
+
+  public String retObjectString()
+    {
+    return "";
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getObjectName(int numLayers)
+    {
+    return R.string.rex3;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getInventor(int numLayers)
+    {
+    return R.string.rex3_inventor;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public int getComplexity(int numLayers)
+    {
+    return 3;
+    }
+}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 04c8357d..bebcec04 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -84,6 +84,7 @@
     <string name="redi2" translatable="false">Redi Cube</string>
     <string name="heli3" translatable="false">Helicopter Cube</string>
     <string name="ivy2"  translatable="false">Ivy Cube</string>
+    <string name="rex3"  translatable="false">Rex Cube</string>
     <string name="dino3" translatable="false">Dino Cube (6 color)</string>
     <string name="din43" translatable="false">Dino Cube (4 color)</string>
 
@@ -100,6 +101,7 @@
     <string name="redi2_inventor" translatable="false">Oskar van Deventer, 2009</string>
     <string name="heli3_inventor" translatable="false">Adam G. Cowan, 2006</string>
     <string name="ivy2_inventor"  translatable="false">Eitan Cher, 2009</string>
+    <string name="rex3_inventor"  translatable="false">Andrew Cormier, 2009</string>
     <string name="dino3_inventor" translatable="false">Robert Webb, 1985</string>
     <string name="din43_inventor" translatable="false">Robert Webb, 1985</string>
 
