From ba8f322de06204afe4c7cb81e51a1d46477bb586 Mon Sep 17 00:00:00 2001
From: petrs <petrs@mapfactor.com>
Date: Sun, 2 Jun 2013 21:14:45 +0200
Subject: new method for vector multiplication, new copy constructor

---
 .../classes/com/jogamp/opengl/math/Quaternion.java | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

(limited to 'src/jogl/classes/com/jogamp/opengl')

diff --git a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
index d1f3e0336..65594a50e 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
@@ -33,6 +33,13 @@ public class Quaternion {
     public Quaternion() {
         setIdentity();
     }
+    
+    public Quaternion(Quaternion q) {
+        x = q.x;
+        y = q.y;
+        z = q.z;
+        w = q.w;
+    }
 
     public Quaternion(float x, float y, float z, float w) {
         this.x = x;
@@ -186,6 +193,27 @@ public class Quaternion {
         y *= n;
         z *= n;
     }
+    
+    /***
+     * Rotate given vector by this quaternion
+     * 
+     * @param vector input vector
+     * @return rotated vector
+     */
+    public float[] mult(float[] vector) {
+        // TODO : optimalize
+        float[] res = new float[3];
+        Quaternion a = new Quaternion(vector[0], vector[1], vector[2], 0.0f);
+        Quaternion b = new Quaternion(this);
+        Quaternion c = new Quaternion(this);
+        b.inverse();
+        a.mult(b);
+        c.mult(a);
+        res[0] = c.x;
+        res[1] = c.y;
+        res[2] = c.z;
+        return res;
+    }
 
     /**
      * Normalize a quaternion required if to be used as a rotational quaternion
-- 
cgit v1.2.3