commit 37b324c4faae92bfdca12142938818acb688fbaf
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Jun 9 16:39:26 2017 +0100

    Further progress with Apps.

diff --git a/src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java b/src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java
index 8cef2b8..78ff348 100644
--- a/src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java
+++ b/src/main/java/org/distorted/examples/aroundtheworld/AroundTheWorldRenderer.java
@@ -51,7 +51,6 @@ class AroundTheWorldRenderer implements GLSurfaceView.Renderer
    private MeshFlat mMesh;
    private AroundTheWorldEffectsManager mManager;
    private int mObjWidth, mObjHeight;
-
    private Static3D mMove, mScale;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/examples/check/CheckRenderer.java b/src/main/java/org/distorted/examples/check/CheckRenderer.java
index cfb0764..3730dea 100644
--- a/src/main/java/org/distorted/examples/check/CheckRenderer.java
+++ b/src/main/java/org/distorted/examples/check/CheckRenderer.java
@@ -27,13 +27,17 @@ import javax.microedition.khronos.opengles.GL10;
 
 import org.distorted.examples.R;
 
+import org.distorted.library.effect.EffectName;
+import org.distorted.library.effect.FragmentEffectChroma;
+import org.distorted.library.effect.MatrixEffectMove;
+import org.distorted.library.effect.MatrixEffectScale;
+import org.distorted.library.effect.VertexEffectDeform;
+import org.distorted.library.effect.VertexEffectSwirl;
 import org.distorted.library.main.Distorted;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedScreen;
 import org.distorted.library.main.DistortedTexture;
-import org.distorted.library.EffectNames;
 import org.distorted.library.main.MeshFlat;
-import org.distorted.library.EffectTypes;
 import org.distorted.library.type.Dynamic3D;
 import org.distorted.library.type.Static1D;
 import org.distorted.library.type.Static3D;
@@ -61,19 +65,69 @@ class CheckRenderer implements GLSurfaceView.Renderer
     private DistortedTexture mTexture;
     private MeshFlat mMesh;
     private DistortedScreen mScreen;
-    private int bmpHeight, bmpWidth;
+    private int mObjHeight, mObjWidth;
+    private Static3D mMove, mScale;
+    private Static3D mSwirl1, mSwirl2, mDeform1, mDeform2;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
     CheckRenderer(GLSurfaceView view)
       { 
       mView = view;
-      mEffects = new DistortedEffects();
 
       CheckActivity act = (CheckActivity)mView.getContext();
 
       DistortedEffects.setMaxVertex(act.getMaxV());
       DistortedEffects.setMaxFragment(act.getMaxF());
+      DistortedEffects.enableEffect(EffectName.SWIRL);
+      DistortedEffects.enableEffect(EffectName.DEFORM);
+      DistortedEffects.enableEffect(EffectName.CHROMA);
+
+      mSwirl1 = new Static3D(0,0,0);
+      mSwirl2 = new Static3D(0,0,0);
+      mDeform1= new Static3D(0,0,0);
+      mDeform2= new Static3D(0,0,0);
+
+      mMove = new Static3D(0,0,0);
+      mScale= new Static3D(1,1,1);
+      mEffects = new DistortedEffects();
+      mEffects.apply(new MatrixEffectMove(mMove));
+      mEffects.apply(new MatrixEffectScale(mScale));
+
+      // Try adding 2 Vertex Effects to the Bitmap.
+      // This will fail if we have set maxVertexEffects to something < 2.
+      //
+      // Even if adding some of the Effects fails, the App will still start - you just won't see
+      // the effects that failed to add.
+
+      Dynamic3D dSwirl = new Dynamic3D(2000,0.0f);
+      dSwirl.add(mSwirl1);
+      dSwirl.add(mSwirl2);
+
+      if( !mEffects.apply( new VertexEffectSwirl(new Static1D(30), dSwirl, new Static4D( 0,0,40,40)) ) )
+        {
+        Log.e("Check", "Failed to add Swirl effect!");
+        }
+
+      Dynamic3D dDeform = new Dynamic3D(2000,0.0f);
+      dDeform.add(mDeform1);
+      dDeform.add(mDeform2);
+
+      if( !mEffects.apply( new VertexEffectDeform(dDeform, new Static3D(mObjWidth/2,0,0)) ) )
+        {
+        Log.e("Check", "Failed to add Deform effect!");
+        }
+
+      // Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
+      Static3D color = new Static3D(1,0,0);
+      Dynamic1D inter = new Dynamic1D(2000,0.0f);
+      inter.add(new Static1D(0));
+      inter.add(new Static1D(1));
+
+      if( !mEffects.apply( new FragmentEffectChroma(inter, color) ) )
+        {
+        Log.e("Check", "Failed to add Chroma effect!");
+        }
 
       mScreen = new DistortedScreen(mView);
       }
