Package com.google.ar.sceneform.math
Class Quaternion
- java.lang.Object
-
- com.google.ar.sceneform.math.Quaternion
-
public class Quaternion extends java.lang.Object
A Sceneform quaternion class for floats.Quaternion operations are Hamiltonian using the right-hand-rule convention.
-
-
Constructor Summary
Constructors Constructor Description Quaternion()
Construct Quaternion and set to IdentityQuaternion(float x, float y, float z, float w)
Construct Quaternion and set each value.Quaternion(Quaternion q)
Construct Quaternion using values from another QuaternionQuaternion(Vector3 eulerAngles)
Construct Quaternion based on eulerAngles.Quaternion(Vector3 axis, float angle)
Construct Quaternion using an axis/angle to define the rotation
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Quaternion
axisAngle(Vector3 axis, float degrees)
Get a new Quaternion using an axis/angle to define the rotationstatic boolean
equals(Quaternion lhs, Quaternion rhs)
Compare two Quaternionsboolean
equals(java.lang.Object other)
Returns true if the other object is a Quaternion and the dot product is 1.0 +/- a tolerance.static Quaternion
eulerAngles(Vector3 eulerAngles)
Get a new Quaternion using eulerAngles to define the rotation.int
hashCode()
static Quaternion
identity()
Get a Quaternion set to identitystatic Vector3
inverseRotateVector(Quaternion q, Vector3 src)
Quaternion
inverted()
Get a Quaternion with the opposite rotationstatic Quaternion
lookRotation(Vector3 forwardInWorld, Vector3 desiredUpInWorld)
Get a new Quaternion representing a rotation towards a specified forward direction.static Quaternion
multiply(Quaternion lhs, Quaternion rhs)
Create a Quaternion by combining two Quaternions multiply(lhs, rhs) is equivalent to performing the rhs rotation then lhs rotation Ordering is important for this operation.boolean
normalize()
Rescales the quaternion to the unit length.Quaternion
normalized()
Get a Quaternion with a matching rotation but scaled to unit length.static Vector3
rotateVector(Quaternion q, Vector3 src)
Rotates a Vector3 by a Quaternionstatic Quaternion
rotationBetweenVectors(Vector3 start, Vector3 end)
Get a new Quaternion representing the rotation from one vector to another.void
set(float qx, float qy, float qz, float qw)
Set each value and normalize the Quaternionvoid
set(Quaternion q)
Copy values from another Quaternion into this onevoid
set(Vector3 axis, float angle)
Update this Quaternion using an axis/angle to define the rotationvoid
setIdentity()
Set the Quaternion to identitystatic Quaternion
slerp(Quaternion start, Quaternion end, float t)
java.lang.String
toString()
-
-
-
Constructor Detail
-
Quaternion
public Quaternion()
Construct Quaternion and set to Identity
-
Quaternion
public Quaternion(float x, float y, float z, float w)
Construct Quaternion and set each value. The Quaternion will be normalized during construction
-
Quaternion
public Quaternion(Quaternion q)
Construct Quaternion using values from another Quaternion
-
Quaternion
public Quaternion(Vector3 axis, float angle)
Construct Quaternion using an axis/angle to define the rotation- Parameters:
axis
- Sets rotation directionangle
- Angle size in degrees
-
Quaternion
public Quaternion(Vector3 eulerAngles)
Construct Quaternion based on eulerAngles.- Parameters:
eulerAngles
- - the angle in degrees for each axis.- See Also:
eulerAngles(Vector3 eulerAngles)
-
-
Method Detail
-
set
public void set(Quaternion q)
Copy values from another Quaternion into this one
-
set
public void set(Vector3 axis, float angle)
Update this Quaternion using an axis/angle to define the rotation
-
set
public void set(float qx, float qy, float qz, float qw)
Set each value and normalize the Quaternion
-
setIdentity
public void setIdentity()
Set the Quaternion to identity
-
normalize
public boolean normalize()
Rescales the quaternion to the unit length.If the Quaternion can not be scaled, it is set to identity and false is returned.
- Returns:
- true if the Quaternion was non-zero
-
normalized
public Quaternion normalized()
Get a Quaternion with a matching rotation but scaled to unit length.- Returns:
- the quaternion scaled to the unit length, or zero if that can not be done.
-
inverted
public Quaternion inverted()
Get a Quaternion with the opposite rotation- Returns:
- the opposite rotation
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
rotateVector
public static Vector3 rotateVector(Quaternion q, Vector3 src)
Rotates a Vector3 by a Quaternion- Returns:
- The rotated vector
-
inverseRotateVector
public static Vector3 inverseRotateVector(Quaternion q, Vector3 src)
-
multiply
public static Quaternion multiply(Quaternion lhs, Quaternion rhs)
Create a Quaternion by combining two Quaternions multiply(lhs, rhs) is equivalent to performing the rhs rotation then lhs rotation Ordering is important for this operation.- Returns:
- The combined rotation
-
slerp
public static Quaternion slerp(Quaternion start, Quaternion end, float t)
-
axisAngle
public static Quaternion axisAngle(Vector3 axis, float degrees)
Get a new Quaternion using an axis/angle to define the rotation- Parameters:
axis
- Sets rotation directiondegrees
- Angle size in degrees
-
eulerAngles
public static Quaternion eulerAngles(Vector3 eulerAngles)
Get a new Quaternion using eulerAngles to define the rotation.The rotations are applied in Z, Y, X order. This is consistent with other graphics engines. One thing to note is the coordinate systems are different between Sceneform and Unity, so the same angles used here will have cause a different orientation than Unity. Carefully check your parameter values to get the same effect as in other engines.
- Parameters:
eulerAngles
- - the angles in degrees.
-
rotationBetweenVectors
public static Quaternion rotationBetweenVectors(Vector3 start, Vector3 end)
Get a new Quaternion representing the rotation from one vector to another.
-
lookRotation
public static Quaternion lookRotation(Vector3 forwardInWorld, Vector3 desiredUpInWorld)
Get a new Quaternion representing a rotation towards a specified forward direction. If upInWorld is orthogonal to forwardInWorld, then the Y axis is aligned with desiredUpInWorld.
-
equals
public static boolean equals(Quaternion lhs, Quaternion rhs)
Compare two QuaternionsTests for equality by calculating the dot product of lhs and rhs. lhs and -lhs will not be equal according to this function.
-
equals
public boolean equals(java.lang.Object other)
Returns true if the other object is a Quaternion and the dot product is 1.0 +/- a tolerance.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
identity
public static Quaternion identity()
Get a Quaternion set to identity
-
-