commit ba98444446834d99d6e6734109f1bac009960751
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun Jun 7 14:41:46 2020 +0100

    Bugfix and new debugging methods in MeshBase
    DeferredJob app rewritten to show the (just fixed) bug

diff --git a/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java b/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java
index 8730ea8..05b71b7 100644
--- a/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java
+++ b/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java
@@ -25,9 +25,9 @@ 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.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedLibrary;
@@ -35,7 +35,7 @@ import org.distorted.library.main.DistortedScreen;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.mesh.MeshBase;
 import org.distorted.library.mesh.MeshJoined;
-import org.distorted.library.mesh.MeshRectangles;
+import org.distorted.library.mesh.MeshTriangles;
 import org.distorted.library.type.Dynamic1D;
 import org.distorted.library.type.DynamicQuat;
 import org.distorted.library.type.Static1D;
@@ -153,37 +153,16 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
       mAngleDyn.resetToBeginning();
       }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-    private Bitmap createTexture()
-      {
-      final int[] FACE_COLORS = new int[] { 0xffff0000, 0xff00ff00 };
-      final int FACES=FACE_COLORS.length;
-      int SIZE = 200;
-
-      Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888);
-      Canvas canvas = new Canvas(result);
-      Paint paint = new Paint();
-      paint.setStyle(Paint.Style.FILL);
-
-      for(int i=0; i<FACES; i++)
-        {
-        paint.setColor(FACE_COLORS[i]);
-        canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint);
-        }
-
-      return result;
-      }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     private MeshBase createMesh()
       {
-      final int MESHES=2;
+      final int MESHES=4;
 
-      MeshBase[] meshes = new MeshRectangles[MESHES];
+      MeshBase[] meshes = new MeshTriangles[MESHES];
+      MatrixEffectMove[] moveEffect = new MatrixEffectMove[MESHES];
 
-      meshes[0] = new MeshRectangles(1,1);
+      meshes[0] = new MeshTriangles(1);
       meshes[0].setEffectAssociation(0,1,0);
 
       for(int i=1; i<MESHES; i++)
@@ -192,32 +171,24 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
         meshes[i].setEffectAssociation(0,1,i);
         }
 
-      Static4D[] lTextureMaps = new Static4D[MESHES];
-      Static4D[] rTextureMaps = new Static4D[MESHES];
+      Static4D[] textureMaps = 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);
+        textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f);
         }
 
       MeshBase[] tmp = new MeshBase[2];
 
       tmp[0] = new MeshJoined(meshes);
-      tmp[0].setTextureMap(lTextureMaps,0);
 
-      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);
+      for(int i=0; i<MESHES; i++)
+        {
+        moveEffect[i] = new MatrixEffectMove( new Static3D(0,0,0.5f-i/(MESHES-1.0f)) );
+        tmp[0].apply(moveEffect[i],0,i);
+        }
 
       tmp[1] = tmp[0].copy(true);
-      tmp[1].setTextureMap(rTextureMaps,0);
 
       tmp[0].mergeEffComponents();
       tmp[1].mergeEffComponents();
@@ -227,15 +198,63 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
 
       MeshBase combined = new MeshJoined(tmp);
 
-      VertexEffectMove moveL = new VertexEffectMove  ( new Static3D(-0.6f,0,0) );
-      VertexEffectMove moveR = new VertexEffectMove  ( new Static3D(+0.6f,0,0) );
+      MatrixEffectMove moveL = new MatrixEffectMove( new Static3D(-0.6f,0,0) );
+      MatrixEffectMove moveR = new MatrixEffectMove( new Static3D(+0.6f,0,0) );
+
+      combined.apply(moveL,0,0);
+      combined.apply(moveR,0,1);
 
-      moveL.setMeshAssociation(0,0);  // apply only to tmp[0]
-      moveR.setMeshAssociation(0,1);  // apply only to tmp[1]
+      combined.setTextureMap(textureMaps,0);
+      combined.setTextureMap(textureMaps,MESHES);
 
-      combined.apply(moveL);
-      combined.apply(moveR);
 
       return combined;
       }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private Bitmap createTexture()
+      {
+      final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
+      final int FACES=FACE_COLORS.length;
+      int SIZE = 200;
+      float STROKE = 0.05f*SIZE;
+      float OFF = STROKE/2 -1;
+      float OFF2 = 0.5f*SIZE + OFF;
+      float HEIGHT = SIZE - OFF;
+      float RADIUS = SIZE/12;
+      float ARC1_H = 0.2f*SIZE;
+      float ARC1_W = SIZE*0.5f;
+      float ARC2_W = 0.153f*SIZE;
+      float ARC2_H = 0.905f*SIZE;
+      float ARC3_W = SIZE-ARC2_W;
+
+      Bitmap result = Bitmap.createBitmap(FACES*SIZE,SIZE, Bitmap.Config.ARGB_8888);
+      Canvas canvas = new Canvas(result);
+      Paint paint = new Paint();
+      paint.setAntiAlias(true);
+      paint.setStrokeWidth(STROKE);
+
+      for(int i=0; i<FACES; i++)
+        {
+        paint.setColor(FACE_COLORS[i]);
+        paint.setStyle(Paint.Style.FILL);
+
+        canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint);
+
+        paint.setColor(0xff000000);
+        paint.setStyle(Paint.Style.STROKE);
+
+        canvas.drawLine(           i*SIZE, HEIGHT,  SIZE       +i*SIZE, HEIGHT, paint);
+        canvas.drawLine(      OFF +i*SIZE,   SIZE,       OFF2  +i*SIZE,      0, paint);
+        canvas.drawLine((SIZE-OFF)+i*SIZE,   SIZE, (SIZE-OFF2) +i*SIZE,      0, paint);
+
+        canvas.drawArc( ARC1_W-RADIUS+i*SIZE, ARC1_H-RADIUS, ARC1_W+RADIUS+i*SIZE, ARC1_H+RADIUS, 225, 90, false, paint);
+        canvas.drawArc( ARC2_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC2_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 105, 90, false, paint);
+        canvas.drawArc( ARC3_W-RADIUS+i*SIZE, ARC2_H-RADIUS, ARC3_W+RADIUS+i*SIZE, ARC2_H+RADIUS, 345, 90, false, paint);
+        }
+
+      return result;
+      }
+
 }
