commit 758729b59e417e3d8dbe104dd320f6ebf43421e6
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Jun 5 13:34:16 2020 +0100

    Progres with SingleMesh; bugfix in MeshBase.apply(Matrix)

diff --git a/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java b/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
index 07b8a03..a9c201b 100644
--- a/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
+++ b/src/main/java/org/distorted/examples/singlemesh/SingleMeshRenderer.java
@@ -25,10 +25,13 @@ import android.graphics.Paint;
 import android.opengl.GLSurfaceView;
 
 import org.distorted.library.effect.EffectType;
+import org.distorted.library.effect.MatrixEffectMove;
 import org.distorted.library.effect.MatrixEffectQuaternion;
 import org.distorted.library.effect.MatrixEffectScale;
+import org.distorted.library.effect.VertexEffectDeform;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
+import org.distorted.library.effect.VertexEffectSink;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedLibrary;
 import org.distorted.library.main.DistortedScreen;
@@ -49,6 +52,27 @@ import javax.microedition.khronos.opengles.GL10;
 
 class SingleMeshRenderer implements GLSurfaceView.Renderer
 {
+    private static final float DIST = 0.5f;
+
+    private static final int[] FACE_COLORS = new int[]
+         {
+           0xffffff00, 0xffffffff,   // (right-YELLOW) (left  -WHITE)
+           0xff0000ff, 0xff00ff00,   // (top  -BLUE  ) (bottom-GREEN)
+           0xffff0000, 0xffb5651d    // (front-RED   ) (back  -BROWN)
+         };
+
+    private static final Static3D[] CUBIT_MOVES = new Static3D[]
+         {
+           new Static3D(-DIST,-DIST,-DIST),
+           new Static3D(-DIST,-DIST,+DIST),
+           new Static3D(-DIST,+DIST,-DIST),
+           new Static3D(-DIST,+DIST,+DIST),
+           new Static3D(+DIST,-DIST,-DIST),
+           new Static3D(+DIST,-DIST,+DIST),
+           new Static3D(+DIST,+DIST,-DIST),
+           new Static3D(+DIST,+DIST,+DIST),
+         };
+
     private GLSurfaceView mView;
     private DistortedTexture mTexture;
     private DistortedScreen mScreen;
@@ -131,7 +155,7 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer
       mScreen.detachAll();
       mScreen.attach(mTexture,mEffects,mMesh);
 
-      DistortedLibrary.setMax(EffectType.VERTEX, 11);
+      DistortedLibrary.setMax(EffectType.VERTEX, 15);
       VertexEffectRotate.enable();
 
       try
@@ -157,85 +181,150 @@ class SingleMeshRenderer implements GLSurfaceView.Renderer
 
     private Bitmap createTexture()
       {
-      final int[] FACE_COLORS = new int[] { 0xffff0000, 0xff00ff00 };
-      final int FACES=FACE_COLORS.length;
-      int SIZE = 200;
+      final int NUM_FACES = 6;
+      final int TEXTURE_HEIGHT = 200;
+      final int INTERIOR_COLOR = 0xff000000;
+      final float R = TEXTURE_HEIGHT*0.10f;
+      final float M = TEXTURE_HEIGHT*0.05f;
 
-      Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888);
-      Canvas canvas = new Canvas(result);
+      Bitmap bitmap;
       Paint paint = new Paint();
+      bitmap = Bitmap.createBitmap( (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
+      Canvas canvas = new Canvas(bitmap);
+
+      paint.setAntiAlias(true);
+      paint.setTextAlign(Paint.Align.CENTER);
       paint.setStyle(Paint.Style.FILL);
 
-      for(int i=0; i<FACES; i++)
+      paint.setColor(INTERIOR_COLOR);
+      canvas.drawRect(0, 0, (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
+
+      for(int i=0; i<NUM_FACES; i++)
         {
         paint.setColor(FACE_COLORS[i]);
-        canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint);
+        canvas.drawRoundRect( i*TEXTURE_HEIGHT+M, M, (i+1)*TEXTURE_HEIGHT-M, TEXTURE_HEIGHT-M, R, R, paint);
         }
 
-      return result;
+      return bitmap;
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private MeshBase createMesh()
+     MeshBase createCubitMesh()
       {
-      final int MESHES=2;
-
+      final int MESHES=6;
+      int association = 1;
       MeshBase[] meshes = new MeshRectangles[MESHES];
-
-      meshes[0] = new MeshRectangles(1,1);
-      meshes[0].setEffectAssociation(0,1,0);
+      meshes[0] = new MeshRectangles(10,10);
+      meshes[0].setEffectAssociation(0,association,0);
 
       for(int i=1; i<MESHES; i++)
         {
+        association <<=1;
         meshes[i] = meshes[0].copy(true);
-        meshes[i].setEffectAssociation(0,1,i);
+        meshes[i].setEffectAssociation(0,association,0);
         }
 
-      Static4D[] lTextureMaps = new Static4D[MESHES];
-      Static4D[] rTextureMaps = new Static4D[MESHES];
-
-      for(int i=0; i<MESHES; i++)
-        {
-        lTextureMaps[i] = new Static4D(0.0f,0.0f,0.5f,1.0f);
-        rTextureMaps[i] = new Static4D(0.5f,0.0f,0.5f,1.0f);
-        }
-
-      MeshBase[] tmp = new MeshBase[2];
-
-      tmp[0] = new MeshJoined(meshes);
-      tmp[0].setTextureMap(lTextureMaps);
-
-      VertexEffectMove   effect0 = new VertexEffectMove  ( new Static3D(0,0,0.5f) );
-      VertexEffectRotate effect1 = new VertexEffectRotate( new Static1D(180), new Static3D(1,0,0), new Static3D(0,0,0) );
-
-      effect0.setMeshAssociation(1,0);  // apply only to Components whose andAssoc has the least significant bit set, i.e.
-                                        // to both meshes[0] and meshes[1]
-      effect1.setMeshAssociation(0,1);  // apply only to Components whose equAssoc is equal to 1, i.e. only to mesh[1]
-
-      tmp[0].apply(effect0);
-      tmp[0].apply(effect1);
-
-      tmp[1] = tmp[0].copy(true);
-      tmp[1].setTextureMap(rTextureMaps);
+      MeshBase mesh = new MeshJoined(meshes);
+
+      Static3D axisY   = new Static3D(0,1,0);
+      Static3D axisX   = new Static3D(1,0,0);
+      Static3D center  = new Static3D(0,0,0);
+      Static1D angle90 = new Static1D(90);
+      Static1D angle180= new Static1D(180);
+      Static1D angle270= new Static1D(270);
+
+      float d1 = 1.0f;
+      float d2 =-0.05f;
+      float d3 = 0.12f;
+
+      Static3D dCen0 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(+0.5f) );
+      Static3D dCen1 = new Static3D( d1*(+0.5f), d1*(+0.5f), d1*(-0.5f) );
+      Static3D dCen2 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(+0.5f) );
+      Static3D dCen3 = new Static3D( d1*(+0.5f), d1*(-0.5f), d1*(-0.5f) );
+      Static3D dCen4 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(+0.5f) );
+      Static3D dCen5 = new Static3D( d1*(-0.5f), d1*(+0.5f), d1*(-0.5f) );
+      Static3D dCen6 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(+0.5f) );
+      Static3D dCen7 = new Static3D( d1*(-0.5f), d1*(-0.5f), d1*(-0.5f) );
+
+      Static3D dVec0 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(+0.5f) );
+      Static3D dVec1 = new Static3D( d2*(+0.5f), d2*(+0.5f), d2*(-0.5f) );
+      Static3D dVec2 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(+0.5f) );
+      Static3D dVec3 = new Static3D( d2*(+0.5f), d2*(-0.5f), d2*(-0.5f) );
+      Static3D dVec4 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(+0.5f) );
+      Static3D dVec5 = new Static3D( d2*(-0.5f), d2*(+0.5f), d2*(-0.5f) );
+      Static3D dVec6 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(+0.5f) );
+      Static3D dVec7 = new Static3D( d2*(-0.5f), d2*(-0.5f), d2*(-0.5f) );
+
+      Static4D dReg  = new Static4D(0,0,0,d3);
+      Static1D dRad  = new Static1D(1);
+
+      VertexEffectMove   effect0 = new VertexEffectMove(new Static3D(0,0,+0.5f));
+      effect0.setMeshAssociation(63,-1);  // all 6 sides
+      VertexEffectRotate effect1 = new VertexEffectRotate( angle180, axisX, center );
+      effect1.setMeshAssociation(32,-1);  // back
+      VertexEffectRotate effect2 = new VertexEffectRotate( angle90 , axisX, center );
+      effect2.setMeshAssociation( 8,-1);  // bottom
+      VertexEffectRotate effect3 = new VertexEffectRotate( angle270, axisX, center );
+      effect3.setMeshAssociation( 4,-1);  // top
+      VertexEffectRotate effect4 = new VertexEffectRotate( angle270, axisY, center );
+      effect4.setMeshAssociation( 2,-1);  // left
+      VertexEffectRotate effect5 = new VertexEffectRotate( angle90 , axisY, center );
+      effect5.setMeshAssociation( 1,-1);  // right
+
+      VertexEffectDeform effect6 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
+      VertexEffectDeform effect7 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
+      VertexEffectDeform effect8 = new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
+      VertexEffectDeform effect9 = new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
+      VertexEffectDeform effect10= new VertexEffectDeform(dVec4, dRad, dCen4, dReg);
+      VertexEffectDeform effect11= new VertexEffectDeform(dVec5, dRad, dCen5, dReg);
+      VertexEffectDeform effect12= new VertexEffectDeform(dVec6, dRad, dCen6, dReg);
+      VertexEffectDeform effect13= new VertexEffectDeform(dVec7, dRad, dCen7, dReg);
+
+      VertexEffectSink effect14= new VertexEffectSink( new Static1D(1.5f), center, new Static4D(0,0,0,0.72f) );
+
+      mesh.apply(effect0);
+      mesh.apply(effect1);
+      mesh.apply(effect2);
+      mesh.apply(effect3);
+      mesh.apply(effect4);
+      mesh.apply(effect5);
+      mesh.apply(effect6);
+      mesh.apply(effect7);
+      mesh.apply(effect8);
+      mesh.apply(effect9);
+      mesh.apply(effect10);
+      mesh.apply(effect11);
+      mesh.apply(effect12);
+      mesh.apply(effect13);
+      mesh.apply(effect14);
+
+      mesh.mergeEffComponents();
+
+      return mesh;
+      }
 
