public final class Quaternion extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
Quaternion defines a single example of a more general class of
 hypercomplex numbers. Quaternions extends a rotation in three dimensions to a
 rotation in four dimensions. This avoids "gimbal lock" and allows for smooth
 continuous rotation.
 Quaternion is defined by four floating point numbers: {x y z w}.| Modifier and Type | Field and Description | 
|---|---|
static Quaternion | 
DIRECTION_Z
another instance of the identity Quaternion (0, 0, 0, 1) 
 | 
static Quaternion | 
IDENTITY
Represents the identity quaternion rotation (0, 0, 0, 1). 
 | 
protected float | 
w
the W (real) component (not an angle!) 
 | 
protected float | 
x
the X component (not an angle!) 
 | 
protected float | 
y
the Y component (not an angle!) 
 | 
protected float | 
z
the Z component (not an angle!) 
 | 
static Quaternion | 
ZERO
The zero quaternion (0, 0, 0, 0) doesn't represent any rotation. 
 | 
| Constructor and Description | 
|---|
Quaternion()
Constructor instantiates a new  
Quaternion object
 initializing all values to zero, except w which is initialized to 1. | 
Quaternion(float[] angles)
Instantiate a new  
Quaternion from Tait-Bryan angles,
 applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic
 order. | 
Quaternion(float x,
          float y,
          float z,
          float w)
Constructor instantiates a new  
Quaternion object from the
 given list of parameters. | 
Quaternion(Quaternion q)
Constructor instantiates a new  
Quaternion object from an
 existing quaternion, creating a copy. | 
Quaternion(Quaternion q1,
          Quaternion q2,
          float interp)
Constructor instantiates a new  
Quaternion object from an
 interpolation between two other quaternions. | 
| Modifier and Type | Method and Description | 
|---|---|
Quaternion | 
add(Quaternion q)
add adds the values of this quaternion to those of the
 parameter quaternion. | 
Quaternion | 
addLocal(Quaternion q)
add adds the values of this quaternion to those of the
 parameter quaternion. | 
void | 
apply(Matrix3f matrix)
apply multiplies this quaternion by a parameter matrix
 internally. | 
Quaternion | 
clone()
Create a copy of this quaternion. 
 | 
float | 
dot(Quaternion q)
dot calculates and returns the dot product of this
 quaternion with that of the parameter quaternion. | 
boolean | 
equals(java.lang.Object o)
equals determines if two quaternions are logically equal,
 that is, if the values of (x, y, z, w) are the same for both quaternions. | 
Quaternion | 
fromAngleAxis(float angle,
             Vector3f axis)
fromAngleAxis sets this quaternion to the values specified
 by an angle and an axis of rotation. | 
Quaternion | 
fromAngleNormalAxis(float angle,
                   Vector3f axis)
fromAngleNormalAxis sets this quaternion to the values
 specified by an angle and a normalized axis of rotation. | 
Quaternion | 
fromAngles(float[] angles)
Reconfigure this  
Quaternion based on Tait-Bryan angles,
 applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic
 order. | 
Quaternion | 
fromAngles(float xAngle,
          float yAngle,
          float zAngle)
Reconfigure this Quaternion based on Tait-Bryan rotations, applying the
 rotations in x-z-y extrinsic order or y-z'-x" intrinsic order. 
 | 
Quaternion | 
fromAxes(Vector3f[] axis)
fromAxes creates a Quaternion that
 represents the coordinate system defined by three axes. | 
Quaternion | 
fromAxes(Vector3f xAxis,
        Vector3f yAxis,
        Vector3f zAxis)
fromAxes creates a Quaternion that
 represents the coordinate system defined by three axes. | 
Quaternion | 
fromRotationMatrix(float m00,
                  float m01,
                  float m02,
                  float m10,
                  float m11,
                  float m12,
                  float m20,
                  float m21,
                  float m22)
Set this quaternion based on a rotation matrix with the specified
 elements. 
 | 
Quaternion | 
fromRotationMatrix(Matrix3f matrix)
fromRotationMatrix generates a quaternion from a supplied
 matrix. | 
Vector3f | 
getRotationColumn(int i)
getRotationColumn returns one of three columns specified
 by the parameter. | 
