commit 487e1d5e44d8973c585732d827c10d4d844d7d65
Author: leszek <leszek@koltunski.pl>
Date:   Sun Jan 19 12:07:55 2025 +0100

    progress with Ghosts. Still far off...

diff --git a/src/main/java/org/distorted/library/helpers/QuatHelper.java b/src/main/java/org/distorted/library/helpers/QuatHelper.java
index 10db43a..f0f9ec2 100644
--- a/src/main/java/org/distorted/library/helpers/QuatHelper.java
+++ b/src/main/java/org/distorted/library/helpers/QuatHelper.java
@@ -153,6 +153,38 @@ public class QuatHelper
     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)
 
@@ -274,6 +306,30 @@ public class QuatHelper
     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) )
 
@@ -320,6 +376,22 @@ public class QuatHelper
       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)