-      tmp[0].mergeEffComponents();
-      tmp[1].mergeEffComponents();
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
-      tmp[0].setEffectAssociation(0,0,0); // set the equAssoc of the 0th (the only) component to 0
-      tmp[1].setEffectAssociation(0,0,1); // set the equAssoc of the 0th (the only) component to 1
+    private MeshBase createMesh()
+      {
+      final int NUM_CUBITS = CUBIT_MOVES.length;
+      MeshBase[] cubits = new MeshBase[NUM_CUBITS];
 
-      MeshBase combined = new MeshJoined(tmp);
+      cubits[0] = createCubitMesh();
 
-      VertexEffectMove moveL = new VertexEffectMove  ( new Static3D(-0.6f,0,0) );
-      VertexEffectMove moveR = new VertexEffectMove  ( new Static3D(+0.6f,0,0) );
+      for(int i=1; i<NUM_CUBITS; i++)
+        {
+        cubits[i] = cubits[0].copy(true);
+        }
 
-      moveL.setMeshAssociation(0,0);  // apply only to tmp[0]
-      moveR.setMeshAssociation(0,1);  // apply only to tmp[1]
+      for(int i=0; i<NUM_CUBITS; i++)
+        {
+        cubits[i].apply( new MatrixEffectMove(CUBIT_MOVES[i]), 1,0);
+        }
 
-      combined.apply(moveL);
-      combined.apply(moveR);
+      MeshBase result = new MeshJoined(cubits);
 
-      return combined;
+      return result;
       }
 }