Vector3f | 
getRotationColumn(int i,
                 Vector3f store)
getRotationColumn returns one of three columns specified
 by the parameter. | 
float | 
getW()
Determine the W (real) component. 
 | 
float | 
getX()
Determine the X component. 
 | 
float | 
getY()
Determine the Y component. 
 | 
float | 
getZ()
Determine the Z component. 
 | 
int | 
hashCode()
hashCode returns the hash code value as an integer and is
 supported for the benefit of hashing based collection classes such as
 Hashtable, HashMap, HashSet etc. | 
Quaternion | 
inverse()
inverse returns the inverse of this quaternion as a new
 quaternion. | 
Quaternion | 
inverseLocal()
inverse calculates the inverse of this quaternion and
 returns this quaternion after it is calculated. | 
boolean | 
isIdentity()  | 
boolean | 
isSimilar(Quaternion other,
         float epsilon)
Returns true if this quaternion is similar to the specified quaternion
 within some value of epsilon. 
 | 
void | 
loadIdentity()
Sets this Quaternion to {0, 0, 0, 1}. 
 | 
Quaternion | 
lookAt(Vector3f direction,
      Vector3f up)
lookAt is a convenience method for auto-setting the
 quaternion based on a direction and an up vector. | 
Quaternion | 
mult(float scalar)
mult multiplies this quaternion by a parameter scalar. | 
Quaternion | 
mult(Quaternion q)
mult multiplies this quaternion by a parameter quaternion. | 
Quaternion | 
mult(Quaternion q,
    Quaternion res)
mult multiplies this quaternion by a parameter quaternion. | 
Vector3f | 
mult(Vector3f v)
mult multiplies this quaternion by a parameter vector. | 
Vector3f | 
mult(Vector3f v,
    Vector3f store)
mult multiplies this quaternion by a parameter vector. | 
Quaternion | 
multLocal(float scalar)
mult multiplies this quaternion by a parameter scalar. | 
Quaternion | 
multLocal(float qx,
         float qy,
         float qz,
         float qw)
Multiplies this Quaternion by the supplied quaternion. 
 | 
Quaternion | 
multLocal(Quaternion q)
Multiplies this Quaternion by the supplied quaternion. 
 | 
Vector3f | 
multLocal(Vector3f v)
mult multiplies this quaternion by a parameter vector. | 
void | 
negate()
Flip the signs of all components of this Quaternion. 
 | 
void | 
nlerp(Quaternion q2,
     float blend)
Sets the values of this quaternion to the nlerp from itself to q2 by blend. 
 | 
float | 
norm()
norm returns the norm of this quaternion. | 
Quaternion | 
normalizeLocal()
normalize normalizes the current Quaternion. | 
Quaternion | 
opposite()  | 
Quaternion | 
opposite(Quaternion store)
FIXME: This seems to have singularity type issues with angle == 0, possibly others such as PI. 
 | 
Quaternion | 
oppositeLocal()  | 
void | 
read(JmeImporter e)
De-serialize this quaternion from the specified importer, for example
 when loading from a J3O file. 
 | 
void | 
readExternal(java.io.ObjectInput in)
readExternal builds a quaternion from an
 ObjectInput object. | 
Quaternion | 
set(float x,
   float y,
   float z,
   float w)
sets the data in a  
Quaternion object from the given list of
 parameters. | 
Quaternion | 
set(Quaternion q)
Sets the data in this  
Quaternion object to be equal to the
 passed Quaternion object. | 
void | 
slerp(Quaternion q2,
     float changeAmnt)
Sets the values of this quaternion to the slerp from itself to q2 by
 changeAmnt 
 | 
Quaternion | 
slerp(Quaternion q1,
     Quaternion q2,
     float t)
slerp sets this quaternion's value as an interpolation
 between two other quaternions. | 
Quaternion | 
subtract(Quaternion q)
subtract subtracts the values of the parameter quaternion
 from those of this quaternion. | 
Quaternion | 
subtractLocal(Quaternion q)
subtract subtracts the values of the parameter quaternion
 from those of this quaternion. | 
float | 
toAngleAxis(Vector3f axisStore)
toAngleAxis sets a given angle and axis to that
 represented by the current quaternion. | 
