commit 1dec66e01ced9715c90295817e83dd3262617c4a
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Thu May 11 14:55:04 2023 +0200

    Implement the android.opengl.Matrix functions ourselves.

diff --git a/src/main/java/org/distorted/library/effect/MatrixEffectMove.java b/src/main/java/org/distorted/library/effect/MatrixEffectMove.java
index 485c40a..a0092ac 100644
--- a/src/main/java/org/distorted/library/effect/MatrixEffectMove.java
+++ b/src/main/java/org/distorted/library/effect/MatrixEffectMove.java
@@ -20,8 +20,7 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.Matrix;
-
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.type.Data3D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -55,8 +54,8 @@ public class MatrixEffectMove extends MatrixEffect
     float sy = uniforms[NUM_FLOAT_UNIFORMS*index+1];
     float sz = uniforms[NUM_FLOAT_UNIFORMS*index+2];
 
-    Matrix.translateM(matrixP, 0, sx, sy, sz);
-    Matrix.translateM(matrixV, 0, sx, sy, sz);
+    MatrixHelper.translate(matrixP, sx, sy, sz);
+    MatrixHelper.translate(matrixV, sx, sy, sz);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java b/src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java
index a8a7a04..60bfdc5 100644
--- a/src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java
+++ b/src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java
@@ -20,8 +20,7 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.Matrix;
-
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.type.Data3D;
 import org.distorted.library.type.Data4D;
 
@@ -66,13 +65,13 @@ public class MatrixEffectQuaternion extends MatrixEffect
     float y = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1];
     float z = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2];
 
-    Matrix.translateM(matrixP, 0, x, y, z);
-    multiplyByQuat   (matrixP, qX, qY, qZ, qW);
-    Matrix.translateM(matrixP, 0,-x,-y,-z);
+    MatrixHelper.translate(matrixP, x, y, z);
+    multiplyByQuat(matrixP, qX, qY, qZ, qW);
+    MatrixHelper.translate(matrixP,-x,-y,-z);
 
-    Matrix.translateM(matrixV, 0, x, y, z);
-    multiplyByQuat   (matrixV, qX, qY, qZ, qW);
-    Matrix.translateM(matrixV, 0,-x,-y,-z);
+    MatrixHelper.translate(matrixV, x, y, z);
+    multiplyByQuat(matrixV, qX, qY, qZ, qW);
+    MatrixHelper.translate(matrixV,-x,-y,-z);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -101,7 +100,7 @@ public class MatrixEffectQuaternion extends MatrixEffect
     mTmpMatrix1[3]  = mTmpMatrix1[7] = mTmpMatrix1[11] = mTmpMatrix1[12] = mTmpMatrix1[13] = mTmpMatrix1[14] = 0;
     mTmpMatrix1[15] = 1;
 
-    Matrix.multiplyMM(mTmpMatrix2, 0, matrix, 0, mTmpMatrix1, 0);
+    MatrixHelper.multiply(mTmpMatrix2, matrix, mTmpMatrix1);
 
     matrix[ 0] = mTmpMatrix2[ 0];
     matrix[ 1] = mTmpMatrix2[ 1];
diff --git a/src/main/java/org/distorted/library/effect/MatrixEffectRotate.java b/src/main/java/org/distorted/library/effect/MatrixEffectRotate.java
index c998b79..53b0d87 100644
--- a/src/main/java/org/distorted/library/effect/MatrixEffectRotate.java
+++ b/src/main/java/org/distorted/library/effect/MatrixEffectRotate.java
@@ -20,8 +20,7 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.Matrix;
-
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.type.Data1D;
 import org.distorted.library.type.Data3D;
 
@@ -64,13 +63,13 @@ public class MatrixEffectRotate extends MatrixEffect
     float y = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1];
     float z = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2];
 
-    Matrix.translateM(matrixP, 0, x, y, z);
-    Matrix.rotateM   (matrixP, 0, angle, axisX, axisY, axisZ);
-    Matrix.translateM(matrixP, 0,-x,-y,-z);
+    MatrixHelper.translate(matrixP, x, y, z);
+    MatrixHelper.rotate(matrixP, angle, axisX, axisY, axisZ);
+    MatrixHelper.translate(matrixP,-x,-y,-z);
 
