commit 5f8e909ac1ba123905c509161ed89ca84643dbf4
Author: LeszekKoltunski <leszek@koltunski.pl>
Date:   Tue Apr 15 15:17:23 2025 +0200

    Rename .java to .kt

diff --git a/src/main/java/org/distorted/library/helpers/MatrixHelper.java b/src/main/java/org/distorted/library/helpers/MatrixHelper.java
deleted file mode 100644
index 3c366ba..0000000
--- a/src/main/java/org/distorted/library/helpers/MatrixHelper.java
+++ /dev/null
@@ -1,197 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// 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
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// this is android.opengl.Matrix.rotateM(), but with pre-computed sin and cos of the angle
-// and also we have to pre-allocate and pass here two temp arrays.
-
-  public static void rotateSinCos(float[] output, float[] tmp1, float[] tmp2, float sin, float cos, float x, float y, float z)
-    {
-    tmp1[0]  = (1-cos)*x*x + cos;
-    tmp1[1]  = (1-cos)*x*y + sin*z;
-    tmp1[2]  = (1-cos)*x*z - sin*y;
-    tmp1[3]  = 0;
-    tmp1[4]  = (1-cos)*x*y - sin*z;
-    tmp1[5]  = (1-cos)*y*y + cos;
-    tmp1[6]  = (1-cos)*y*z + sin*x;
-    tmp1[7]  = 0;
-    tmp1[8]  = (1-cos)*x*z + sin*y;
-    tmp1[9]  = (1-cos)*y*z - sin*x;
-    tmp1[10] = (1-cos)*z*z + cos;
-    tmp1[11] = 0;
-    tmp1[12] = 0;
-    tmp1[13] = 0;
-    tmp1[14] = 0;
-    tmp1[15] = 1;
-
-    tmp2[0]  =  output[ 0];
-    tmp2[1]  =  output[ 1];
-    tmp2[2]  =  output[ 2];
-    tmp2[3]  =  output[ 3];
-    tmp2[4]  =  output[ 4];
-    tmp2[5]  =  output[ 5];
-    tmp2[6]  =  output[ 6];
-    tmp2[7]  =  output[ 7];
-    tmp2[8]  =  output[ 8];
-    tmp2[9]  =  output[ 9];
-    tmp2[10] =  output[10];
-    tmp2[11] =  output[11];
-    tmp2[12] =  output[12];
-    tmp2[13] =  output[13];
-    tmp2[14] =  output[14];
-    tmp2[15] =  output[15];
-
-    multiply(output,tmp2,tmp1);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  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/MatrixHelper.kt b/src/main/java/org/distorted/library/helpers/MatrixHelper.kt
new file mode 100644
index 0000000..3c366ba
--- /dev/null
+++ b/src/main/java/org/distorted/library/helpers/MatrixHelper.kt
@@ -0,0 +1,197 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// this is android.opengl.Matrix.rotateM(), but with pre-computed sin and cos of the angle
+// and also we have to pre-allocate and pass here two temp arrays.
+
+  public static void rotateSinCos(float[] output, float[] tmp1, float[] tmp2, float sin, float cos, float x, float y, float z)
+    {
+    tmp1[0]  = (1-cos)*x*x + cos;
+    tmp1[1]  = (1-cos)*x*y + sin*z;
+    tmp1[2]  = (1-cos)*x*z - sin*y;
+    tmp1[3]  = 0;
+    tmp1[4]  = (1-cos)*x*y - sin*z;
+    tmp1[5]  = (1-cos)*y*y + cos;
+    tmp1[6]  = (1-cos)*y*z + sin*x;
+    tmp1[7]  = 0;
+    tmp1[8]  = (1-cos)*x*z + sin*y;
+    tmp1[9]  = (1-cos)*y*z - sin*x;
+    tmp1[10] = (1-cos)*z*z + cos;
+    tmp1[11] = 0;
+    tmp1[12] = 0;
+    tmp1[13] = 0;
+    tmp1[14] = 0;
+    tmp1[15] = 1;
+
+    tmp2[0]  =  output[ 0];
+    tmp2[1]  =  output[ 1];
+    tmp2[2]  =  output[ 2];
+    tmp2[3]  =  output[ 3];
+    tmp2[4]  =  output[ 4];
+    tmp2[5]  =  output[ 5];
+    tmp2[6]  =  output[ 6];
+    tmp2[7]  =  output[ 7];
+    tmp2[8]  =  output[ 8];
+    tmp2[9]  =  output[ 9];
+    tmp2[10] =  output[10];
+    tmp2[11] =  output[11];
+    tmp2[12] =  output[12];
+    tmp2[13] =  output[13];
+    tmp2[14] =  output[14];
+    tmp2[15] =  output[15];
+
+    multiply(output,tmp2,tmp1);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  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
deleted file mode 100644
index a4efda5..0000000
--- a/src/main/java/org/distorted/library/helpers/QuatHelper.java
+++ /dev/null
@@ -1,491 +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.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*quat2
-
-  public static void quatMultiply( float[] ret, 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();
-
-    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;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat1*quat(rx,ry,rz,rw)
-
-    public static void quatMultiply( float[] ret, 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();
-
-      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;
-      }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat1*quat2
-
-  public static float[] quatMultiply( float[] quat1, float[] quat2 )
-    {
-    float qx = quat1[0];
-    float qy = quat1[1];
-    float qz = quat1[2];
-    float qw = quat1[3];
-
-    float rx = quat2[0];
-    float ry = quat2[1];
-    float rz = quat2[2];
-    float rw = quat2[3];
-
-    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 float[] {tx,ty,tz,tw};
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// return quat1*(rx,ry,rz,rw)
-
-  public static Static4D quatMultiply( Static4D quat, float rx, float ry, float rz, float rw )
-    {
-    float qx = quat.get0();
-    float qy = quat.get1();
-    float qz = quat.get2();
-    float qw = quat.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)*quat
-
-  public static Static4D quatMultiply( float qx, float qy, float qz, float qw, Static4D quat )
-    {
-    float rx = quat.get0();
-    float ry = quat.get1();
-    float rz = quat.get2();
-    float rw = quat.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, Static4D q, float[] r )
-    {
-    float q0 = q.get0();
-    float q1 = q.get1();
-    float q2 = q.get2();
-    float q3 = q.get3();
-
-    ret[0] = r[3]*q0 - r[2]*q1 + r[1]*q2 + r[0]*q3;
-    ret[1] = r[3]*q1 + r[2]*q0 + r[1]*q3 - r[0]*q2;
-    ret[2] = r[3]*q2 + r[2]*q3 - r[1]*q0 + r[0]*q1;
-    ret[3] = r[3]*q3 - r[2]*q2 - r[1]*q1 - r[0]*q0;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
-
-  public static void quatMultiply( float[] ret, float[] q, Static4D r )
-    {
-    float r0 = r.get0();
-    float r1 = r.get1();
-    float r2 = r.get2();
-    float r3 = r.get3();
-
-    ret[0] = r3*q[0] - r2*q[1] + r1*q[2] + r0*q[3];
-    ret[1] = r3*q[1] + r2*q[0] + r1*q[3] - r0*q[2];
-    ret[2] = r3*q[2] + r2*q[3] - r1*q[0] + r0*q[1];
-    ret[3] = r3*q[3] - r2*q[2] - r1*q[1] - r0*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;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
-
-  private static void quatMultiply( float[] ret, int index, float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw )
-    {
-    ret[index  ] = rw*qx - rz*qy + ry*qz + rx*qw;
-    ret[index+1] = rw*qy + rz*qx + ry*qw - rx*qz;
-    ret[index+2] = rw*qz + rz*qw - ry*qx + rx*qy;
-    ret[index+3] = rw*qw - rz*qz - ry*qy - rx*qx;
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// 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 (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
-
-  public static void rotateVectorByQuat(float[] output, int index, 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,index,tmp[0],tmp[1],tmp[2],tmp[3],-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, float[] quat)
-    {
-    float[] tmp = new float[4];
-
-    float qx = quat[0];
-    float qy = quat[1];
-    float qz = quat[2];
-    float qw = quat[3];
-
-    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 (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
-
-  public static void rotateVectorByQuat(float[] output, int index, float x, float y, float z, float w, float[] quat)
-    {
-    float[] tmp = new float[4];
-
-    float qx = quat[0];
-    float qy = quat[1];
-    float qz = quat[2];
-    float qw = quat[3];
-
-    quatMultiply(tmp,qx,qy,qz,qw,x,y,z,w);
-    quatMultiply(output,index,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 vec by quat ( i.e. return quat*vector*(quat^-1) )
-
-  public static void rotateVectorByQuat(float[] output, float[] vec, Static4D quat)
-    {
-    float[] tmp = new float[4];
-
-    quatMultiply(tmp,quat,vec);
-
-    float x1 = quat.get0();
-    float y1 = quat.get1();
-    float z1 = quat.get2();
-    float w1 = quat.get3();
-    quat.set(-x1,-y1,-z1,w1);
-
-    quatMultiply(output,tmp,quat);
-
-    float x2 = quat.get0();
-    float y2 = quat.get1();
-    float z2 = quat.get2();
-    float w2 = quat.get3();
-    quat.set(-x2,-y2,-z2,w2);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// 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 '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,qx,qy,qz,qw);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
-
-    public static void rotateVectorByInvertedQuat(float[] output, float x, float y, float z, float w, float[] quat)
-      {
-      float[] tmp = new float[4];
-
-      float qx = quat[0];
-      float qy = quat[1];
-      float qz = quat[2];
-      float qw = quat[3];
-
-      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 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
-
-  public static void rotateVectorByInvertedQuat(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);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  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/helpers/QuatHelper.kt b/src/main/java/org/distorted/library/helpers/QuatHelper.kt
new file mode 100644
index 0000000..a4efda5
--- /dev/null
+++ b/src/main/java/org/distorted/library/helpers/QuatHelper.kt
@@ -0,0 +1,491 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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*quat2
+
+  public static void quatMultiply( float[] ret, 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();
+
+    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;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return quat1*quat(rx,ry,rz,rw)
+
+    public static void quatMultiply( float[] ret, 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();
+
+      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;
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return quat1*quat2
+
+  public static float[] quatMultiply( float[] quat1, float[] quat2 )
+    {
+    float qx = quat1[0];
+    float qy = quat1[1];
+    float qz = quat1[2];
+    float qw = quat1[3];
+
+    float rx = quat2[0];
+    float ry = quat2[1];
+    float rz = quat2[2];
+    float rw = quat2[3];
+
+    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 float[] {tx,ty,tz,tw};
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// return quat1*(rx,ry,rz,rw)
+
+  public static Static4D quatMultiply( Static4D quat, float rx, float ry, float rz, float rw )
+    {
+    float qx = quat.get0();
+    float qy = quat.get1();
+    float qz = quat.get2();
+    float qw = quat.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)*quat
+
+  public static Static4D quatMultiply( float qx, float qy, float qz, float qw, Static4D quat )
+    {
+    float rx = quat.get0();
+    float ry = quat.get1();
+    float rz = quat.get2();
+    float rw = quat.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, Static4D q, float[] r )
+    {
+    float q0 = q.get0();
+    float q1 = q.get1();
+    float q2 = q.get2();
+    float q3 = q.get3();
+
+    ret[0] = r[3]*q0 - r[2]*q1 + r[1]*q2 + r[0]*q3;
+    ret[1] = r[3]*q1 + r[2]*q0 + r[1]*q3 - r[0]*q2;
+    ret[2] = r[3]*q2 + r[2]*q3 - r[1]*q0 + r[0]*q1;
+    ret[3] = r[3]*q3 - r[2]*q2 - r[1]*q1 - r[0]*q0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
+
+  public static void quatMultiply( float[] ret, float[] q, Static4D r )
+    {
+    float r0 = r.get0();
+    float r1 = r.get1();
+    float r2 = r.get2();
+    float r3 = r.get3();
+
+    ret[0] = r3*q[0] - r2*q[1] + r1*q[2] + r0*q[3];
+    ret[1] = r3*q[1] + r2*q[0] + r1*q[3] - r0*q[2];
+    ret[2] = r3*q[2] + r2*q[3] - r1*q[0] + r0*q[1];
+    ret[3] = r3*q[3] - r2*q[2] - r1*q[1] - r0*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;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
+
+  private static void quatMultiply( float[] ret, int index, float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw )
+    {
+    ret[index  ] = rw*qx - rz*qy + ry*qz + rx*qw;
+    ret[index+1] = rw*qy + rz*qx + ry*qw - rx*qz;
+    ret[index+2] = rw*qz + rz*qw - ry*qx + rx*qy;
+    ret[index+3] = rw*qw - rz*qz - ry*qy - rx*qx;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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 (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
+
+  public static void rotateVectorByQuat(float[] output, int index, 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,index,tmp[0],tmp[1],tmp[2],tmp[3],-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, float[] quat)
+    {
+    float[] tmp = new float[4];
+
+    float qx = quat[0];
+    float qy = quat[1];
+    float qz = quat[2];
+    float qw = quat[3];
+
+    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 (x1,x2,x3,x4) by quat  ( i.e. return quat*vector*(quat^-1) )
+
+  public static void rotateVectorByQuat(float[] output, int index, float x, float y, float z, float w, float[] quat)
+    {
+    float[] tmp = new float[4];
+
+    float qx = quat[0];
+    float qy = quat[1];
+    float qz = quat[2];
+    float qw = quat[3];
+
+    quatMultiply(tmp,qx,qy,qz,qw,x,y,z,w);
+    quatMultiply(output,index,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 vec by quat ( i.e. return quat*vector*(quat^-1) )
+
+  public static void rotateVectorByQuat(float[] output, float[] vec, Static4D quat)
+    {
+    float[] tmp = new float[4];
+
+    quatMultiply(tmp,quat,vec);
+
+    float x1 = quat.get0();
+    float y1 = quat.get1();
+    float z1 = quat.get2();
+    float w1 = quat.get3();
+    quat.set(-x1,-y1,-z1,w1);
+
+    quatMultiply(output,tmp,quat);
+
+    float x2 = quat.get0();
+    float y2 = quat.get1();
+    float z2 = quat.get2();
+    float w2 = quat.get3();
+    quat.set(-x2,-y2,-z2,w2);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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 '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,qx,qy,qz,qw);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
+
+    public static void rotateVectorByInvertedQuat(float[] output, float x, float y, float z, float w, float[] quat)
+      {
+      float[] tmp = new float[4];
+
+      float qx = quat[0];
+      float qy = quat[1];
+      float qz = quat[2];
+      float qw = quat[3];
+
+      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 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
+
+  public static void rotateVectorByInvertedQuat(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);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  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);
+    }
+  }