float[] | 
toAngles(float[] angles)
Convert this  
Quaternion to Tait-Bryan angles, to be applied
 in x-z-y intrinsic order or y-z'-x" extrinsic order, for instance by
 fromAngles(float[]). | 
void | 
toAxes(Vector3f[] axes)
toAxes determines the axes of the coordinate system
 described by this Quaternion. | 
Matrix3f | 
toRotationMatrix()
toRotationMatrix converts this quaternion to a rotational
 matrix. | 
Matrix3f | 
toRotationMatrix(Matrix3f result)
toRotationMatrix converts this quaternion to a rotational
 matrix. | 
Matrix4f | 
toRotationMatrix(Matrix4f result)
toRotationMatrix converts this quaternion to a rotational
 matrix. | 
java.lang.String | 
toString()
toString returns a string representation of this
 Quaternion. | 
Matrix4f | 
toTransformMatrix(Matrix4f store)
toTransformMatrix converts this quaternion to a transform
 matrix. | 
void | 
write(JmeExporter e)
Serialize this quaternion to the specified exporter, for example when
 saving to a J3O file. 
 | 
void | 
writeExternal(java.io.ObjectOutput out)
writeExternal writes this quaternion out to a
 ObjectOutput object. | 
public static final Quaternion IDENTITY
public static final Quaternion DIRECTION_Z
public static final Quaternion ZERO
protected float x
protected float y
protected float z
protected float w
public Quaternion()
Quaternion object
 initializing all values to zero, except w which is initialized to 1.public Quaternion(float x,
                  float y,
                  float z,
                  float w)
Quaternion object from the
 given list of parameters.x - the x value of the quaternion.y - the y value of the quaternion.z - the z value of the quaternion.w - the w value of the quaternion.public Quaternion(float[] angles)
Quaternion from Tait-Bryan angles,
 applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic
 order.angles - an array of Tait-Bryan angles (in radians, exactly 3
 elements, the X angle in angles[0], the Y angle in angles[1], and the Z
 angle in angles[2], unaffected)public Quaternion(Quaternion q1, Quaternion q2, float interp)
Quaternion object from an
 interpolation between two other quaternions.q1 - the first quaternion.q2 - the second quaternion.interp - the amount to interpolate between the two quaternions.public Quaternion(Quaternion q)
Quaternion object from an
 existing quaternion, creating a copy.q - the quaternion to copy.public float getX()
public float getY()
public float getZ()
public float getW()
public Quaternion set(float x, float y, float z, float w)
Quaternion object from the given list of
 parameters.x - the x value of the quaternion.y - the y value of the quaternion.z - the z value of the quaternion.w - the w value of the quaternion.public Quaternion set(Quaternion q)
Quaternion object to be equal to the
 passed Quaternion object. The values are copied producing
 a new object.q - The Quaternion to copy values from.public void loadIdentity()
public boolean isIdentity()
public Quaternion fromAngles(float[] angles)
Quaternion based on Tait-Bryan angles,
 applying the rotations in x-z-y extrinsic order or y-z'-x" intrinsic
 order.angles - an array of Tait-Bryan angles (in radians, exactly 3
 elements, the X angle in angles[0], the Y angle in angles[1], and the Z
 angle in angles[2], unaffected)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 float[] toAngles(float[] angles)
Quaternion to Tait-Bryan angles, to be applied
 in x-z-y intrinsic order or y-z'-x" extrinsic order, for instance by
 fromAngles(float[]).
 Note that the result is not always 100% accurate due to the implications
 of Tait-Bryan angles.angles - an array of 3 floats in which to store the result, or else
 null (If null, a new array will be allocated.)public Quaternion fromRotationMatrix(Matrix3f matrix)
