public final class Quaternion
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Mathematically, quaternions are an extension of complex numbers. In mathematics texts, W often appears first, but in JME it always comes last.
| Modifier and Type | Field and Description |
|---|---|
static Quaternion |
DIRECTION_Z
Another shared instance of the identity quaternion (0, 0, 0, 1).
|
static Quaternion |
IDENTITY
Shared instance of the identity quaternion (0, 0, 0, 1).
|
protected float |
w
The real (W) component.
|
protected float |
x
The first imaginary (X) component.
|
protected float |
y
The 2nd imaginary (Y) component.
|
protected float |
z
The 3rd imaginary (Z) component.
|
static Quaternion |
ZERO
Shared instance of the zero quaternion (0, 0, 0, 0).
|
| Constructor and Description |
|---|
Quaternion()
Instantiates an identity quaternion: all components zeroed except
w, which is set to 1. |
Quaternion(float x,
float y,
float z,
float w)
Instantiates a quaternion with the specified components.
|
Quaternion(Quaternion q)
Instantiates a copy of the argument.
|
| Modifier and Type | Method and Description |
|---|---|
Quaternion |
addLocal(Quaternion q)
Adds the argument and returns the (modified) current instance.
|
Quaternion |
clone()
Creates a copy.
|
boolean |
equals(java.lang.Object o)
Tests for exact equality with the argument, distinguishing -0 from 0.
|
Quaternion |
fromAngleNormalAxis(float angle,
Vector3f axis)
Sets the quaternion from the specified rotation angle and normalized axis
of rotation.
|
Quaternion |
fromAngles(float xAngle,
float yAngle,
float zAngle)
Sets the quaternion from the specified Tait-Bryan angles, applying the
rotations in x-z-y extrinsic order or y-z'-x" intrinsic order.
|
Quaternion |
fromAxes(Vector3f xAxis,
Vector3f yAxis,
Vector3f zAxis)
Sets the quaternion from the specified orthonormal basis.
|
Quaternion |
fromRotationMatrix(float m00,
float m01,
float m02,
float m10,
float m11,
float m12,
float m20,
float m21,
float m22)
Sets the quaternion from a rotation matrix with the specified elements.
|
Quaternion |
fromRotationMatrix(Matrix3f matrix)
Sets the quaternion from the specified rotation matrix.
|
float |
getW()
Returns the W (real) component.
|
float |
getX()
Returns the X component.
|
float |
getY()
Returns the Y component.
|
float |
getZ()
Returns the Z component.
|
int |
hashCode()
Returns a hash code.
|
Quaternion |
inverse()
Returns the multiplicative inverse.
|
void |
loadIdentity()
Sets all components to zero except
w, which is set to 1. |
Quaternion |
mult(Quaternion q)
Multiplies by the argument and returns the product as a new instance.
|
Quaternion |
mult(Quaternion q,
Quaternion storeResult)
Multiplies by the specified quaternion and returns the product in a 3rd
quaternion.
|
Quaternion |
multLocal(float scalar)
Multiplies by the scalar argument and returns the (modified) current
instance.
|
Quaternion |
multLocal(float qx,
float qy,
float qz,
float qw)
Multiplies by a quaternion with the specified components and returns the
(modified) current instance.
|
Quaternion |
multLocal(Quaternion q)
Multiplies by the argument and returns the (modified) current instance.
|
float |
norm()
Returns the norm, defined as the dot product of the quaternion with
itself.
|
Quaternion |
normalizeLocal()
Scales the quaternion to have norm=1 and returns the (modified) current
instance.
|
Quaternion |
set(float x,
float y,
float z,
float w)
Sets all 4 components to specified values.
|
Quaternion |
set(Quaternion q)
Copies all 4 components from the argument.
|
Matrix3f |
toRotationMatrix()
Converts to an equivalent rotation matrix.
|
Matrix3f |
toRotationMatrix(Matrix3f result)
Converts to an equivalent rotation matrix.
|
Matrix4f |
toRotationMatrix(Matrix4f result)
Sets the rotation component of the specified transform matrix.
|
java.lang.String |
toString()
Returns a string representation of the quaternion, which is unaffected.
|
Matrix4f |
toTransformMatrix(Matrix4f store)
Sets the rotation component of the specified transform matrix.
|
public static final Quaternion IDENTITY
This is the usual representation for a null rotation.
public static final Quaternion DIRECTION_Z
public static final Quaternion ZERO
The zero quaternion doesn't represent any valid rotation.
protected float x
protected float y
protected float z
protected float w
public Quaternion()
w, which is set to 1.public Quaternion(float x,
float y,
float z,
float w)
x - the desired X componenty - the desired Y componentz - the desired Z componentw - the desired W componentpublic Quaternion(Quaternion q)
q - the quaternion to copy (not null, unaffected)public float getX()
x componentpublic float getY()
y componentpublic float getZ()
z componentpublic float getW()
w componentpublic Quaternion set(float x, float y, float z, float w)
x - the desired X componenty - the desired Y componentz - the desired Z componentw - the desired W componentpublic Quaternion set(Quaternion q)
q - the quaternion to copy (not null, unaffected)public void loadIdentity()
w, which is set to 1.public Quaternion fromAngles(float xAngle, float yAngle, float zAngle)
xAngle - the X angle (in radians)yAngle - the Y angle (in radians)zAngle - the Z angle (in radians)public Quaternion fromRotationMatrix(Matrix3f matrix)
Does not verify that the argument is a valid rotation matrix. Positive scaling is compensated for, but not reflection or shear.
matrix - the input matrix (not null, unaffected)public Quaternion fromRotationMatrix(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
Does not verify that the arguments form a valid rotation matrix. Positive scaling is compensated for, but not reflection or shear.
m00 - the matrix element in row 0, column 0m01 - the matrix element in row 0, column 1m02 - the matrix element in row 0, column 2m10 - the matrix element in row 1, column 0m11 - the matrix element in row 1, column 1m12 - the matrix element in row 1, column 2m20 - the matrix element in row 2, column 0m21 - the matrix element in row 2, column 1m22 - the matrix element in row 2, column 2public Matrix3f toRotationMatrix()
Note: the result is created from a normalized version of the current instance.
public Matrix3f toRotationMatrix(Matrix3f result)
Note: the result is created from a normalized version of the current instance.
result - storage for the result (not null)result, configured as a 3x3 rotation matrixpublic Matrix4f toTransformMatrix(Matrix4f store)
Note: preserves the translation component of store but not
its scaling component.
Note: the result is created from a normalized version of the current instance.
store - storage for the result (not null)store, with 9 of its 16 elements modifiedpublic Matrix4f toRotationMatrix(Matrix4f result)
Note: preserves the translation and scaling components of
result unless result includes reflection.
Note: the result is created from a normalized version of the current instance.
result - storage for the result (not null)result, with 9 of its 16 elements modifiedpublic Quaternion fromAngleNormalAxis(float angle, Vector3f axis)
angle - the desired rotation angle (in radians)axis - the desired axis of rotation (not null, length=1, unaffected)public Quaternion addLocal(Quaternion q)
Seldom used. To combine rotations, use
multLocal(com.jme3.math.Quaternion) or
mult(com.jme3.math.Quaternion, com.jme3.math.Quaternion)
instead of this method.
q - the quaternion to add (not null, unaffected unless it's
this)public Quaternion mult(Quaternion q)
This method is used to combine rotations. Note that quaternion multiplication is noncommutative, so generally q * p != p * q.
q - the right factor (not null, unaffected)this * q (a new Quaternion)public Quaternion mult(Quaternion q, Quaternion storeResult)
storeResult.
This method is used to combine rotations. Note that quaternion multiplication is noncommutative, so generally q * p != p * q.
It is safe for q and storeResult to be the same object.
However, if this and storeResult are the same object, the result
is undefined.
q - the right factor (not null, unaffected unless it's storeResult)storeResult - storage for the product, or null for a new Quaternionthis * q (either storeResult or a new Quaternion)public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis)
The 3 basis vectors describe the axes of a rotated coordinate system. They are assumed to be normalized, mutually orthogonal, and in right-hand order. No error checking is performed; the caller must ensure that the specified vectors represent a right-handed coordinate system.
xAxis - the X axis of the desired coordinate system (not null,
length=1, unaffected)yAxis - the Y axis of the desired coordinate system (not null,
length=1, unaffected)zAxis - the Z axis of the desired coordinate system (not null,
length=1, unaffected)public Quaternion multLocal(Quaternion q)
This method is used to combine rotations. Note that quaternion multiplication is noncommutative, so generally q * p != p * q.
q - the right factor (not null, unaffected unless it's this)public Quaternion multLocal(float qx, float qy, float qz, float qw)
This method is used to combine rotations. Note that quaternion multiplication is noncommutative, so generally q * p != p * q.
qx - the X component of the right factorqy - the Y component of the right factorqz - the Z component of the right factorqw - the W component of the right factorpublic Quaternion multLocal(float scalar)
scalar - the scaling factorpublic float norm()
public Quaternion normalizeLocal()
public Quaternion inverse()
public java.lang.String toString()
(0.0, 0.0, 0.0, 1.0)
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
o is null, false is returned. Either way, the current instance is
unaffected.equals in class java.lang.Objecto - the object to compare (may be null, unaffected)this and o have identical values,
otherwise falsepublic int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()public Quaternion clone()
clone in class java.lang.Object