@@ -89,26 +143,22 @@ class CheckRenderer implements GLSurfaceView.Renderer
     
     public void onSurfaceChanged(GL10 glUnused, int width, int height) 
       { 
-      mEffects.abortEffects(EffectTypes.MATRIX);
-      
-      if( (float)bmpHeight/bmpWidth > (float)height/width )
+      if( (float)mObjHeight/mObjWidth > (float)height/width )
         {
-        int w = (height*bmpWidth)/bmpHeight;
-        float factor = (float)height/bmpHeight;
-
-        mEffects.move( new Static3D((width-w)/2,0,0) );
-        mEffects.scale(factor);
+        int w = (height*mObjWidth)/mObjHeight;
+        float factor = (float)height/mObjHeight;
+        mMove.set((width-w)/2,0,0);
+        mScale.set(factor,factor,factor);
         }
       else
         {
-        int h = (width*bmpHeight)/bmpWidth;
-        float factor = (float)width/bmpWidth;
-
-        mEffects.move( new Static3D(0,(height-h)/2,0) );
-        mEffects.scale(factor);
+        int h = (width*mObjHeight)/mObjWidth;
+        float factor = (float)width/mObjWidth;
+        mMove.set(0,(height-h)/2,0);
+        mScale.set(factor,factor,factor);
         }
-      
-      mScreen.resize(width, height);
+
+      mScreen.resize(width,height);
       }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -131,64 +181,21 @@ class CheckRenderer implements GLSurfaceView.Renderer
         catch(IOException e) { }
         }
 
-      bmpHeight = bitmap.getHeight();
-      bmpWidth  = bitmap.getWidth();
+      mObjHeight = bitmap.getHeight();
+      mObjWidth  = bitmap.getWidth();
 
-      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
+      if( mTexture==null ) mTexture = new DistortedTexture(mObjWidth,mObjHeight);
       mTexture.setTexture(bitmap);
 
-      if( mMesh==null ) mMesh = new MeshFlat(30,30*bmpHeight/bmpWidth);
+      if( mMesh==null ) mMesh = new MeshFlat(30,30*mObjHeight/mObjWidth);
 
       mScreen.detachAll();
       mScreen.attach(mTexture,mEffects,mMesh);
 
