commit 7cd30f7c9c7b808c342b2aaddd0dd2c90110c2ba
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Dec 11 11:28:01 2020 +0100

    Fixes for the Rex Cube (still doesn't work)

diff --git a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
index f069e82..e0663bd 100644
--- a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
+++ b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
@@ -43,6 +43,8 @@ class FactoryCubit
   private static final int   IVY_N = 8;
   private static final float IVY_C = 0.59f;
   private static final float IVY_M = 0.35f;
+  private static final float REX_D = 0.03f;
+  private static final int   REX_N = 5;
 
   private static final Static1D RADIUS = new Static1D(1);
 
@@ -193,6 +195,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)
@@ -579,6 +602,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.00f,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.00f,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.00f,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
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1006,6 +1171,48 @@ 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,   -F, 0.0f);
+    Static3D center= new Static3D(0.0f, 0.0f, 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 VertexEffectMove(move);
+    effect[1] = new VertexEffectRotate(angle180, axisY, center);
+    effect[2] = new VertexEffectRotate(angle90 , axisX, center);
+
+    effect[1].setMeshAssociation(10,-1);  // meshes 1 & 3
+    effect[2].setMeshAssociation(10,-1);  // meshes 1 & 3
+
+    return effect;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  VertexEffect[] createVertexEffectsRexCorner()
+    {
+    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[1];
+    effect[0] = new VertexEffectRotate(angle, axisZ, center);
+
+    return effect;
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // OBJECTS
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1299,6 +1506,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/examples/meshfile/MeshFileRenderer.java b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
index cbfad70..65a58d2 100644
--- a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
+++ b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
@@ -331,7 +331,7 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
     private void createMesh()
       {
       FactoryCubit factory = FactoryCubit.getInstance();
-      mMesh = factory.createIvyCornerMesh();
+      mMesh = factory.createRexEdgeMesh();
 
       //mMesh = createStaticMesh();
 
