commit bf3b54806702013d1bb20e7c8d4610de1b132d0a
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Sun May 31 12:18:05 2020 +0100

    Progress with Deferred Jobs.

diff --git a/src/main/java/org/distorted/examples/deferredjob/DeferredJobActivity.java b/src/main/java/org/distorted/examples/deferredjob/DeferredJobActivity.java
index 6318f8c..44b4b7b 100644
--- a/src/main/java/org/distorted/examples/deferredjob/DeferredJobActivity.java
+++ b/src/main/java/org/distorted/examples/deferredjob/DeferredJobActivity.java
@@ -23,6 +23,7 @@ import android.app.Activity;
 import android.opengl.GLSurfaceView;
 import android.os.Bundle;
 import android.view.View;
+import android.widget.Button;
 import android.widget.CheckBox;
 
 import org.distorted.examples.R;
@@ -73,17 +74,14 @@ public class DeferredJobActivity extends Activity
 
     public void onClick(View view)
       {
-      CheckBox box = (CheckBox)view;
-      int id = box.getId();
-      boolean checked = box.isChecked();
+      Button butt = (Button)view;
+      int id = butt.getId();
       DeferredJobSurfaceView sView = findViewById(R.id.deferredjobSurfaceView);
 
       switch(id)
         {
-        case R.id.deferredjobCheckBox0  : sView.getRenderer().setChecked(0,checked); break;
-        case R.id.deferredjobCheckBox1  : sView.getRenderer().setChecked(1,checked); break;
-        case R.id.deferredjobCheckBox2  : sView.getRenderer().setChecked(2,checked); break;
-        case R.id.deferredjobCheckBox3  : sView.getRenderer().setChecked(3,checked); break;
+        case R.id.deferredjobButton0 : sView.getRenderer().apply(0); break;
+        case R.id.deferredjobButton1 : sView.getRenderer().apply(1); break;
         }
       }
 }
diff --git a/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java b/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java
index 46aa0b2..193d386 100644
--- a/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java
+++ b/src/main/java/org/distorted/examples/deferredjob/DeferredJobRenderer.java
@@ -31,13 +31,13 @@ import org.distorted.library.effect.VertexEffectDeform;
 import org.distorted.library.effect.VertexEffectMove;
 import org.distorted.library.effect.VertexEffectRotate;
 import org.distorted.library.effect.VertexEffectScale;
-import org.distorted.library.effect.VertexEffectSink;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedLibrary;
 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;
@@ -58,8 +58,9 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
     private DistortedEffects mEffects;
     private Static3D mScale;
     private MeshBase mMesh;
-    private int mSinkAssociation;
-    private VertexEffectSink mSink;
+    private VertexEffectRotate mRotate;
+    private Dynamic1D mAngleDyn;
+    private Static1D mAngle;
 
     Static4D mQuat1, mQuat2;
     int mScreenMin;
@@ -86,15 +87,19 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
       quatInt1.add(mQuat1);
       quatInt2.add(mQuat2);
 
-      mSinkAssociation = 0;
-      mSink = new VertexEffectSink( sink, center, new Static4D(0,0,0,0.75f) );
-      mSink.setMeshAssociation(-1,mSinkAssociation);
+      mAngle = new Static1D(0);
+
+      mAngleDyn = new Dynamic1D(2000,0.5f);
+      mAngleDyn.add(new Static1D(0));
+      mAngleDyn.add( mAngle );
+
+      mRotate = new VertexEffectRotate( mAngleDyn, new Static3D(1,0,0), new Static3D(0,0,0) );
 
       mEffects = new DistortedEffects();
+      mEffects.apply( mRotate );
       mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
       mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
       mEffects.apply( new MatrixEffectScale(mScale));
-      mEffects.apply( mSink );
 
       mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
       }
