commit 63fb0859e566c81f73571385a97390c9f21ab481
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Dec 11 22:25:02 2020 +0100

    Fixes for the Rex Cube (mostly works now)

diff --git a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
index e0663bd..0edff64 100644
--- a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
+++ b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
@@ -196,21 +196,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;
@@ -610,10 +609,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;
@@ -623,20 +621,20 @@ 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[] 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);
@@ -655,26 +653,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++)
@@ -685,7 +682,7 @@ 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[] 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);
@@ -700,47 +697,62 @@ class FactoryCubit
 
   MeshBase createFacesRexEdge()
     {
-    MeshBase[] meshes = new MeshBase[4];
+    MeshBase[] meshes = new MeshBase[1];
 
     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*H;
 
     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;
-
-    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
-    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
+    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;
+
+/*
+    vertices[0] = V1x;
+    vertices[1] = V1y;
+    vertices[2] = V2x;
+    vertices[3] = V2y;
+    vertices[4] = +D;
+    vertices[5] = +F-REX_D;
+    vertices[6] = +D;
+    vertices[7] = +F;
+    vertices[8] = -D;
+    vertices[9] = +F;
+*/
+    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);
+ /*
     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);
     }
 
