diff options
author | Petr Skramovsky <[email protected]> | 2013-06-02 21:14:45 +0200 |
---|---|---|
committer | Petr Skramovsky <[email protected]> | 2013-06-05 13:34:04 +0200 |
commit | 08bfa5797069cb5757620e74b8befaa079d04ddb (patch) | |
tree | bc8f09a9b8a9a204877c16f4513016335359eb55 | |
parent | 0a4defdfe478c3e231f3b1255cba6989aa2c489e (diff) |
new method for vector multiplication, new copy constructor
-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 |