@@ -110,7 +115,7 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
     
     public void onSurfaceChanged(GL10 glUnused, int width, int height) 
       {
-      final float SCALE = 0.7f;
+      final float SCALE = 0.5f;
       mScreenMin = Math.min(width, height);
       float factor = SCALE*mScreenMin;
       mScale.set(factor,factor,factor);
@@ -122,15 +127,15 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
     public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
       {
       if( mTexture==null ) mTexture = new DistortedTexture();
-      mTexture.setTexture( createTetrahedronTexture() );
+      mTexture.setTexture( createTexture() );
 
-      if( mMesh==null ) mMesh = createJoinedTetrahedron();
+      if( mMesh==null ) mMesh = createMesh();
 
       mScreen.detachAll();
       mScreen.attach(mTexture,mEffects,mMesh);
 
       DistortedLibrary.setMax(EffectType.VERTEX, 11);
-      VertexEffectSink.enable();
+      VertexEffectRotate.enable();
 
       try
         {
@@ -138,63 +143,35 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
         }
       catch(Exception ex)
         {
-        android.util.Log.e("MeshJoin", ex.getMessage() );
+        android.util.Log.e("DeferredJob", ex.getMessage() );
         }
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    void setChecked(int number, boolean checked)
+    void apply(int number)
       {
-      int n = (0x1 << number);
-
-      if( checked ) mSinkAssociation |= n;
-      else          mSinkAssociation &= (15-n);
-
-      mSink.setMeshAssociation(-1,mSinkAssociation);
+      mAngle.set(360);
+      mAngleDyn.resetToBeginning();
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private Bitmap createTetrahedronTexture()
+    private Bitmap createTexture()
       {
-      final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
+      final int[] FACE_COLORS = new int[] { 0xffff0000, 0xff00ff00 };
       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);
+      paint.setStyle(Paint.Style.FILL);
 
       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;
@@ -202,87 +179,31 @@ class DeferredJobRenderer implements GLSurfaceView.Renderer
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-    private MeshBase createJoinedTetrahedron()
+    private MeshBase createMesh()
       {
-      final float SQ2 = (float)Math.sqrt(2);
-      final float SQ3 = (float)Math.sqrt(3);
-      final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
-      final int MESHES=4;
+      final int MESHES=2;
 
-      int association = 1;
-      MeshBase[] meshes = new MeshTriangles[MESHES];
+      MeshBase[] meshes = new MeshRectangles[MESHES];
 
-      for(int i=0; i<MESHES; i++)
+      meshes[0] = new MeshRectangles(2,2);
+
+      for(int i=1; i<MESHES; i++)
         {
-        meshes[i] = new MeshTriangles(5);
-        meshes[i].setEffectAssociation(0,association);
-        association <<= 1;
+        meshes[i] = meshes[0].copy(true);
         }
 
       Static4D[] textureMaps = new Static4D[MESHES];
-      for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.25f,0.0f,0.25f,1.0f);
+      for(int i=0; i<MESHES; i++) textureMaps[i] = new Static4D(i*0.5f,0.0f,0.5f,1.0f);
       MeshBase result = new MeshJoined(meshes);
       result.setTextureMap(textureMaps);
 
-      Static3D a0 = new Static3D(         0,        1,       0 );
-      Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
-      Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
-      Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
-
-      float tetraHeight = SQ2*SQ3/3;
-      float d1 = 0.75f*tetraHeight;
-      float d2 =-0.10f*tetraHeight;
-      float d3 = 0.20f*tetraHeight;
-
-      Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
-      Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
-      Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
-      Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
-
-      Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
-      Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
-      Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
-      Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
-
-      Static4D dReg  = new Static4D(0,0,0,d3);
-      Static1D dRad  = new Static1D(1);
-
-      Static1D angle  = new Static1D(angleFaces);
-      Static3D axis1  = new Static3D(  -1, 0,      0);
-      Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
-      Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
-      Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
-      Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
-
-      VertexEffectScale   effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
-      VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
-      VertexEffectMove    effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
-      VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
-      VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
-      VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
-      VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
-
-      VertexEffectDeform effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
-      VertexEffectDeform effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
-      VertexEffectDeform effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
-      VertexEffectDeform effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
-
-      effect4.setMeshAssociation(-1,14);  // apply to mesh[1], [2] and [3]
-      effect5.setMeshAssociation(-1, 2);  // apply only to mesh[1]
-      effect6.setMeshAssociation(-1, 4);  // apply only to mesh[2]
-      effect7.setMeshAssociation(-1, 8);  // apply only to mesh[3]
+      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) );
+
+      effect1.setMeshAssociation(1,0);  // apply only to mesh[1]
 
+      result.apply(effect0);
       result.apply(effect1);
-      result.apply(effect2);
-      result.apply(effect3);
-      result.apply(effect4);
-      result.apply(effect5);
-      result.apply(effect6);
-      result.apply(effect7);
-      result.apply(effect8);
-      result.apply(effect9);
-      result.apply(effect10);
-      result.apply(effect11);
 
       return result;
       }
diff --git a/src/main/res/layout/deferredjoblayout.xml b/src/main/res/layout/deferredjoblayout.xml
index 3f5e65d..be1a131 100644
--- a/src/main/res/layout/deferredjoblayout.xml
+++ b/src/main/res/layout/deferredjoblayout.xml
@@ -10,50 +10,25 @@
         android:layout_height="0dp"
         android:layout_weight="1" />
 
-    <TextView
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center"
-        android:text="@string/association"
-        android:textAppearance="?android:attr/textAppearanceMedium" />
-
     <LinearLayout
         android:orientation="horizontal"
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
 
-        <CheckBox
+        <Button
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:id="@+id/deferredjobCheckBox0"
-            android:text="@string/color_yellow"
+            android:id="@+id/deferredjobButton0"
+            android:text="@string/color_red"
             android:onClick="onClick"
-            android:layout_weight="1"
-            android:checked="false"/>
-        <CheckBox
+            android:layout_weight="1"/>
+        <Button
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
-            android:id="@+id/deferredjobCheckBox1"
+            android:id="@+id/deferredjobButton1"
             android:text="@string/color_green"
             android:onClick="onClick"
-            android:layout_weight="1"
-            android:checked="false"/>
-        <CheckBox
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:id="@+id/deferredjobCheckBox2"
-            android:text="@string/color_blue"
-            android:onClick="onClick"
-            android:layout_weight="1"
-            android:checked="false"/>
-        <CheckBox
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:id="@+id/deferredjobCheckBox3"
-            android:text="@string/color_red"
-            android:onClick="onClick"
-            android:layout_weight="1"
-            android:checked="false"/>
+            android:layout_weight="1"/>
 
     </LinearLayout>
 
