commit 19938eb7e76e004b164589f0ca6eec2894935e08
Author: leszek <leszek@koltunski.pl>
Date:   Mon Apr 24 23:53:43 2017 +0100

    Convert a few more APPs to the new resolution-independent Matrix Effects.

diff --git a/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java b/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
index 2305348..0b994ce 100644
--- a/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
+++ b/src/main/java/org/distorted/examples/mirror/MirrorRenderer.java
@@ -46,15 +46,14 @@ import javax.microedition.khronos.opengles.GL10;
 class MirrorRenderer implements GLSurfaceView.Renderer
 {
    private static final float MIRROR_SCALE     =0.70f;  // each next mirror will be 70% of the size or the previous
-   private static final float HEAD_SCALE       =0.30f;  // Head's height will be 30% of the height of the mirror
+   private static final float HEAD_SCALE       =0.40f;  // Head's height will be 30% of the height of the mirror
    private static final float MIRROR_BRIGHTNESS=0.70f;  // Each next mirror 30% darker
-   private static final float MIRROR_MARGIN    =0.11f;  // The frame of the mirror takes up 11% of its width
+   private static final float MIRROR_MARGIN    =0.09f;  // The frame of the mirror takes up 9% of its width
    private static final float MIRROR_MOVE      =0.12f;  // Each next mirror is moved to the right by 12% of
                                                         // the length of the previous one
 
    private GLSurfaceView mView;
-   private DistortedEffects mEffectsMirror, mEffectsHead, mEffectsNull;
-   private DistortedEffects mEffectsOffscreen1, mEffectsOffscreen2;
+   private DistortedEffects mEffectsHead, mEffectsNull, mEffectsOffscreen1, mEffectsOffscreen2;
    private DistortedTexture mTextureMirror, mTextureHead;
    private DistortedFramebuffer mOffScreen1, mOffScreen2;
    private DistortedScreen mScreen;
@@ -63,7 +62,7 @@ class MirrorRenderer implements GLSurfaceView.Renderer
    private Dynamic3D mHeadDyn;
    private int mX;
 
-   private int mMirrorW, mMirrorH, mHeadW, mHeadH;
+   private int mHeadW, mHeadH;
    private int mScreenW, mScreenH;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -74,11 +73,10 @@ class MirrorRenderer implements GLSurfaceView.Renderer
       mQuad    = new MeshFlat(1,1);
       mScreen  = new DistortedScreen();
 
-      mEffectsMirror    = new DistortedEffects();
-      mEffectsHead      = new DistortedEffects();
-      mEffectsOffscreen1= new DistortedEffects();
-      mEffectsOffscreen2= new DistortedEffects();
-      mEffectsNull      = new DistortedEffects();
+      mEffectsHead       = new DistortedEffects();
+      mEffectsOffscreen1 = new DistortedEffects();
+      mEffectsOffscreen2 = new DistortedEffects();
+      mEffectsNull       = new DistortedEffects();
 
       mX = MirrorActivity.INIT_POSITION;
 
@@ -92,10 +90,7 @@ class MirrorRenderer implements GLSurfaceView.Renderer
    void setPosition(int pos)
       {
       mX = pos;
-
-      float headW = (HEAD_SCALE *mScreenH* mHeadW) / (mScreenW* mHeadH);
-
-      mHeadPosition.set1(mX*(1.0f-2*MIRROR_MARGIN-headW)*mScreenW / 100.0f + MIRROR_MARGIN*mScreenW);
+      mHeadPosition.set1( (mX/50.0f-1)*(0.5f-MIRROR_MARGIN-HEAD_SCALE/2) );
       }
    
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -133,28 +128,37 @@ class MirrorRenderer implements GLSurfaceView.Renderer
         mOffScreen2 = new DistortedFramebuffer( (int)(MIRROR_SCALE*mScreenW), (int)(MIRROR_SCALE*mScreenH) );
 
         mEffectsHead.abortAllEffects();
-        mEffectsMirror.abortAllEffects();
         mEffectsOffscreen1.abortAllEffects();
         mEffectsOffscreen2.abortAllEffects();
 
-        mEffectsMirror.scale( new Static3D( (float)mScreenW/mMirrorW, (float)mScreenH/mMirrorH, 1.0f) );
-        mEffectsOffscreen1.scale(MIRROR_SCALE);
         mEffectsOffscreen1.brightness(new Static1D(MIRROR_BRIGHTNESS));
-        mEffectsOffscreen2.move( new Static3D( MIRROR_MOVE*mScreenW, MIRROR_MOVE*mScreenH*mMirrorW/mMirrorH, 0) );
+        mEffectsOffscreen2.move( new Static3D( MIRROR_MOVE-0.5f+MIRROR_SCALE/2, MIRROR_MOVE-0.5f+MIRROR_SCALE/2, 0) );
+        mEffectsOffscreen2.scale( new Static3D( MIRROR_SCALE, MIRROR_SCALE, 1) );
 
         mEffectsHead.move(mHeadDyn);
-        float headScale = HEAD_SCALE *mScreenH/ mHeadH;
-        mEffectsHead.scale(headScale);
-        mHeadPosition.set2( mScreenH*(1.0f-MIRROR_MARGIN*mMirrorW/mMirrorH) - headScale* mHeadH);
+        float qx = mScreenW/ mHeadW;
+        float qy = mScreenH/ mHeadH;
+
+        if( qx<qy )
+          {
+          mEffectsHead.scale(new Static3D(HEAD_SCALE, HEAD_SCALE*qx/qy, 1) );
+          mHeadPosition.set2(0.5f-MIRROR_MARGIN-(HEAD_SCALE/2)*qx/qy);
+          }
+        else
+          {
+          mEffectsHead.scale( new Static3D(HEAD_SCALE*qy/qx, HEAD_SCALE, 1) );
+          mHeadPosition.set2(0.5f-MIRROR_MARGIN-HEAD_SCALE/2);
+          }
+
         setPosition(mX);
 
-        mOffScreen1.attach( mTextureMirror, mEffectsMirror    , mQuad );
+        mOffScreen1.attach( mTextureMirror, mEffectsNull      , mQuad );
         mOffScreen1.attach( mOffScreen2   , mEffectsOffscreen2, mQuad );
         mOffScreen1.attach( mTextureHead  , mEffectsHead      , mQuad );
         mOffScreen2.attach( mOffScreen1   , mEffectsOffscreen1, mQuad );
 
         mScreen.detachAll();
-        mScreen.attach    ( mOffScreen1   , mEffectsNull      , mQuad );
+        mScreen.attach    ( mOffScreen1   , mEffectsNull     , mQuad );
         mScreen.resize(mScreenW,mScreenH);
         }
       }
