aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Quaternion.java28
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