fromRotationMatrix generates a quaternion from a supplied
 matrix. This matrix is assumed to be a rotational matrix.matrix - the matrix that defines the rotation.public Quaternion fromRotationMatrix(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
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()
toRotationMatrix converts this quaternion to a rotational
 matrix. Note: the result is created from a normalized version of this quat.public Matrix3f toRotationMatrix(Matrix3f result)
toRotationMatrix converts this quaternion to a rotational
 matrix. The result is stored in result.result - The Matrix3f to store the result in.public Matrix4f toTransformMatrix(Matrix4f store)
toTransformMatrix converts this quaternion to a transform
 matrix. The result is stored in result.
 Note this method won't preserve the scale of the given matrix.store - The Matrix3f to store the result in.public Matrix4f toRotationMatrix(Matrix4f result)
toRotationMatrix converts this quaternion to a rotational
 matrix. The result is stored in result. 4th row and 4th column values are
 untouched. Note: the result is created from a normalized version of this quat.
 Note that this method will preserve the scale of the given matrixresult - The Matrix4f to store the result in.public Vector3f getRotationColumn(int i)
getRotationColumn returns one of three columns specified
 by the parameter. This column is returned as a Vector3f
 object.i - the column to retrieve. Must be between 0 and 2.public Vector3f getRotationColumn(int i, Vector3f store)
getRotationColumn returns one of three columns specified
 by the parameter. This column is returned as a Vector3f
 object. The value is retrieved as if this quaternion was first normalized.i - the column to retrieve. Must be between 0 and 2.store - the vector object to store the result in. if null, a new one
            is created.public Quaternion fromAngleAxis(float angle, Vector3f axis)
fromAngleAxis sets this quaternion to the values specified
 by an angle and an axis of rotation. This method creates an object, so
 use fromAngleNormalAxis if your axis is already normalized.angle - the angle to rotate (in radians).axis - the axis of rotation.public Quaternion fromAngleNormalAxis(float angle, Vector3f axis)
fromAngleNormalAxis sets this quaternion to the values
 specified by an angle and a normalized axis of rotation.angle - the angle to rotate (in radians).axis - the axis of rotation (already normalized).public float toAngleAxis(Vector3f axisStore)
toAngleAxis sets a given angle and axis to that
 represented by the current quaternion. The values are stored as
 follows: The axis is provided as a parameter and built by the method,
 the angle is returned as a float.axisStore - the object we'll store the computed axis in.public Quaternion slerp(Quaternion q1, Quaternion q2, float t)
slerp sets this quaternion's value as an interpolation
 between two other quaternions.q1 - the first quaternion.q2 - the second quaternion.t - the amount to interpolate between the two quaternions.public void slerp(Quaternion q2, float changeAmnt)
q2 - Final interpolation valuechangeAmnt - The amount differencepublic void nlerp(Quaternion q2, float blend)
q2 - the desired final value when blend=1 (not null, unaffected)blend - the fractional weight applied to q2 (0→this, 1→q2)public Quaternion add(Quaternion q)
add adds the values of this quaternion to those of the
 parameter quaternion. The result is returned as a new quaternion.q - the quaternion to add to this.public Quaternion addLocal(Quaternion q)
add adds the values of this quaternion to those of the
 parameter quaternion. The result is stored in this Quaternion.q - the quaternion to add to this.public Quaternion subtract(Quaternion q)
subtract subtracts the values of the parameter quaternion
 from those of this quaternion. The result is returned as a new
 quaternion.q - the quaternion to subtract from this.public Quaternion subtractLocal(Quaternion q)
subtract subtracts the values of the parameter quaternion
 from those of this quaternion. The result is stored in this Quaternion.q - the quaternion to subtract from this.public Quaternion mult(Quaternion q)
mult multiplies this quaternion by a parameter quaternion.
 The result is returned as a new quaternion. It should be noted that
 quaternion multiplication is not commutative so q * p != p * q.q - the quaternion to multiply this quaternion by.public Quaternion mult(Quaternion q, Quaternion res)
mult multiplies this quaternion by a parameter quaternion.
 The result is returned as a new quaternion. It should be noted that
 quaternion multiplication is not commutative so q * p != p * q.
 It IS safe for q and res to be the same object.
 It IS NOT safe for this and res to be the same object.q - the quaternion to multiply this quaternion by.res - the quaternion to store the result in.public void apply(Matrix3f matrix)
apply multiplies this quaternion by a parameter matrix
 internally.matrix - the matrix to apply to this quaternion.public Quaternion fromAxes(Vector3f[] axis)
fromAxes creates a Quaternion that
 represents the coordinate system defined by three axes. These axes are
 assumed to be orthogonal and no error checking is applied. Thus, the user
 must insure that the three axes being provided indeed represents a proper
 right handed coordinate system.axis - the array containing the three vectors representing the
            coordinate system.public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis)