-    Matrix.translateM(matrixV, 0, x, y, z);
-    Matrix.rotateM   (matrixV, 0, angle, axisX, axisY, axisZ);
-    Matrix.translateM(matrixV, 0,-x,-y,-z);
+    MatrixHelper.translate(matrixV, x, y, z);
+    MatrixHelper.rotate(matrixV, angle, axisX, axisY, axisZ);
+    MatrixHelper.translate(matrixV,-x,-y,-z);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/effect/MatrixEffectScale.java b/src/main/java/org/distorted/library/effect/MatrixEffectScale.java
index 9103af6..08e5e65 100644
--- a/src/main/java/org/distorted/library/effect/MatrixEffectScale.java
+++ b/src/main/java/org/distorted/library/effect/MatrixEffectScale.java
@@ -20,8 +20,7 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.Matrix;
-
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.type.Data3D;
 import org.distorted.library.type.Static3D;
 
@@ -62,8 +61,8 @@ public class MatrixEffectScale extends MatrixEffect
     float sy = uniforms[NUM_FLOAT_UNIFORMS*index+1];
     float sz = uniforms[NUM_FLOAT_UNIFORMS*index+2];
 
-    Matrix.scaleM(matrixP, 0, sx, sy, sz);
-    Matrix.scaleM(matrixV, 0, sy*sz, sx*sz, sx*sy);
+    MatrixHelper.scale(matrixP, sx, sy, sz);
+    MatrixHelper.scale(matrixV, sy*sz, sx*sz, sx*sy);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/effect/MatrixEffectShear.java b/src/main/java/org/distorted/library/effect/MatrixEffectShear.java
index f5e479c..3a91f87 100644
--- a/src/main/java/org/distorted/library/effect/MatrixEffectShear.java
+++ b/src/main/java/org/distorted/library/effect/MatrixEffectShear.java
@@ -20,8 +20,7 @@
 
 package org.distorted.library.effect;
 
-import android.opengl.Matrix;
-
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.type.Data3D;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -63,7 +62,7 @@ public class MatrixEffectShear extends MatrixEffect
     float y  = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1];
     float z  = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2];
 
-    Matrix.translateM(matrixP, 0, x, y, z);
+    MatrixHelper.translate(matrixP, x, y, z);
 
     matrixP[4] += sx*matrixP[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear.
     matrixP[5] += sx*matrixP[1]; //                        0 1 0 0
@@ -80,9 +79,8 @@ public class MatrixEffectShear extends MatrixEffect
     matrixP[6] += sz*matrixP[10];//                        0 z 1 0
     matrixP[7] += sz*matrixP[11];//                        0 0 0 1
 
-    Matrix.translateM(matrixP, 0,-x,-y,-z);
-
-    Matrix.translateM(matrixV, 0, x, y, z);
+    MatrixHelper.translate(matrixP,-x,-y,-z);
+    MatrixHelper.translate(matrixV, x, y, z);
 
     matrixV[0] -= sx*matrixV[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. vector X-shear.
     matrixV[1] -= sx*matrixV[5]; //                       -x 1 0 0
@@ -99,7 +97,7 @@ public class MatrixEffectShear extends MatrixEffect
     matrixV[10]-= sz*matrixV[6]; //                        0 0 1 0
     matrixV[11]-= sz*matrixV[7]; //                        0 0 0 1
 
-    Matrix.translateM(matrixV, 0,-x,-y,-z);
+    MatrixHelper.translate(matrixV,-x,-y,-z);
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java b/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
index db15a68..014516b 100644
--- a/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java
@@ -21,8 +21,8 @@
 package org.distorted.library.effectqueue;
 
 import android.opengl.GLES30;
-import android.opengl.Matrix;
 
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.effect.EffectType;
 import org.distorted.library.effect.MatrixEffect;
 import org.distorted.library.message.EffectMessageSender;
@@ -89,30 +89,23 @@ class EffectQueueMatrix extends EffectQueue
 
   void send(float distance, float mipmap, float[] projection, int variant)
     {
-    Matrix.setIdentityM(mModelViewMatrixP, 0);
-    Matrix.translateM(mModelViewMatrixP, 0, 0,0, -distance);
-
-    if( mipmap!=1 )
-      {
-      Matrix.scaleM(mModelViewMatrixP, 0, mipmap, mipmap, mipmap);
-      }
-
-    mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0];
-    mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1];
-    mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2];
-    mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3];
-    mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4];
-    mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5];
-    mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6];
-    mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7];
-    mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8];
-    mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9];
-    mModelViewMatrixV[10] = mModelViewMatrixP[10];
-    mModelViewMatrixV[11] = mModelViewMatrixP[11];
-    mModelViewMatrixV[12] = mModelViewMatrixP[12];
-    mModelViewMatrixV[13] = mModelViewMatrixP[13];
-    mModelViewMatrixV[14] = mModelViewMatrixP[14];
-    mModelViewMatrixV[15] = mModelViewMatrixP[15];
+    // i.e. setIdentity(); translate(0,0,-distance); scale(mipmap,mipmap,mipmap)
+    mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0] = mipmap;
+    mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1] = 0;
+    mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2] = 0;
+    mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3] = 0;
+    mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4] = 0;
+    mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5] = mipmap;
+    mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6] = 0;
+    mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7] = 0;
+    mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8] = 0;
+    mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9] = 0;
+    mModelViewMatrixV[10] = mModelViewMatrixP[10] = mipmap;
+    mModelViewMatrixV[11] = mModelViewMatrixP[11] = 0;
+    mModelViewMatrixV[12] = mModelViewMatrixP[12] = 0;
+    mModelViewMatrixV[13] = mModelViewMatrixP[13] = 0;
+    mModelViewMatrixV[14] = mModelViewMatrixP[14] = -distance;
+    mModelViewMatrixV[15] = mModelViewMatrixP[15] = 1;
 
     float[] array = mUBF.getBackingArray();
 
