commit 6a96e571f38c2d3af2dcecade14f7c537652d011
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Apr 12 22:32:53 2021 +0200

    Cubit creation: center the textures. Add octahedron.

diff --git a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
index 8a25210..20ace76 100644
--- a/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
+++ b/src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
@@ -19,7 +19,6 @@
 
 package org.distorted.examples.meshfile;
 
-import org.distorted.library.effect.MatrixEffect;
 import org.distorted.library.effect.MatrixEffectMove;
 import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.effect.MatrixEffectScale;
@@ -50,6 +49,7 @@ class FactoryCubit
   private static class StickerInfo
     {
     double[] vertices;
+    double dx,dy;
     }
 
   private static class FaceInfo
@@ -607,6 +607,50 @@ class FactoryCubit
     return ret;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void centerTextures()
+    {
+    int numStickers = mStickerInfo.size();
+    StickerInfo info;
+
+    for(int sticker=0; sticker<numStickers; sticker++)
+      {
+      double minX = Double.MAX_VALUE;
+      double minY = Double.MAX_VALUE;
+      double maxX =-Double.MAX_VALUE;
+      double maxY =-Double.MAX_VALUE;
+
+      info = mStickerInfo.get(sticker);
+      double[] vert = info.vertices;
+      int numVert = vert.length/2;
+
+      for ( int v=0; v<numVert; v++)
+        {
+        double x = vert[2*v  ];
+        double y = vert[2*v+1];
+
+        if (x < minX) minX = x;
+        if (y < minY) minY = y;
+        if (x > maxX) maxX = x;
+        if (y > maxY) maxY = y;
+        }
+
+      info.dx = info.dy = 0.0;
+
+      if( minX<-0.5 ) info.dx = minX + 0.5;
+      if( minY<-0.5 ) info.dy = minY + 0.5;
+      if( maxX> 0.5 ) info.dx = maxX - 0.5;
+      if( maxY> 0.5 ) info.dy = maxY - 0.5;
+
+      for ( int v=0; v<numVert; v++)
+        {
+        vert[2*v  ] -= info.dx;
+        vert[2*v+1] -= info.dy;
+        }
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   private void prepareFaceInfo( final double[][] vertices, final int[][] indexes)
@@ -632,6 +676,8 @@ class FactoryCubit
 
       mFaceInfo.add(newInfo);
       }
+
+    centerTextures();
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -736,8 +782,6 @@ class FactoryCubit
                               final float[][] bands    , final int[]   bandIndexes,
                               final float[][] corners  , final int[]   cornerIndexes)
     {
-    int EFFECTS_PER_FACE = 3;
-
     prepareFaceInfo(vertices,vertIndexes);
 
     int numFaces = vertIndexes.length;
@@ -765,14 +809,16 @@ class FactoryCubit
       }
 
     MeshBase mesh = new MeshJoined(meshes);
-    MatrixEffect[] effects = new MatrixEffect[EFFECTS_PER_FACE*numFaces];
     Static3D center = new Static3D(0,0,0);
 
     for(int face=0; face<numFaces; face++)
       {
       int assoc = (1<<face);
       fInfo = mFaceInfo.get(face);
+      sInfo = mStickerInfo.get(fInfo.sticker);
 
+      float dx = (float)sInfo.dx;
+      float dy = (float)sInfo.dy;
       float vx = (float)fInfo.vx;
       float vy = (float)fInfo.vy;
       float vz = (float)fInfo.vz;
@@ -782,17 +828,15 @@ class FactoryCubit
       float qz = (float)fInfo.qz;
       float qw = (float)fInfo.qw;
 
+      Static3D move2D= new Static3D(dx,dy,0.0f);
       Static3D move3D= new Static3D(vx,vy,vz);
       Static3D scale = new Static3D(sc,sc, fInfo.flip ? -sc : sc);
       Static4D quat  = new Static4D(qx,qy,qz,qw);
 
-      effects[EFFECTS_PER_FACE*face  ] = new MatrixEffectScale(scale);
-      effects[EFFECTS_PER_FACE*face+1] = new MatrixEffectQuaternion(quat,center);
-      effects[EFFECTS_PER_FACE*face+2] = new MatrixEffectMove(move3D);
-
-      mesh.apply(effects[EFFECTS_PER_FACE*face  ],assoc,-1);
-      mesh.apply(effects[EFFECTS_PER_FACE*face+1],assoc,-1);
-      mesh.apply(effects[EFFECTS_PER_FACE*face+2],assoc,-1);
+      mesh.apply(new MatrixEffectMove(move2D)           ,assoc,-1);
+      mesh.apply(new MatrixEffectScale(scale)           ,assoc,-1);
+      mesh.apply(new MatrixEffectQuaternion(quat,center),assoc,-1);
+      mesh.apply(new MatrixEffectMove(move3D)           ,assoc,-1);
       }
 
     prepareAndRoundCorners(mesh, vertices, vertIndexes, corners, cornerIndexes);
diff --git a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
index 141641c..e4d8216 100644
--- a/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
+++ b/src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
@@ -252,7 +252,7 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
     private void createMesh()
       {
-      int mode = 2;
+      int mode = 0;
       double[][] vertices = null;
       int[][] vertIndexes = null;
       float[][] bands     = null;
@@ -288,7 +288,7 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
         bands = new float[][]
           {
-              {0.05f,45,0.6f,0.5f,5,  2,2}
+              {0.05f,40,0.5f,0.2f,5,  2,2}
           };
 
         bandIndexes = new int[] { 0,0,0,0,0,0 };
@@ -358,8 +358,8 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
 
         bands = new float[][]
           {
-              {0.028f,30,0.166f,0.8f,7,  2,5},
-              {0.028f,30,0.166f,0.8f,7,  1,2}
+              {0.028f,30,0.25f,0.1f,7,  2,5},
+              {0.001f,30,0.25f,0.1f,7,  1,2}
           };
 
         bandIndexes = new int[] { 0,1,1,0 };
@@ -372,6 +372,47 @@ class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.Excep
         cornerIndexes = new int[] { 0,0,0,0 };
         }
 
+      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
+
+      else if( mode==3 )
+        {
+        vertices = new double[][]
+          {
+              { 0.5,   0.0, 0.5},
+              { 0.5,   0.0,-0.5},
+              {-0.5,   0.0,-0.5},
+              {-0.5,   0.0, 0.5},
+              { 0.0, SQ2/2, 0.0},
+              { 0.0,-SQ2/2, 0.0},
+          };
+
+        vertIndexes = new int[][]
+          {
+              {3,0,4},   // counterclockwise!
+              {0,1,4},
+              {1,2,4},
+              {2,3,4},
+              {5,0,3},
+              {5,1,0},
+              {5,2,1},
+              {5,3,2}
+          };
+
+        bands = new float[][]
+          {
+             {0.05f,17,0.5f,0.2f,5,  2,2}
+          };
+
+        bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
+
+        corners = new float[][]
+          {
+              { 0.03f, 0.12f }
+          };
+
+        cornerIndexes = new int[] { 0,0,0,0,0,0 };
+        }
+
       FactoryCubit factory = FactoryCubit.getInstance();
       mMesh = factory.createRoundedSolid(vertices, vertIndexes, bands, bandIndexes, corners, cornerIndexes);
 