@@ -183,12 +187,10 @@ class MirrorRenderer implements GLSurfaceView.Renderer
         catch(IOException e) { }
         }
 
-      mMirrorW = bitmapM.getWidth();
-      mMirrorH = bitmapM.getHeight();
-      mHeadW   = bitmapH.getWidth();
-      mHeadH   = bitmapH.getHeight();
+      mHeadW = bitmapH.getWidth();
+      mHeadH = bitmapH.getHeight();
 
-      if( mTextureMirror==null ) mTextureMirror = new DistortedTexture(mMirrorW,mMirrorH);
+      if( mTextureMirror==null ) mTextureMirror = new DistortedTexture(bitmapM.getWidth(),bitmapM.getHeight());
       if( mTextureHead  ==null ) mTextureHead   = new DistortedTexture(mHeadW, mHeadH);
 
       mTextureMirror.setTexture(bitmapM);
diff --git a/src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java b/src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java
index e62324f..2db3f0c 100644
--- a/src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java
+++ b/src/main/java/org/distorted/examples/quaternion/QuaternionRenderer.java
@@ -41,7 +41,6 @@ import org.distorted.library.Distorted;
 
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.opengl.GLES30;
 import android.opengl.GLSurfaceView;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -99,13 +98,14 @@ class QuaternionRenderer implements GLSurfaceView.Renderer
     
   public void onSurfaceChanged(GL10 glUnused, int width, int height) 
     {
-    float scaleFactor = width>height ? height/3:width/3;
+    float qx = (float)width ;
+    float qy = (float)height;
+    float scale = 0.5f;
 
     mEffects.abortEffects(EffectTypes.MATRIX);
-    mEffects.move( new Static3D( (width-scaleFactor)/2 , (height-scaleFactor)/2 , 0) );
-    mEffects.scale(scaleFactor);
-    mEffects.quaternion( mRot, new Static3D( (float)mTexture.getWidth()/2, (float)mTexture.getHeight()/2 , 0) );
-       
+    mEffects.quaternion( mRot, new Static3D(0,0,0) );
+    mEffects.scale(  qx<qy ? (new Static3D(scale,scale*qx/qy,scale)) : (new Static3D(scale*qy/qx,scale,scale)) );
+
     mScreen.resize(width, height);
     }
 
