public final class DQuaternion extends java.lang.Object implements Savable, java.lang.Cloneable, java.io.Serializable
DQuaternion
defines a single example of a more general class of
hypercomplex numbers. DQuaternions extends a rotation in three dimensions to a
rotation in four dimensions. This avoids "gimbal lock" and allows for smooth
continuous rotation.
DQuaternion
is defined by four double point numbers: {x y z w}.
This class's only purpose is to give better accuracy in floating point operations during computations.
This is made by copying the original Quaternion class from jme3 core and leaving only required methods and basic computation methods, so that
the class is smaller and easier to maintain.
Should any other methods be needed, they will be added.Modifier and Type | Field and Description |
---|---|
static DQuaternion |
DIRECTION_Z |
static DQuaternion |
IDENTITY
Represents the identity quaternion rotation (0, 0, 0, 1).
|
protected double |
w |
protected double |
x |
protected double |
y |
protected double |
z |
static DQuaternion |
ZERO |
Constructor and Description |
---|
DQuaternion()
Constructor instantiates a new
DQuaternion object
initializing all values to zero, except w which is initialized to 1. |
DQuaternion(double x,
double y,
double z,
double w)
Constructor instantiates a new
DQuaternion object from the
given list of parameters. |
DQuaternion(Quaternion q) |
Modifier and Type | Method and Description |
---|---|
DQuaternion |
add(DQuaternion q)
add adds the values of this quaternion to those of the
parameter quaternion. |
DQuaternion |
addLocal(DQuaternion q)
add adds the values of this quaternion to those of the
parameter quaternion. |
DQuaternion |
clone() |
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. |
DQuaternion |
fromAngleAxis(double angle,
Vector3d axis)
fromAngleAxis sets this quaternion to the values specified
by an angle and an axis of rotation. |
DQuaternion |
fromAngleNormalAxis(double angle,
Vector3d axis)
fromAngleNormalAxis sets this quaternion to the values
specified by an angle and a normalized axis of rotation. |
DQuaternion |
fromRotationMatrix(double m00,
double m01,
double m02,
double m10,
double m11,
double m12,
double m20,
double m21,
double m22) |
double |
getW() |
double |
getX() |
double |
getY() |
double |
getZ() |
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. |
void |
loadIdentity()
Sets this DQuaternion to {0, 0, 0, 1}.
|
DQuaternion |
mult(DQuaternion q)
mult multiplies this quaternion by a parameter quaternion. |
DQuaternion |
mult(DQuaternion q,
DQuaternion res)
mult multiplies this quaternion by a parameter quaternion. |
Vector3d |
mult(Vector3d v)
mult multiplies this quaternion by a parameter vector. |
Vector3d |
mult(Vector3d v,
Vector3d store)
mult multiplies this quaternion by a parameter vector. |
DQuaternion |
multLocal(DQuaternion q)
Multiplies this DQuaternion by the supplied quaternion.
|
double |
norm()
norm returns the norm of this quaternion. |
void |
read(JmeImporter e) |
DQuaternion |
set(double x,
double y,
double z,
double w)
sets the data in a
DQuaternion object from the given list
of parameters. |
DQuaternion |
set(DQuaternion q)
Sets the data in this
DQuaternion object to be equal to the
passed DQuaternion object. |
DQuaternion |
subtract(DQuaternion q)
subtract subtracts the values of the parameter quaternion
from those of this quaternion. |
DQuaternion |
subtractLocal(DQuaternion q)
subtract subtracts the values of the parameter quaternion
from those of this quaternion. |
Quaternion |
toQuaternion() |
Matrix |
toRotationMatrix(Matrix result)
toRotationMatrix converts this quaternion to a rotational
matrix. |
java.lang.String |
toString()
toString creates the string representation of this DQuaternion . |
void |
write(JmeExporter e) |
public static final DQuaternion IDENTITY
public static final DQuaternion DIRECTION_Z
public static final DQuaternion ZERO
protected double x
protected double y
protected double z
protected double w
public DQuaternion()
DQuaternion
object
initializing all values to zero, except w which is initialized to 1.public DQuaternion(double x, double y, double z, double w)
DQuaternion
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 DQuaternion(Quaternion q)
public Quaternion toQuaternion()
public double getX()
public double getY()
public double getZ()
public double getW()
public DQuaternion set(double x, double y, double z, double w)
DQuaternion
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 DQuaternion set(DQuaternion q)
DQuaternion
object to be equal to the
passed DQuaternion
object. The values are copied producing
a new object.q
- The DQuaternion to copy values from.public void loadIdentity()
public double norm()
norm
returns the norm of this quaternion. This is the dot
product of this quaternion with itself.public DQuaternion fromRotationMatrix(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
public Matrix toRotationMatrix(Matrix 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.result
- The Matrix4f to store the result in.public DQuaternion fromAngleAxis(double angle, Vector3d 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 DQuaternion fromAngleNormalAxis(double angle, Vector3d 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 DQuaternion add(DQuaternion 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 DQuaternion addLocal(DQuaternion q)
add
adds the values of this quaternion to those of the
parameter quaternion. The result is stored in this DQuaternion.q
- the quaternion to add to this.public DQuaternion subtract(DQuaternion 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 DQuaternion subtractLocal(DQuaternion q)
subtract
subtracts the values of the parameter quaternion
from those of this quaternion. The result is stored in this DQuaternion.q
- the quaternion to subtract from this.public DQuaternion mult(DQuaternion 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 DQuaternion mult(DQuaternion q, DQuaternion 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 Vector3d mult(Vector3d 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 DQuaternion multLocal(DQuaternion q)
q
- The DQuaternion to multiply this one by.public Vector3d mult(Vector3d v, Vector3d 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 java.lang.String toString()
toString
creates the string representation of this DQuaternion
. The values of the quaternion are displaced (x,
y, z, w), in the following manner: toString
in class java.lang.Object
Object.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.Object
o
- the object to compare for equalitypublic 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.Object
Object.hashCode()
public void write(JmeExporter e) throws java.io.IOException
public void read(JmeImporter e) throws java.io.IOException
public DQuaternion clone()
clone
in class java.lang.Object