commit 03aa6c3b0702b6c3287224a7aa7260033448d55f
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Thu Jun 22 17:38:05 2017 +0100

    Simplification in EffectQueueMatrix.

diff --git a/src/main/java/org/distorted/library/main/EffectQueueMatrix.java b/src/main/java/org/distorted/library/main/EffectQueueMatrix.java
index 550b2bd..d903e0e 100644
--- a/src/main/java/org/distorted/library/main/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/main/EffectQueueMatrix.java
@@ -35,6 +35,13 @@ class EffectQueueMatrix extends EffectQueue
 
   private static float[] mMVPMatrix = new float[16];
   private static float[] mViewMatrix= new float[16];
+  private static float[] mTmpMatrix = new float[16];
+  private static float[] mTmpResult = new float[4];
+  private static float[] mTmpPoint  = new float[4];
+  private static float mMinx;
+  private static float mMaxx;
+  private static float mMiny;
+  private static float mMaxy;
 
   private static int mObjDH;      // This is a handle to half a Object dimensions
   private static int mMVPMatrixH; // the transformation matrix
@@ -49,97 +56,45 @@ class EffectQueueMatrix extends EffectQueue
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+  private void magnifyDir()
+    {
+    Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0);
+    float nx = mTmpResult[0]/mTmpResult[3];
+    float ny = mTmpResult[1]/mTmpResult[3];
+
+    if( nx<mMinx ) mMinx = nx;
+    if( nx>mMaxx ) mMaxx = nx;
+    if( ny<mMiny ) mMiny = ny;
+    if( ny>mMaxy ) mMaxy = ny;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// modify the ModelView matrix so that the object drawn appears to be (about) 'marginInPixels' pixels
+// larger in each direction when rendered. Used in BLUR.
+
   private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels)
     {
-    float scale, nx, ny;
-    float[] result= new float[4];
-    float[] point = new float[4];
-    float[] matrix= new float[16];
-    float minx = Integer.MAX_VALUE;
-    float maxx = Integer.MIN_VALUE;
-    float miny = Integer.MAX_VALUE;
-    float maxy = Integer.MIN_VALUE;
-
-    point[3] = 1.0f;
-
-    Matrix.multiplyMM(matrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
-
-    point[0] = +halfX; point[1] = +halfY; point[2] = +halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = +halfX; point[1] = +halfY; point[2] = -halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = +halfX; point[1] = -halfY; point[2] = +halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = +halfX; point[1] = -halfY; point[2] = -halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = -halfX; point[1] = +halfY; point[2] = +halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = -halfX; point[1] = +halfY; point[2] = -halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = -halfX; point[1] = -halfY; point[2] = +halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    point[0] = -halfX; point[1] = -halfY; point[2] = -halfZ;
-    Matrix.multiplyMV(result,0,matrix,0,point,0);
-    nx = result[0]/result[3];
-    ny = result[1]/result[3];
-    if( nx<minx ) minx = nx;
-    if( nx>maxx ) maxx = nx;
-    if( ny<miny ) miny = ny;
-    if( ny>maxy ) maxy = ny;
-
-    float xlen = projection.mWidth *(maxx-minx)/2;
-    float ylen = projection.mHeight*(maxy-miny)/2;
-
-    scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen );
+    mMinx = Integer.MAX_VALUE;
+    mMaxx = Integer.MIN_VALUE;
+    mMiny = Integer.MAX_VALUE;
+    mMaxy = Integer.MIN_VALUE;
+
+    mTmpPoint[3] = 1.0f;
+
+    Matrix.multiplyMM(mTmpMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0);
+
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir();
+    mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir();
+
+    float xlen = projection.mWidth *(mMaxx-mMinx)/2;
+    float ylen = projection.mHeight*(mMaxy-mMiny)/2;
+    float scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen );
 
     //android.util.Log.d("scale", ""+marginInPixels+" scale= "+scale+" xlen="+xlen+" ylen="+ylen);
 
