Package toxi.geom
Class Quaternion
java.lang.Object
toxi.geom.Quaternion
Quaternion implementation with SLERP based on http://is.gd/2n9s
-
Field Summary
Modifier and TypeFieldDescriptionstatic final float
float
float
float
float
-
Constructor Summary
ConstructorDescriptionQuaternion
(float w, float x, float y, float z) Quaternion
(float w, ReadonlyVec3D v) -
Method Summary
Modifier and TypeMethodDescriptionadd
(Quaternion q) copy()
static Quaternion
createFromAxisAngle
(ReadonlyVec3D axis, float angle) Creates a Quaternion from a axis and a angle.static Quaternion
createFromEuler
(float pitch, float yaw, float roll) Creates a Quaternion from Euler angles.static Quaternion
Creates a quaternion from a rotation matrix.float
dot
(Quaternion q) Computes the dot product with the given quaternion.static Quaternion
getAlignmentQuat
(ReadonlyVec3D dir, ReadonlyVec3D forward) Constructs a quaternion that rotates the vector given by the "forward" param into the direction given by the "dir" param.Computes this quaternion's conjugate, defined as the same w around the inverted axis.Deprecated.Computes normalized version of this quaternion.identity()
interpolateTo
(Quaternion target, float t) Spherical interpolation to target quaternion (code ported from GamaSutra)interpolateTo
(Quaternion target, float t, InterpolateStrategy is) interpolateToSelf
(Quaternion target, double t) Spherical interpolation to target quaternion (code ported from GamaSutra)interpolateToSelf
(Quaternion target, float t, InterpolateStrategy is) Uses spherical interpolation to approach the target quaternion.float
multiply
(Quaternion q2) scale
(float t) scaleSelf
(float t) set
(float w, float x, float y, float z) set
(Quaternion q) sub
(Quaternion q) float[]
toArray()
float[]
Converts the quaternion into a float array consisting of: rotation angle in radians, rotation axis x,y,zConverts the quat to a 4x4 rotation matrix (in row-major format).toMatrix4x4
(Matrix4x4 result) toString()
-
Field Details
-
DOT_THRESHOLD
public static final float DOT_THRESHOLD- See Also:
-
x
public float x -
y
public float y -
z
public float z -
w
public float w
-
-
Constructor Details
-
Quaternion
public Quaternion() -
Quaternion
public Quaternion(float w, float x, float y, float z) -
Quaternion
-
Quaternion
-
-
Method Details
-
createFromAxisAngle
Creates a Quaternion from a axis and a angle.- Parameters:
axis
- axis vector (will be normalized)angle
- angle in radians.- Returns:
- new quaternion
-
createFromEuler
Creates a Quaternion from Euler angles.- Parameters:
pitch
- X-angle in radians.yaw
- Y-angle in radians.roll
- Z-angle in radians.- Returns:
- new quaternion
-
createFromMatrix
Creates a quaternion from a rotation matrix. The algorithm used is from Allan and Mark Watt's "Advanced Animation and Rendering Techniques" (ACM Press 1992).- Parameters:
m
- rotation matrix- Returns:
- quaternion
-
getAlignmentQuat
Constructs a quaternion that rotates the vector given by the "forward" param into the direction given by the "dir" param.- Parameters:
dir
-forward
-- Returns:
- quaternion
-
add
-
addSelf
-
applyTo
-
copy
-
dot
Computes the dot product with the given quaternion.- Parameters:
q
-- Returns:
- dot product
-
getConjugate
Computes this quaternion's conjugate, defined as the same w around the inverted axis.- Returns:
- new conjugate quaternion
-
getMatrix
Deprecated.usetoMatrix4x4()
instead- Returns:
- result matrix
-
getNormalized
Computes normalized version of this quaternion.- Returns:
- new normalized quaternion
-
identity
-
interpolateTo
Spherical interpolation to target quaternion (code ported from GamaSutra)- Parameters:
target
- quaterniont
- interpolation factor (0..1)- Returns:
- new interpolated quat
-
interpolateTo
- Parameters:
target
-t
-is
-- Returns:
- interpolated quaternion as new instance
-
interpolateToSelf
Spherical interpolation to target quaternion (code ported from GamaSutra)- Parameters:
target
- quaterniont
- interpolation factor (0..1)- Returns:
- new interpolated quat
-
interpolateToSelf
Uses spherical interpolation to approach the target quaternion. The interpolation factor is manipulated by the chosenInterpolateStrategy
first.- Parameters:
target
-t
-is
-- Returns:
- itself
-
magnitude
public float magnitude() -
multiply
-
normalize
-
scale
-
scaleSelf
-
set
-
set
-
set
-
sub
-
subSelf
-
toArray
public float[] toArray() -
toAxisAngle
public float[] toAxisAngle()Converts the quaternion into a float array consisting of: rotation angle in radians, rotation axis x,y,z- Returns:
- 4-element float array
-
toMatrix4x4
Converts the quat to a 4x4 rotation matrix (in row-major format). Assumes the quat is currently normalized (if not, you'll need to callnormalize()
first).- Returns:
- result matrix
-
toMatrix4x4
-
toString
-
toMatrix4x4()
instead