fromAxes creates a Quaternion that
 represents the coordinate system defined by three axes. These axes are
 assumed to be orthogonal and no error checking is applied. Thus, the user
 must insure that the three axes being provided indeed represents a proper
 right handed coordinate system.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 void toAxes(Vector3f[] axes)
toAxes determines the axes of the coordinate system
 described by this Quaternion.axes - an array to store the results (not null, length=3, modified)public Vector3f mult(Vector3f v)
mult multiplies this quaternion by a parameter vector. The
 result is returned as a new vector.v - the vector to multiply this quaternion by.public Vector3f multLocal(Vector3f v)
mult multiplies this quaternion by a parameter vector. The
 result is stored in the supplied vectorv - the vector to multiply this quaternion by.public Quaternion multLocal(Quaternion q)
q - The Quaternion to multiply this one by.public Quaternion multLocal(float qx, float qy, float qz, float qw)
qx - quat x valueqy - quat y valueqz - quat z valueqw - quat w valuepublic Vector3f mult(Vector3f v, Vector3f store)
mult multiplies this quaternion by a parameter vector. The
 result is returned as a new vector.v - the vector to multiply this quaternion by.store - the vector to store the result in. It IS safe for v and store
            to be the same object.public Quaternion mult(float scalar)
mult multiplies this quaternion by a parameter scalar. The
 result is returned as a new quaternion.scalar - the scalar to multiply this quaternion by.public Quaternion multLocal(float scalar)
mult multiplies this quaternion by a parameter scalar. The
 result is stored locally.scalar - the scalar to multiply this quaternion by.public float dot(Quaternion q)
dot calculates and returns the dot product of this
 quaternion with that of the parameter quaternion.q - the quaternion to calculate the dot product of.public float norm()
norm returns the norm of this quaternion. This is the dot
 product of this quaternion with itself.public Quaternion normalizeLocal()
normalize normalizes the current Quaternion.
 The result is stored internally.public Quaternion inverse()
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 null is returned.public Quaternion inverseLocal()
inverse calculates the inverse of this quaternion and
 returns this quaternion after it is calculated. If this quaternion does
 not have an inverse (if its normal is 0 or less), nothing happenspublic void negate()
public java.lang.String toString()
toString returns a string representation of this
 Quaternion. The format is:
 (X.XXXX, Y.YYYY, Z.ZZZZ, W.WWWW)toString in class java.lang.ObjectObject.toString()public boolean equals(java.lang.Object o)
equals determines if two quaternions are logically equal,
 that is, if the values of (x, y, z, w) are the same for both quaternions.equals in class java.lang.Objecto - the object to compare for equalitypublic boolean isSimilar(Quaternion other, float epsilon)
other - the Quaternion to compare with (not null, unaffected)epsilon - the error tolerance for each componentpublic int hashCode()
hashCode returns the hash code value as an integer and is
 supported for the benefit of hashing based collection classes such as
 Hashtable, HashMap, HashSet etc.hashCode in class java.lang.ObjectObject.hashCode()public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
readExternal builds a quaternion from an
 ObjectInput object. in - the ObjectInput value to read from.java.io.IOException - if the ObjectInput value has problems reading a float.Externalizablepublic void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
writeExternal writes this quaternion out to a
 ObjectOutput object. NOTE: Used with serialization. Not to
 be called manually.out - the object to write to.java.io.IOException - if writing to the ObjectOutput fails.Externalizablepublic Quaternion lookAt(Vector3f direction, Vector3f up)
lookAt is a convenience method for auto-setting the
 quaternion based on a direction and an up vector. It computes
 the rotation to transform the z-axis to point into 'direction'
 and the y-axis to 'up'.  Note that the results will be invalid
 if a zero length direction vector (0,0,0) is supplied, or if the 
 direction and up vectors are parallel.direction - where to look at in terms of local coordinatesup - a vector indicating the local up direction.
            (typically {0, 1, 0} in jME.)public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter e) throws java.io.IOException
public Quaternion opposite()
public Quaternion opposite(Quaternion store)
store - A Quaternion to store our result in. If null, a new one is
            created.public Quaternion oppositeLocal()
public Quaternion clone()
clone in class java.lang.Object