Package net.risingworld.api.utils
Klasse Quaternion
java.lang.Object
net.risingworld.api.utils.Quaternion
- Alle implementierten Schnittstellen:
Serializable
A quaternion which describes a rotation.
- Siehe auch:
-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final Quaternion
A quaternion representing no rotationfloat
The W value of this Quaternion (scalar part)float
The X value of this Quaternion (vector part)float
The Y value of this Quaternion (vector part)float
The Z value of this Quaternion (vector part)static final Quaternion
An "empty" quaternion. -
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungfloat
angle
(Quaternion quaternion) Gets the angle (in degrees) between this quaternion and the other quaternion.copy()
Creates a copy of this Quaternion.float
dot
(Quaternion quaternion) Gets the dot product of this quaternion with the provided quaternion.boolean
equals
(float x, float y, float z, float w) boolean
Gets whether or not this quaternion is equal to another object.fromAngles
(float[] angles) Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z).fromAngles
(float pitch, float yaw, float roll) Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z).fromString
(String input) float
getPitch()
Gets the pitch (aka attitude aka x euler angle) of this quaternion.float
getRoll()
Gets the roll (aka bank aka z euler angle) of this quaternion.float
getW()
Returns the W value of this Quaternion.float
getX()
Returns the X value of this Quaternion.float
getY()
Returns the Y value of this Quaternion.float
getYaw()
Gets the yaw (aka heading aka y euler angle) of this quaternion.float
getZ()
Returns the Z value of this Quaternion.int
hashCode()
Gets a unique* hash code for this quaternion, based on its values.inverse()
Gets the inverse of this quaternion as a new quaternion.Calculates the inverse of this quaternion and stores the result in this quaternion.boolean
isNaN()
Checks if this quaternion is invalid, or more precisely, if any of its values is NaN (not a number).Sets this quaternion to 0, 0, 0, 1.lookAt
(float directionx, float directiony, float directionz) "Looks at" a given direction, i.e the quaternion will be set based on the direction."Looks at" a given direction, i.e the quaternion will be set based on the direction."Looks at" a given direction, i.e the quaternion will be set based on the direction and an up vector.Multiplies the quaternion by a Vector3f.multLocal
(float scalar) Multiplies the quaternion by a scalar.multLocal
(float qx, float qy, float qz, float qw) Multiplies this quaternion by the provided values.multLocal
(Quaternion quaternion) Multiplies this quaternion by the provided quaternion.Multiplies the quaternion by a Vector3f.Negates the values of this quaternion.float
norm()
Gets the norm of this quaternion, i.e the dot product of this quaternion with itself.Gets the normalized quaternion as a new quaternion.Normalizes this quaternion.set
(float x, float y, float z, float w) Sets the X, Y, Z and W values of this Quaternion to the provided values.set
(Quaternion quaternion) Sets the X, Y, Z and W values of this Quaternion to the values of the provided quaternion.setW
(float w) Sets the Z value of this Quaternion.setX
(float x) Sets the X value of this Vector3f.setY
(float y) Sets the Y value of this Vector3f.setZ
(float z) Sets the Z value of this Quaternion.float[]
toAngles()
Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array.float[]
toAngles
(float[] storeTo) Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array.toString()
Gets a String representation of this quaternion, for example(0.0, 1.25, -0.7, 1.0)
-
Felddetails
-
IDENTITY
A quaternion representing no rotation -
ZERO
An "empty" quaternion. If you're looking for a quaternion with no rotation instead, check outIDENTITY
-
x
public float xThe X value of this Quaternion (vector part) -
y
public float yThe Y value of this Quaternion (vector part) -
z
public float zThe Z value of this Quaternion (vector part) -
w
public float wThe W value of this Quaternion (scalar part)
-
-
Konstruktordetails
-
Quaternion
public Quaternion() -
Quaternion
public Quaternion(float x, float y, float z, float w) -
Quaternion
-
-
Methodendetails
-
copy
Creates a copy of this Quaternion.- Gibt zurück:
- a new instance with the same values of this Quaternion.
-
set
Sets the X, Y, Z and W values of this Quaternion to the values of the provided quaternion.- Parameter:
quaternion
- the Quaternion to copy.- Gibt zurück:
- this Quaternion.
-
set
Sets the X, Y, Z and W values of this Quaternion to the provided values.- Parameter:
x
- the X value.y
- the Y value.z
- the Z value.w
- the W value.- Gibt zurück:
- this Quaternion.
-
setX
Sets the X value of this Vector3f.- Parameter:
x
- the new X value.- Gibt zurück:
- this Vector3f.
-
setY
Sets the Y value of this Vector3f.- Parameter:
y
- the new Y value.- Gibt zurück:
- this Vector3f.
-
setZ
Sets the Z value of this Quaternion.- Parameter:
z
- the new Z value.- Gibt zurück:
- this Quaternion.
-
setW
Sets the Z value of this Quaternion.- Parameter:
w
- the new W value.- Gibt zurück:
- this Quaternion.
-
getX
public float getX()Returns the X value of this Quaternion.- Gibt zurück:
- the current X value.
-
getY
public float getY()Returns the Y value of this Quaternion.- Gibt zurück:
- the current Y value.
-
getZ
public float getZ()Returns the Z value of this Quaternion.- Gibt zurück:
- the current Z value.
-
getW
public float getW()Returns the W value of this Quaternion.- Gibt zurück:
- the current W value.
-
getPitch
public float getPitch()Gets the pitch (aka attitude aka x euler angle) of this quaternion.- Gibt zurück:
- the pitch/attitude as euler angle in degrees.
-
getYaw
public float getYaw()Gets the yaw (aka heading aka y euler angle) of this quaternion.- Gibt zurück:
- the yaw/heading as euler angle in degrees.
-
getRoll
public float getRoll()Gets the roll (aka bank aka z euler angle) of this quaternion.- Gibt zurück:
- the roll/bank as euler angle in degrees.
-
loadIdentity
Sets this quaternion to 0, 0, 0, 1. i.e it does no longer represent any rotation.- Gibt zurück:
- this quaternion.
-
fromAngles
Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z). The rotation will be applied in the order: y, z, x- Parameter:
angles
- Euler rotation angles (pitch, yaw, roll) in degrees as a float array.- Gibt zurück:
- this quaternion.
-
fromAngles
Calculates this quaternion from the given Euler rotation angles (pitch, yaw, roll) aka (attitude, heading, bank) aka (x, y, z). The rotation will be applied in the order: x, y, z- Parameter:
pitch
- Euler pitch (attitude) rotation in degrees.yaw
- Euler yaw (heading) rotation in degrees.roll
- Euler roll (bank) rotation in degrees.- Gibt zurück:
- this quaternion.
- Siehe auch:
-
toAngles
public float[] toAngles()Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array.- Gibt zurück:
- a float array containing the Euler angles (pitch, yaw, roll).
-
toAngles
public float[] toAngles(float[] storeTo) Calculates the according Euler rotation angles (pitch, yaw, roll) for this quaternion and stores them in the provided float array. The angles are stored in degrees.- Parameter:
storeTo
- the float array in which the angles should be stored. This array needs to be able to hold at least three elements. If null is provided, a new float array will be created.- Gibt zurück:
- the float array containing the Euler angles (in degrees).
- Siehe auch:
-
angle
Gets the angle (in degrees) between this quaternion and the other quaternion.- Parameter:
quaternion
- the other quaternion.- Gibt zurück:
- the angle between the two quaternions (in degrees).
-
multLocal
Multiplies this quaternion by the provided quaternion. The result is stored in this quaternion.- Parameter:
quaternion
- the quaternion to multiply this one by.- Gibt zurück:
- this quaternion.
-
multLocal
Multiplies this quaternion by the provided values. The result is stored in this quaternion.- Parameter:
qx
- the x compontent to multiply this quaternion by.qy
- the y compontent to multiply this quaternion by.qz
- the z compontent to multiply this quaternion by.qw
- the w compontent to multiply this quaternion by.- Gibt zurück:
- this quaternion.
-
multLocal
Multiplies the quaternion by a scalar. The result is stored in this quaternion.- Parameter:
scalar
- the scalar value.- Gibt zurück:
- this quaternion.
-
multLocal
Multiplies the quaternion by a Vector3f. The result is stored in the vector. You can use this method to apply a rotation (represented by the quaternion) to a vector.- Parameter:
vector
- the Vector3f to multiply this quaternion by.- Gibt zurück:
- the vector.
-
mult
Multiplies the quaternion by a Vector3f. The result is returned as a new vector. You can use this method to apply a rotation (represented by the quaternion) to a vector.- Parameter:
vector
- the Vector3f to multiply this quaternion by.- Gibt zurück:
- a new vector.
- Example: Turn a rotation in a direction
-
negateLocal
Negates the values of this quaternion.- Gibt zurück:
- this quaternion.
-
inverse
Gets the inverse of this quaternion as a new quaternion. The inverse quaternion represents the same rotation, but in the opposite direction.
If this quaternion does not have an inverse, null is returned.- Gibt zurück:
- a new quaternion containing the inverse of this quaternion, or null if there is no inverse for this quaternion.
-
inverseLocal
Calculates the inverse of this quaternion and stores the result in this quaternion. The inverse quaternion represents the same rotation, but in the opposite direction.
If this quaternion does not have an inverse, nothing happens.- Gibt zurück:
- this quaternion containing the inverse of this quaternion.
-
normalize
Gets the normalized quaternion as a new quaternion.- Gibt zurück:
- a new quaternion containing the normalized values of this quaternion.
-
normalizeLocal
Normalizes this quaternion.- Gibt zurück:
- this quaternion.
-
dot
Gets the dot product of this quaternion with the provided quaternion.- Parameter:
quaternion
- the quaternion to calculate the dot product with.- Gibt zurück:
- the dot product.
-
norm
public float norm()Gets the norm of this quaternion, i.e the dot product of this quaternion with itself.- Gibt zurück:
- the norm of this quaternion.
-
lookAt
"Looks at" a given direction, i.e the quaternion will be set based on the direction. The resulting quaternion represents the rotation for transforming a z-axis to point into the given direction.- Parameter:
direction
- the direction (where to "look at").- Gibt zurück:
- this quaternion.
- Example:
- Example: Simplified version
-
lookAt
"Looks at" a given direction, i.e the quaternion will be set based on the direction. The resulting quaternion represents the rotation for transforming a z-axis to point into the given direction.- Parameter:
directionx
- the x component of the direction vector.directiony
- the y component of the direction vector.directionz
- the z component of the direction vector.- Gibt zurück:
- this quaternion.
- Siehe auch:
-
lookAt
"Looks at" a given direction, i.e the quaternion will be set based on the direction and an up vector. The resulting quaternion represents the rotation for transforming a z-axis to point into the given direction.- Parameter:
direction
- the direction (where to "look at").up
- the according up-vector, typically (0, 1, 0);- Gibt zurück:
- this quaternion.
- Siehe auch:
-
isNaN
public boolean isNaN()Checks if this quaternion is invalid, or more precisely, if any of its values is NaN (not a number).- Gibt zurück:
- true if this quaternion contains any NaN values, false if not.
-
equals
public boolean equals(float x, float y, float z, float w) -
equals
Gets whether or not this quaternion is equal to another object. This function returns true, if the other object is aQuaternion
and if it has exactly the same x, y, z and w values. -
hashCode
public int hashCode()Gets a unique* hash code for this quaternion, based on its values. If two quaternions have the same x, y, z and w values, they will return the same hash code.
* Please keep in mind that the uniqueness is not fully reliable. There is always a small chance that collisions occur (i.e two completely different quaternions return the same hash code). But usually the reliability is sufficient. -
toString
Gets a String representation of this quaternion, for example(0.0, 1.25, -0.7, 1.0)
-
fromString
-