public class Quaternion extends Object implements Serializable, Cloneable
Represents a rotation. Quaternion is a 4 value math object used to describe rotations. It has the advantage of being able to avoid lock by adding a 4th dimension to rotation.
Note: This class is a stripped and modified version of Ardor3D's Quaternion to match jPCT.
It may have bugs because of conversion. But especially fromVectorToVector(SimpleVector, SimpleVector)
,
and Matrix in/out methods work ok.
This class will possibly disappear once jPCT has its own Quaternion.
This class is adapted from Ardor3D.
Modifier and Type | Field and Description |
---|---|
static Quaternion |
IDENTITY
x=0, y=0, z=0, w=1
|
float |
w |
float |
x |
float |
y |
float |
z |
Constructor and Description |
---|
Quaternion()
Constructs a new quaternion set to (0, 0, 0, 1).
|
Quaternion(float x,
float y,
float z,
float w)
Constructs a new quaternion set to (x, y, z, w).
|
Quaternion(Matrix matrix)
Constructs a new quaternion by using rotation information from given matrix.
|
Quaternion(Quaternion source)
Constructs a new quaternion set to the (x, y, z, w) values of the given source quaternion.
|
Modifier and Type | Method and Description |
---|---|
Quaternion |
add(Quaternion quat)
Adds another Quaternion to this Quaternion.
|
float |
calcDot(Quaternion quat) |
Quaternion |
calcSub(Quaternion quat)
Calculates the difference vector of two Quaternions.
|
Quaternion |
clone() |
boolean |
equals(Object o) |
Quaternion |
fromAngleAxis(float angle,
SimpleVector axis)
Sets the values of this quaternion to the values represented by a given angle and axis of rotation.
|
Quaternion |
fromAngleNormalAxis(float angle,
SimpleVector axis)
Sets the values of this quaternion to the values represented by a given angle and unit length axis of rotation.
|
Quaternion |
fromAxes(SimpleVector[] axes)
Updates this quaternion to represent a rotation formed by the given three axes.
|
Quaternion |
fromAxes(SimpleVector xAxis,
SimpleVector yAxis,
SimpleVector zAxis)
Updates this quaternion to represent a rotation formed by the given three axes.
|
Quaternion |
fromMatrix(Matrix matrix)
Sets the value of this quaternion to the rotation described by the given matrix.
|
Quaternion |
fromVectorToVector(SimpleVector from,
SimpleVector to)
Sets this quaternion to that which will rotate vector "from" into vector "to".
|
Matrix |
getRotationMatrix()
Returns matrix representation of this quaternion.
|
int |
hashCode() |
Quaternion |
invert()
inverse returns the inverse of this quaternion as a new
quaternion. |
boolean |
isIdentity() |
boolean |
isValid()
Check a quaternion...
|
float |
magnitude() |
float |
magnitudeSquared() |
Quaternion |
multiply(float qx,
float qy,
float qz,
float qw)
Multiplies this quaternion by the supplied quaternion values.
|
Quaternion |
multiply(Quaternion other) |
float |
norm()
norm returns the norm of this quaternion. |
Quaternion |
normalize()
Normalizes this quaternion.
|
Quaternion |
rotate(Matrix matrix)
Applies rotation of given matrix to this quaternion.
|
Quaternion |
rotateX(float angle)
Rotates the quaternion around X axis.
|
Quaternion |
rotateY(float angle)
Rotates the quaternion around Y axis.
|
Quaternion |
rotateZ(float angle)
Rotates the quaternion around Z axis.
|
Quaternion |
scalarMul(float scalar)
Multiplies each value of this quaternion by the given scalar value.
|
Quaternion |
set(float x,
float y,
float z,
float w)
Sets the value of this quaternion to (x, y, z, w)
|
Quaternion |
set(Quaternion source)
Sets the value of this quaternion to the (x, y, z, w) values of the provided source quaternion.
|
Quaternion |
setIdentity()
Sets the value of this quaternion to (0, 0, 0, 1).
|
Matrix |
setRotation(Matrix matrix)
Sets rotation part of given matrix to rotation represented by this quaternion.
|
Quaternion |
slerp(Quaternion source,
Quaternion dest,
float weight)
Does a spherical linear interpolation between the given start and end quaternions by the given change amount.
|
String |
toString() |
public static final Quaternion IDENTITY
public float x
public float y
public float z
public float w
public Quaternion()
public Quaternion(Quaternion source)
source
- public Quaternion(float x, float y, float z, float w)
x
- y
- z
- w
- public Quaternion(Matrix matrix)
fromMatrix(Matrix)
public Quaternion set(float x, float y, float z, float w)
x
- y
- z
- w
- public Quaternion set(Quaternion source)
source
- NullPointerException
- if source is null.public Quaternion fromMatrix(Matrix matrix)
matrix
- NullPointerException
- if matrix is null.public Quaternion fromAngleAxis(float angle, SimpleVector axis)
angle
- the angle to rotate (in radians).axis
- the axis of rotation.NullPointerException
- if axis is nullpublic Quaternion fromAngleNormalAxis(float angle, SimpleVector axis)
angle
- the angle to rotate (in radians).axis
- the axis of rotation (already normalized - unit length).NullPointerException
- if axis is nullpublic Quaternion fromVectorToVector(SimpleVector from, SimpleVector to)
from
- the source vector to rotateto
- the destination vector into which to rotate the source vectorpublic Quaternion normalize()
public Quaternion add(Quaternion quat)
quat
- the Quaternion to addpublic Quaternion calcSub(Quaternion quat)
quat
- the second Quaternionpublic Quaternion scalarMul(float scalar)
scalar
- the quaternion to multiply this quaternion by.public Quaternion multiply(Quaternion other)
public Quaternion multiply(float qx, float qy, float qz, float qw)
qx
- qy
- qz
- qw
- public Quaternion fromAxes(SimpleVector[] axes)
axes
- the array containing the three vectors representing the coordinate system.IllegalArgumentException
- if the given axes array is smaller than 3 elements.public Quaternion fromAxes(SimpleVector xAxis, SimpleVector yAxis, SimpleVector zAxis)
xAxis
- vector representing the x-axis of the coordinate system.yAxis
- vector representing the y-axis of the coordinate system.zAxis
- vector representing the z-axis of the coordinate system.public Quaternion slerp(Quaternion source, Quaternion dest, float weight)
source
- dest
- weight
- NullPointerException
- if startQuat or endQuat are null.public float magnitudeSquared()
public float magnitude()
magnitude()
)public float calcDot(Quaternion quat)
quat
- public Quaternion setIdentity()
public boolean isIdentity()
public boolean isValid()
public String toString()
public int hashCode()
public boolean equals(Object o)
public Quaternion clone()
public Matrix getRotationMatrix()
public Matrix setRotation(Matrix matrix)
matrix
- the matrix to store the resultpublic Quaternion rotateX(float angle)
Matrix.rotateX(float)
behind the scenes.public Quaternion rotateY(float angle)
Matrix.rotateY(float)
behind the scenes.public Quaternion rotateZ(float angle)
Matrix.rotateZ(float)
behind the scenes.public Quaternion rotate(Matrix matrix)
Matrix.matMul(Matrix)
behind the scenes.public Quaternion invert()
inverse
returns the inverse of this quaternion as a new
quaternion. If this quaternion does not have an inverse (if its normal is
0 or less), then an IllegalStateException is thrown.IllegalStateException
- if can not be invertedpublic float norm()
norm
returns the norm of this quaternion. This is the dot
product of this quaternion with itself.