diff options
author | petrs <[email protected]> | 2013-06-02 21:14:45 +0200 |
---|---|---|
committer | petrs <[email protected]> | 2013-06-02 21:14:45 +0200 |
commit | ba8f322de06204afe4c7cb81e51a1d46477bb586 (patch) | |
tree | bc8f09a9b8a9a204877c16f4513016335359eb55 /src/jogl/classes/com/jogamp/opengl | |
parent | 1fe8fa0765f13980cd4498cb65ab2e36908e75b1 (diff) |
new method for vector multiplication, new copy constructor
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/math/Quaternion.java | 28 |
1 files changed, 28 insertions, 0 deletions
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 |