-      mEffects.abortEffects(EffectTypes.VERTEX);
-      mEffects.abortEffects(EffectTypes.FRAGMENT);
-
-      // Try adding 2 Vertex Effects to the Bitmap.
-      // This will fail if we have set maxVertexEffects to something < 2.
-      //
-      // Even if adding some of the Effects fails, the App will still start - you just won't see
-      // the effects that failed to add.
-
-      Dynamic3D dSwirl = new Dynamic3D(2000,0.0f);
-      dSwirl.add(new Static3D(        0, bmpHeight/2, 0));
-      dSwirl.add(new Static3D( bmpWidth, bmpHeight/2, 0));
-
-      long swirlEffectID = mEffects.swirl( new Static1D(30), dSwirl, new Static4D( 0,0,40,40) );
-
-      if( swirlEffectID<0 )
-        {
-        Log.e("Check", "Failed to add Swirl effect!");
-        }
-
-      Dynamic3D dDeform = new Dynamic3D(2000,0.0f);
-      dDeform.add(new Static3D( 0,         0,0));
-      dDeform.add(new Static3D( 0,-bmpHeight,0));
-
-      long deformEffectID = mEffects.deform(dDeform, new Static3D(bmpWidth/2,0,0) );
-
-      if( deformEffectID<0 )
-        {
-        Log.e("Check", "Failed to add Deform effect!");
-        }
-
-      // Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
-      Static3D color = new Static3D(1,0,0);
-      Dynamic1D inter = new Dynamic1D(2000,0.0f);
-      inter.add(new Static1D(0));
-      inter.add(new Static1D(1));
-
-      long chromaEffectID = mEffects.chroma(inter, color);
-
-      if( chromaEffectID<0 )
-        {
-        Log.e("Check", "Failed to add Chroma effect!");
-        }
-
-      DistortedEffects.enableEffect(EffectNames.SWIRL);
-      DistortedEffects.enableEffect(EffectNames.DEFORM);
-      DistortedEffects.enableEffect(EffectNames.CHROMA);
+      mSwirl1.set (        0, mObjHeight/2, 0);
+      mSwirl2.set (mObjWidth, mObjHeight/2, 0);
+      mDeform1.set(        0,         0   , 0);
+      mDeform2.set(        0,-mObjHeight  , 0);
 
       try
         {
diff --git a/src/main/java/org/distorted/examples/cubes/CubesRenderer.java b/src/main/java/org/distorted/examples/cubes/CubesRenderer.java
index d0724c3..751afd9 100644
--- a/src/main/java/org/distorted/examples/cubes/CubesRenderer.java
+++ b/src/main/java/org/distorted/examples/cubes/CubesRenderer.java
@@ -27,11 +27,13 @@ import javax.microedition.khronos.opengles.GL10;
 
 import org.distorted.examples.R;
 
+import org.distorted.library.effect.MatrixEffectMove;
+import org.distorted.library.effect.MatrixEffectQuaternion;
+import org.distorted.library.effect.MatrixEffectScale;
 import org.distorted.library.main.DistortedEffects;
 import org.distorted.library.main.DistortedScreen;
 import org.distorted.library.main.DistortedTexture;
 import org.distorted.library.main.MeshObject;
-import org.distorted.library.EffectTypes;
 import org.distorted.library.type.DynamicQuat;
 import org.distorted.library.type.Static4D;
 import org.distorted.library.type.Static3D;
@@ -50,8 +52,8 @@ class CubesRenderer implements GLSurfaceView.Renderer
     private DistortedEffects mEffects;
     private MeshObject mMesh;
     private DistortedScreen mScreen;
-    private DynamicQuat mQuatInt1, mQuatInt2;
     private int mObjWidth, mObjHeight, mObjDepth;
+    private Static3D mMove, mScale, mCenter;
 
     Static4D mQuat1, mQuat2;
     int mScreenMin;
@@ -62,9 +64,12 @@ class CubesRenderer implements GLSurfaceView.Renderer
       {
       mView = v;
 
+      mMove = new Static3D(0,0,0);
+      mScale= new Static3D(1,1,1);
+      mCenter=new Static3D(0,0,0);
+
       CubesActivity act = (CubesActivity)v.getContext();
 
-      mEffects = new DistortedEffects();
       mTexture = act.getTexture();
       mMesh = act.getMesh();
 
@@ -75,11 +80,17 @@ class CubesRenderer implements GLSurfaceView.Renderer
       mQuat1 = new Static4D(0,0,0,1);  // unity
       mQuat2 = new Static4D(0,0,0,1);  // quaternions
       
-      mQuatInt1 = new DynamicQuat(0,0.5f);
-      mQuatInt2 = new DynamicQuat(0,0.5f);
+      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
+      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
+
+      quatInt1.add(mQuat1);
+      quatInt2.add(mQuat2);
 
-      mQuatInt1.add(mQuat1);
-      mQuatInt2.add(mQuat2);
+      mEffects = new DistortedEffects();
+      mEffects.apply( new MatrixEffectMove(mMove) );
+      mEffects.apply( new MatrixEffectScale(mScale));
+      mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
+      mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
 
       mScreen = new DistortedScreen(mView);
       }
@@ -96,26 +107,10 @@ class CubesRenderer implements GLSurfaceView.Renderer
     public void onSurfaceChanged(GL10 glUnused, int width, int height) 
       {
       mScreenMin = width<height ? width:height;
-    	
-      mEffects.abortEffects(EffectTypes.MATRIX);
-      float factor;
-
-      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
-        {
-        factor = (0.75f*height)/mObjHeight;
-        }
-      else
-        {
-        factor = (0.75f*width)/mObjWidth;
-        }
-
-      mEffects.move( new Static3D( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0) );
-      mEffects.scale(factor);
-      Static3D center = new Static3D( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
-
-      mEffects.quaternion(mQuatInt1, center);
-      mEffects.quaternion(mQuatInt2, center);
-       
+      float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.75f*height)/mObjHeight :  (0.75f*width)/mObjWidth;
+      mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
+      mScale.set(factor,factor,factor);
+      mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
       mScreen.resize(width, height);
       }
 