@@ -123,7 +116,7 @@ class EffectQueueMatrix extends EffectQueue
       }
 
     // combined Model-View-Projection matrix
-    Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrixP, 0);
+    MatrixHelper.multiply(mMVPMatrix, projection, mModelViewMatrixP);
 
     GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0);
     GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0);
diff --git a/src/main/java/org/distorted/library/helpers/MatrixHelper.java b/src/main/java/org/distorted/library/helpers/MatrixHelper.java
new file mode 100644
index 0000000..723dec5
--- /dev/null
+++ b/src/main/java/org/distorted/library/helpers/MatrixHelper.java
@@ -0,0 +1,161 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2023 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library is distributed in the hope that it will be useful,                               //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.helpers;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class MatrixHelper
+  {
+  public static void setIdentity(float[] output)
+    {
+    output[ 0] = 1;
+    output[ 1] = 0;
+    output[ 2] = 0;
+    output[ 3] = 0;
+    output[ 4] = 0;
+    output[ 5] = 1;
+    output[ 6] = 0;
+    output[ 7] = 0;
+    output[ 8] = 0;
+    output[ 9] = 0;
+    output[10] = 1;
+    output[11] = 0;
+    output[12] = 0;
+    output[13] = 0;
+    output[14] = 0;
+    output[15] = 1;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void multiply(float[] output, float[] m1, float[] m2)
+    {
+    output[ 0] = m1[ 0]*m2[ 0] + m1[ 4]*m2[ 1] + m1[ 8]*m2[ 2] + m1[12]*m2[ 3];
+    output[ 1] = m1[ 1]*m2[ 0] + m1[ 5]*m2[ 1] + m1[ 9]*m2[ 2] + m1[13]*m2[ 3];
+    output[ 2] = m1[ 2]*m2[ 0] + m1[ 6]*m2[ 1] + m1[10]*m2[ 2] + m1[14]*m2[ 3];
+    output[ 3] = m1[ 3]*m2[ 0] + m1[ 7]*m2[ 1] + m1[11]*m2[ 2] + m1[15]*m2[ 3];
+
+    output[ 4] = m1[ 0]*m2[ 4] + m1[ 4]*m2[ 5] + m1[ 8]*m2[ 6] + m1[12]*m2[ 7];
+    output[ 5] = m1[ 1]*m2[ 4] + m1[ 5]*m2[ 5] + m1[ 9]*m2[ 6] + m1[13]*m2[ 7];
+    output[ 6] = m1[ 2]*m2[ 4] + m1[ 6]*m2[ 5] + m1[10]*m2[ 6] + m1[14]*m2[ 7];
+    output[ 7] = m1[ 3]*m2[ 4] + m1[ 7]*m2[ 5] + m1[11]*m2[ 6] + m1[15]*m2[ 7];
+
+    output[ 8] = m1[ 0]*m2[ 8] + m1[ 4]*m2[ 9] + m1[ 8]*m2[10] + m1[12]*m2[11];
+    output[ 9] = m1[ 1]*m2[ 8] + m1[ 5]*m2[ 9] + m1[ 9]*m2[10] + m1[13]*m2[11];
+    output[10] = m1[ 2]*m2[ 8] + m1[ 6]*m2[ 9] + m1[10]*m2[10] + m1[14]*m2[11];
+    output[11] = m1[ 3]*m2[ 8] + m1[ 7]*m2[ 9] + m1[11]*m2[10] + m1[15]*m2[11];
+
+    output[12] = m1[ 0]*m2[12] + m1[ 4]*m2[13] + m1[ 8]*m2[14] + m1[12]*m2[15];
+    output[13] = m1[ 1]*m2[12] + m1[ 5]*m2[13] + m1[ 9]*m2[14] + m1[13]*m2[15];
+    output[14] = m1[ 2]*m2[12] + m1[ 6]*m2[13] + m1[10]*m2[14] + m1[14]*m2[15];
+    output[15] = m1[ 3]*m2[12] + m1[ 7]*m2[13] + m1[11]*m2[14] + m1[15]*m2[15];
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void frustum(float[] output, float l, float r, float b, float t, float n, float f)
+    {
+    output[0]  =  2 * n / (r - l);
+    output[1]  =  0;
+    output[2]  =  0;
+    output[3]  =  0;
+    output[4]  =  0;
+    output[5]  =  2 * n / (t - b);
+    output[6]  =  0;
+    output[7]  =  0;
+    output[8]  =  (r + l) / (r - l);
+    output[9]  =  (t + b) / (t - b);
+    output[10] = -(f + n) / (f - n);
+    output[11] = -1;
+    output[12] =  0;
+    output[13] =  0;
+    output[14] = -(2 * f * n) / (f - n);
+    output[15] =  0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void ortho(float[] output, float l, float r, float b, float t, float n, float f)
+    {
+    output[0]  =  2 / (r - l);
+    output[1]  =  0;
+    output[2]  =  0;
+    output[3]  =  0;
+    output[4]  =  0;
+    output[5]  =  2 / (t - b);
+    output[6]  =  0;
+    output[7]  =  0;
+    output[8]  =  0;
+    output[9]  =  0;
+    output[10] = -2 / (f - n);
+    output[11] =  0;
+    output[12] = -(r + l) / (r - l);
+    output[13] = -(t + b) / (t - b);
+    output[14] = -(f + n) / (f - n);
+    output[15] =  1;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void setLookAt(float[] output, float eyeX , float eyeY , float eyeZ ,
+                                               float lookX, float lookY, float lookZ,
+                                               float upX  , float upY  , float upZ  )
+    {
+    // TODO
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void rotate(float[] output, float angle, float axisX, float axisY, float axisZ)
+    {
+    android.opengl.Matrix.rotateM(output,0,angle,axisX,axisY,axisZ);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void translate(float[] output, float dx, float dy, float dz)
+    {
+    output[12] += ( output[ 0]*dx + output[ 4]*dy + output[ 8]*dz);
+    output[13] += ( output[ 1]*dx + output[ 5]*dy + output[ 9]*dz);
+    output[14] += ( output[ 2]*dx + output[ 6]*dy + output[10]*dz);
+    output[15] += ( output[ 3]*dx + output[ 7]*dy + output[11]*dz);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void scale(float[] output, float sx, float sy, float sz)
+    {
+    output[ 0] *= sx;
+    output[ 1] *= sx;
+    output[ 2] *= sx;
+    output[ 3] *= sx;
+
+    output[ 4] *= sy;
+    output[ 5] *= sy;
+    output[ 6] *= sy;
+    output[ 7] *= sy;
+
+    output[ 8] *= sz;
+    output[ 9] *= sz;
+    output[10] *= sz;
+    output[11] *= sz;
+    }
+  }
diff --git a/src/main/java/org/distorted/library/helpers/QuatHelper.java b/src/main/java/org/distorted/library/helpers/QuatHelper.java
new file mode 100644
index 0000000..8631e96
--- /dev/null
+++ b/src/main/java/org/distorted/library/helpers/QuatHelper.java
@@ -0,0 +1,284 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2021 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library is distributed in the hope that it will be useful,                               //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.helpers;
+
+import org.distorted.library.type.Static4D;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class QuatHelper
+  {
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return quat1*quat2
+
+  public static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
+    {
+    float qx = quat1.get0();
+    float qy = quat1.get1();
+    float qz = quat1.get2();
+    float qw = quat1.get3();
+
+    float rx = quat2.get0();
+    float ry = quat2.get1();
+    float rz = quat2.get2();
+    float rw = quat2.get3();
+
+    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
+    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
+    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
+    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
+
+    return new Static4D(tx,ty,tz,tw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return quat1*(rx,ry,rz,rw)
+
+  public static Static4D quatMultiply( Static4D quat1, float rx, float ry, float rz, float rw )
+    {
+    float qx = quat1.get0();
+    float qy = quat1.get1();
+    float qz = quat1.get2();
+    float qw = quat1.get3();
+
+    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
+    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
+    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
+    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
+
+    return new Static4D(tx,ty,tz,tw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return (qx,qy,qz,qw)*quat2
+
+  public static Static4D quatMultiply( float qx, float qy, float qz, float qw, Static4D quat2 )
+    {
+    float rx = quat2.get0();
+    float ry = quat2.get1();
+    float rz = quat2.get2();
+    float rw = quat2.get3();
+
+    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
+    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
+    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
+    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
+
+    return new Static4D(tx,ty,tz,tw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return (qx,qy,qz,qw)*(rx,ry,rz,rw)
+
+  public static Static4D quatMultiply( float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw )
+    {
+    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
+    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
+    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
+    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
+
+    return new Static4D(tx,ty,tz,tw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
+
+  public static void quatMultiply( float[] ret, float[] q, float[] r )
+    {
+    ret[0] = r[3]*q[0] - r[2]*q[1] + r[1]*q[2] + r[0]*q[3];
+    ret[1] = r[3]*q[1] + r[2]*q[0] + r[1]*q[3] - r[0]*q[2];
+    ret[2] = r[3]*q[2] + r[2]*q[3] - r[1]*q[0] + r[0]*q[1];
+    ret[3] = r[3]*q[3] - r[2]*q[2] - r[1]*q[1] - r[0]*q[0];
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
+
+  public static void quatMultiply( float[] ret, float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw )
+    {
+    ret[0] = rw*qx - rz*qy + ry*qz + rx*qw;
+    ret[1] = rw*qy + rz*qx + ry*qw - rx*qz;
+    ret[2] = rw*qz + rz*qw - ry*qx + rx*qy;
+    ret[3] = rw*qw - rz*qz - ry*qy - rx*qx;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotate 'vector' by quat  ( i.e. return quat*vector*(quat^-1) )
+
+  public static Static4D rotateVectorByQuat(Static4D vector, Static4D quat)
+    {
+    float qx = quat.get0();
+    float qy = quat.get1();
+    float qz = quat.get2();
+    float qw = quat.get3();
+
+    Static4D tmp = quatMultiply(qx,qy,qz,qw,vector);
+
+    return quatMultiply(tmp,-qx,-qy,-qz,qw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotate (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
+
+  public static Static4D rotateVectorByQuat(float x, float y, float z, float w, Static4D quat)
+    {
+    float qx = quat.get0();
+    float qy = quat.get1();
+    float qz = quat.get2();
+    float qw = quat.get3();
+
+    Static4D tmp = quatMultiply(qx,qy,qz,qw,x,y,z,w);
+
+    return quatMultiply(tmp,-qx,-qy,-qz,qw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotate (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
+
+  public static void rotateVectorByQuat(float[] output, float x, float y, float z, float w, Static4D quat)
+    {
+    float[] tmp = new float[4];
+
+    float qx = quat.get0();
+    float qy = quat.get1();
+    float qz = quat.get2();
+    float qw = quat.get3();
+
+    quatMultiply(tmp,qx,qy,qz,qw,x,y,z,w);
+    quatMultiply(output,tmp[0],tmp[1],tmp[2],tmp[3],-qx,-qy,-qz,qw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotate vec by quat ( i.e. return quat*vector*(quat^-1) )
+
+  public static void rotateVectorByQuat(float[] output, float[] vec, float[] quat)
+    {
+    float[] tmp = new float[4];
+
+    quatMultiply(tmp,quat,vec);
+
+    quat[0] = -quat[0];
+    quat[1] = -quat[1];
+    quat[2] = -quat[2];
+
+    quatMultiply(output,tmp,quat);
+
+    quat[0] = -quat[0];
+    quat[1] = -quat[1];
+    quat[2] = -quat[2];
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
+
+  public static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat)
+    {
+    float qx = quat.get0();
+    float qy = quat.get1();
+    float qz = quat.get2();
+    float qw = quat.get3();
+
+    Static4D tmp = quatMultiply(-qx,-qy,-qz,qw,vector);
+
+    return quatMultiply(tmp,quat);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static Static4D quatFromDrag(float dragX, float dragY)
+    {
+    float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
+    float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
+    float axisZ = 0;
+    float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
+
+    if( axisL>0 )
+      {
+      axisX /= axisL;
+      axisY /= axisL;
+      axisZ /= axisL;
+
+      float ratio = axisL;
+      ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
+
+      float cosA = (float)Math.cos(Math.PI*ratio);
+      float sinA = (float)Math.sqrt(1-cosA*cosA);
+
+      return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
+      }
+
+    return new Static4D(0f, 0f, 0f, 1f);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static double computeCos(double oldX, double oldY, double newX, double newY, double len1, double len2)
+    {
+    double ret= (oldX*newX+oldY*newY) / (len1*len2);
+    if( ret<-1.0 ) return -1.0;
+    if( ret> 1.0 ) return  1.0;
+
+    return ret;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// sin of (signed!) angle between vectors 'old' and 'new', counterclockwise!
+
+  public static double computeSin(double oldX, double oldY, double newX, double newY, double len1, double len2)
+    {
+    double ret= (newX*oldY-oldX*newY) / (len1*len2);
+    if( ret<-1.0 ) return -1.0;
+    if( ret> 1.0 ) return  1.0;
+
+    return ret;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return quat Q that turns 3D vector A=(ax,ay,az) to another 3D vector B=(bx,by,bz)
+// take care of double-cover by ensuring that always Q.get3() >=0
+
+  public static Static4D retRotationQuat(float ax, float ay, float az, float bx, float by, float bz)
+    {
+    float nx = ay*bz - az*by;
+    float ny = az*bx - ax*bz;
+    float nz = ax*by - ay*bx;
+
+    float sin = (float)Math.sqrt(nx*nx + ny*ny + nz*nz);
+    float cos = ax*bx + ay*by + az*bz;
+
+    if( sin!=0 )
+      {
+      nx /= sin;
+      ny /= sin;
+      nz /= sin;
+      }
+
+    // Why sin<=0 and cos>=0 ?
+    // 0<angle<180 -> 0<halfAngle<90 -> both sin and cos are positive.
+    // But1: quats work counterclockwise -> negate cos.
+    // But2: double-cover, we prefer to have the cos positive (so that unit=(0,0,0,1))
+    // so negate again both cos and sin.
+    float sinHalf =-(float)Math.sqrt((1-cos)/2);
+    float cosHalf = (float)Math.sqrt((1+cos)/2);
+
+    return new Static4D(nx*sinHalf,ny*sinHalf,nz*sinHalf,cosHalf);
+    }
+  }
diff --git a/src/main/java/org/distorted/library/main/InternalOutputSurface.java b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
index 40daf04..05b9ae4 100644
--- a/src/main/java/org/distorted/library/main/InternalOutputSurface.java
+++ b/src/main/java/org/distorted/library/main/InternalOutputSurface.java
@@ -22,10 +22,10 @@ package org.distorted.library.main;
 
 import android.opengl.GLES30;
 import android.opengl.GLES31;
-import android.opengl.Matrix;
 
 import org.distorted.library.effect.EffectQuality;
 import org.distorted.library.effectqueue.EffectQueuePostprocess;
+import org.distorted.library.helpers.MatrixHelper;
 import org.distorted.library.mesh.MeshBase;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -65,6 +65,8 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
   int mCurrFBO;     // internal current FBO (see DistortedLibrary.FBO_QUEUE_SIZE)
   int mWidth, mHeight;
 
+static final float[] tmpM = new float[16];
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   InternalOutputSurface(int width, int height, int createColor, int numfbos, int numcolors, int depthStencil, int fbo, int type, int storage)
@@ -150,7 +152,7 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
         mDistance    = mHeight/a;
         float far    = 2*mDistance-near;
 
-        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+        MatrixHelper.frustum(mProjectionMatrix, left, right, bottom, top, near, far);
         }
       else             // parallel projection
         {
@@ -162,7 +164,7 @@ public abstract class InternalOutputSurface extends InternalSurface implements I
         mDistance    = mWidth+mHeight;
         float far    = mWidth+mHeight+mHeight*(1.0f-mNear);
 
-        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+        MatrixHelper.ortho(mProjectionMatrix, left, right, bottom, top, near, far);
         }
       }
     }
diff --git a/src/main/java/org/distorted/library/main/QuatHelper.java b/src/main/java/org/distorted/library/main/QuatHelper.java
deleted file mode 100644
index a974060..0000000
--- a/src/main/java/org/distorted/library/main/QuatHelper.java
+++ /dev/null
@@ -1,284 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// Copyright 2021 Leszek Koltunski  leszek@koltunski.pl                                          //
-//                                                                                               //
-// This file is part of Distorted.                                                               //
-//                                                                                               //
-// This library is free software; you can redistribute it and/or                                 //
-// modify it under the terms of the GNU Lesser General Public                                    //
-// License as published by the Free Software Foundation; either                                  //
-// version 2.1 of the License, or (at your option) any later version.                            //
-//                                                                                               //
-// This library is distributed in the hope that it will be useful,                               //
-// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
-// Lesser General Public License for more details.                                               //
-//                                                                                               //
-// You should have received a copy of the GNU Lesser General Public                              //
-// License along with this library; if not, write to the Free Software                           //
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-package org.distorted.library.main;
-
-import org.distorted.library.type.Static4D;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-public class QuatHelper
-  {
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat1*quat2
-
-  public static Static4D quatMultiply( Static4D quat1, Static4D quat2 )
-    {
-    float qx = quat1.get0();
-    float qy = quat1.get1();
-    float qz = quat1.get2();
-    float qw = quat1.get3();
-
-    float rx = quat2.get0();
-    float ry = quat2.get1();
-    float rz = quat2.get2();
-    float rw = quat2.get3();
-
-    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-    return new Static4D(tx,ty,tz,tw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat1*(rx,ry,rz,rw)
-
-  public static Static4D quatMultiply( Static4D quat1, float rx, float ry, float rz, float rw )
-    {
-    float qx = quat1.get0();
-    float qy = quat1.get1();
-    float qz = quat1.get2();
-    float qw = quat1.get3();
-
-    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-    return new Static4D(tx,ty,tz,tw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return (qx,qy,qz,qw)*quat2
-
-  public static Static4D quatMultiply( float qx, float qy, float qz, float qw, Static4D quat2 )
-    {
-    float rx = quat2.get0();
-    float ry = quat2.get1();
-    float rz = quat2.get2();
-    float rw = quat2.get3();
-
-    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-    return new Static4D(tx,ty,tz,tw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return (qx,qy,qz,qw)*(rx,ry,rz,rw)
-
-  public static Static4D quatMultiply( float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw )
-    {
-    float tx = rw*qx - rz*qy + ry*qz + rx*qw;
-    float ty = rw*qy + rz*qx + ry*qw - rx*qz;
-    float tz = rw*qz + rz*qw - ry*qx + rx*qy;
-    float tw = rw*qw - rz*qz - ry*qy - rx*qx;
-
-    return new Static4D(tx,ty,tz,tw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
-
-  public static void quatMultiply( float[] ret, float[] q, float[] r )
-    {
-    ret[0] = r[3]*q[0] - r[2]*q[1] + r[1]*q[2] + r[0]*q[3];
-    ret[1] = r[3]*q[1] + r[2]*q[0] + r[1]*q[3] - r[0]*q[2];
-    ret[2] = r[3]*q[2] + r[2]*q[3] - r[1]*q[0] + r[0]*q[1];
-    ret[3] = r[3]*q[3] - r[2]*q[2] - r[1]*q[1] - r[0]*q[0];
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
-
-  public static void quatMultiply( float[] ret, float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw )
-    {
-    ret[0] = rw*qx - rz*qy + ry*qz + rx*qw;
-    ret[1] = rw*qy + rz*qx + ry*qw - rx*qz;
-    ret[2] = rw*qz + rz*qw - ry*qx + rx*qy;
-    ret[3] = rw*qw - rz*qz - ry*qy - rx*qx;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate 'vector' by quat  ( i.e. return quat*vector*(quat^-1) )
-
-  public static Static4D rotateVectorByQuat(Static4D vector, Static4D quat)
-    {
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.get3();
-
-    Static4D tmp = quatMultiply(qx,qy,qz,qw,vector);
-
-    return quatMultiply(tmp,-qx,-qy,-qz,qw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
-
-  public static Static4D rotateVectorByQuat(float x, float y, float z, float w, Static4D quat)
-    {
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.get3();
-
-    Static4D tmp = quatMultiply(qx,qy,qz,qw,x,y,z,w);
-
-    return quatMultiply(tmp,-qx,-qy,-qz,qw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
-
-  public static void rotateVectorByQuat(float[] output, float x, float y, float z, float w, Static4D quat)
-    {
-    float[] tmp = new float[4];
-
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.get3();
-
-    quatMultiply(tmp,qx,qy,qz,qw,x,y,z,w);
-    quatMultiply(output,tmp[0],tmp[1],tmp[2],tmp[3],-qx,-qy,-qz,qw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate vec by quat ( i.e. return quat*vector*(quat^-1) )
-
-  public static void rotateVectorByQuat(float[] output, float[] vec, float[] quat)
-    {
-    float[] tmp = new float[4];
-
-    quatMultiply(tmp,quat,vec);
-
-    quat[0] = -quat[0];
-    quat[1] = -quat[1];
-    quat[2] = -quat[2];
-
-    quatMultiply(output,tmp,quat);
-
-    quat[0] = -quat[0];
-    quat[1] = -quat[1];
-    quat[2] = -quat[2];
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
-
-  public static Static4D rotateVectorByInvertedQuat(Static4D vector, Static4D quat)
-    {
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.get3();
-
-    Static4D tmp = quatMultiply(-qx,-qy,-qz,qw,vector);
-
-    return quatMultiply(tmp,quat);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static Static4D quatFromDrag(float dragX, float dragY)
-    {
-    float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
-    float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
-    float axisZ = 0;
-    float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
-
-    if( axisL>0 )
-      {
-      axisX /= axisL;
-      axisY /= axisL;
-      axisZ /= axisL;
-
-      float ratio = axisL;
-      ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
-
-      float cosA = (float)Math.cos(Math.PI*ratio);
-      float sinA = (float)Math.sqrt(1-cosA*cosA);
-
-      return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
-      }
-
-    return new Static4D(0f, 0f, 0f, 1f);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  public static double computeCos(double oldX, double oldY, double newX, double newY, double len1, double len2)
-    {
-    double ret= (oldX*newX+oldY*newY) / (len1*len2);
-    if( ret<-1.0 ) return -1.0;
-    if( ret> 1.0 ) return  1.0;
-
-    return ret;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// sin of (signed!) angle between vectors 'old' and 'new', counterclockwise!
-
-  public static double computeSin(double oldX, double oldY, double newX, double newY, double len1, double len2)
-    {
-    double ret= (newX*oldY-oldX*newY) / (len1*len2);
-    if( ret<-1.0 ) return -1.0;
-    if( ret> 1.0 ) return  1.0;
-
-    return ret;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat Q that turns 3D vector A=(ax,ay,az) to another 3D vector B=(bx,by,bz)
-// take care of double-cover by ensuring that always Q.get3() >=0
-
-  public static Static4D retRotationQuat(float ax, float ay, float az, float bx, float by, float bz)
-    {
-    float nx = ay*bz - az*by;
-    float ny = az*bx - ax*bz;
-    float nz = ax*by - ay*bx;
-
-    float sin = (float)Math.sqrt(nx*nx + ny*ny + nz*nz);
-    float cos = ax*bx + ay*by + az*bz;
-
-    if( sin!=0 )
-      {
-      nx /= sin;
-      ny /= sin;
-      nz /= sin;
-      }
-
-    // Why sin<=0 and cos>=0 ?
-    // 0<angle<180 -> 0<halfAngle<90 -> both sin and cos are positive.
-    // But1: quats work counterclockwise -> negate cos.
-    // But2: double-cover, we prefer to have the cos positive (so that unit=(0,0,0,1))
-    // so negate again both cos and sin.
-    float sinHalf =-(float)Math.sqrt((1-cos)/2);
-    float cosHalf = (float)Math.sqrt((1+cos)/2);
-
-    return new Static4D(nx*sinHalf,ny*sinHalf,nz*sinHalf,cosHalf);
-    }
-  }
