A Sceneform quaternion class for floats.
Quaternion operations are Hamiltonian using the right-hand-rule convention.
Fields
public float | w | |
public float | x | |
public float | y | |
public float | z |
Public Constructors
Quaternion()
Construct Quaternion and set to Identity
|
|
Quaternion(float x, float y, float z, float w)
Construct Quaternion and set each value.
|
|
Quaternion(Vector3 axis, float angle)
Construct Quaternion using an axis/angle to define the rotation
|
|
Public Methods
static Quaternion | |
static boolean |
equals(Quaternion lhs, Quaternion rhs)
Compare two Quaternions
Tests for equality by calculating the dot product of lhs and rhs. |
boolean | |
static Quaternion | |
static Quaternion |
identity()
Get a Quaternion set to identity
|
static Vector3 | |
Quaternion |
inverted()
Get a Quaternion with the opposite rotation
|
static 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 | |
static 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 Quaternion
|
void | |
void | |
void |
setIdentity()
Set the Quaternion to identity
|
static Quaternion | |
String |
toString()
|
Inherited Methods
Fields
public float w
public float x
public float y
public float z
Public Constructors
public Quaternion ()
Construct Quaternion and set to Identity
public Quaternion (float x, float y, float z, float w)
Construct Quaternion and set each value. The Quaternion will be normalized during construction
Parameters
x | |
---|---|
y | |
z | |
w |
public Quaternion (Quaternion q)
Construct Quaternion using values from another Quaternion
Parameters
q |
---|
public Quaternion (Vector3 axis, float angle)
Construct Quaternion using an axis/angle to define the rotation
Parameters
axis | Sets rotation direction |
---|---|
angle | Angle size in degrees |
public Quaternion (Vector3 eulerAngles)
Construct Quaternion based on eulerAngles.
Parameters
eulerAngles | - the angle in degrees for each axis. |
---|
See Also
Public Methods
public static Quaternion axisAngle (Vector3 axis, float degrees)
Get a new Quaternion using an axis/angle to define the rotation
Parameters
axis | Sets rotation direction |
---|---|
degrees | Angle size in degrees |
public static boolean equals (Quaternion lhs, Quaternion rhs)
Compare two Quaternions
Tests for equality by calculating the dot product of lhs and rhs. lhs and -lhs will not be equal according to this function.
Parameters
lhs | |
---|---|
rhs |
public boolean equals (Object other)
Returns true if the other object is a Quaternion and the dot product is 1.0 +/- a tolerance.
Parameters
other |
---|
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. |
---|
public Quaternion inverted ()
Get a Quaternion with the opposite rotation
Returns
- the opposite rotation
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.
Parameters
forwardInWorld | |
---|---|
desiredUpInWorld |
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.
Parameters
lhs | |
---|---|
rhs |
Returns
- The combined rotation
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
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.
public static Vector3 rotateVector (Quaternion q, Vector3 src)
Rotates a Vector3 by a Quaternion
Parameters
q | |
---|---|
src |
Returns
- The rotated vector
public static Quaternion rotationBetweenVectors (Vector3 start, Vector3 end)
Get a new Quaternion representing the rotation from one vector to another.
Parameters
start | |
---|---|
end |
public void set (float qx, float qy, float qz, float qw)
Set each value and normalize the Quaternion
Parameters
qx | |
---|---|
qy | |
qz | |
qw |
public void set (Vector3 axis, float angle)
Update this Quaternion using an axis/angle to define the rotation
Parameters
axis | |
---|---|
angle |
public void setIdentity ()
Set the Quaternion to identity