Class SbRotation
The rotation value is stored internally as a quaternion. Quaternion representation is more compact, faster to compute and more numerically stable than rotation matrices. Quaternion representation allows smooth rotation (spherical linear interpolation) and avoids the problem of "gimbal lock" associated with Euler angles. It is not necessary to deal directly with quaternions. Many convenience methods are provided to set and get rotations using matrix and axis/angle representations.
Rotations are most commonly specified using an axis and an angle in radians. A common mistake is to use the constructor or setValue method that takes four float values, when intending to set an axis and angle. The methods that take four float values directly specify the quaternion value, which is probably not the intended result. For example:
// Create a rotation of PI/2 radians around the Z axis: // Incorrect. // (Compiles, but actually sets the quaternion value directly!) SbRotation rotation1 = new SbRotation(0, 0, 1, 1.5707963f); // This is the correct rotation. SbRotation rotation2 = new SbRotation(new SbVec3f(0, 0, 1), 1.5707963f);
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.SbRotation
(float[] components) SbRotation
(float q0, float q1, float q2, float q3) Constructor.Constructor.Constructor.SbRotation
(SbRotation copyFrom) SbRotation
(SbVec3f axis, float radians) Constructor.SbRotation
(SbVec3f rotateFrom, SbVec3f rotateTo) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns corresponding 3D rotation axis vector and angle in radians.boolean
equals
(SbRotation r, float tolerance) Equality comparison within given tolerance - the square of the length of the maximum distance between the two quaternion vectors.boolean
Returns corresponding 4x4 rotation matrix.Returns corresponding 3x3 rotation matrix.Returns corresponding 4x4 rotation matrix.float[]
getValue()
static SbRotation
identity()
Returns a null rotation.inverse()
Returns the inverse of a rotation.invert()
Changes a rotation to be its inverse.void
Multiplies by another rotation; results in product of rotations.Multiplies the given vector by the matrix of this rotation.void
scaleAngle
(float scaleFactor) Keep the axis the same.setValue
(float[] components) setValue
(float[] components, int startIndex) setValue
(float q0, float q1, float q2, float q3) Sets value of rotation from 4 individual components of a quaternion.Sets value of rotation from a rotation matrix.Sets rotation from a 3x3 rotation matrix.Sets rotation from a double precision rotation matrix.void
setValue
(SbRotation copyFrom) setValue
(SbRotationd rotated) Sets rotation from a double precision rotation.Sets value of vector from 3D rotation axis vector and angle in radians.Sets rotation to rotate one direction vector to another.static SbRotation
slerp
(SbRotation rot0, SbRotation rot1, float t) Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1.times
(SbRotation q2) Multiplication of two rotations; results in product of rotations.static SbRotation[]
toArray
(long nativeArray, long length)
-
Field Details
-
array
public final float[] array
-
-
Constructor Details
-
SbRotation
-
SbRotation
public SbRotation(float[] components) -
SbRotation
public SbRotation(float q0, float q1, float q2, float q3) Constructor. The quaternion constructor takes four floats that define a quaternion.
Note this is NOT the same as an axis/radian definition. -
SbRotation
public SbRotation()Default constructor. The initial value is no rotation. -
SbRotation
Constructor. The matrix constructor takes a valid rotation matrix. -
SbRotation
Constructor. The matrix constructor takes a valid 3x3 rotation matrix. -
SbRotation
Constructor. The axis/radians constructor creates a rotation of angle radians about the given axis. -
SbRotation
Constructor. The rotateFrom/To constructor defines a rotation that rotates from one vector into another. The rotateFrom and rotateTo vectors are normalized by the constructor before calculating the rotation.
-
-
Method Details
-
setValue
-
getValue
public float[] getValue() -
setValue
-
setValue
-
scaleAngle
public void scaleAngle(float scaleFactor) Keep the axis the same. Multiply the angle of rotation by the amount scaleFactor. -
multVec
Multiplies the given vector by the matrix of this rotation. -
times
Multiplication of two rotations; results in product of rotations. -
identity
Returns a null rotation. -
toArray
-
setValue
Sets value of rotation from 4 individual components of a quaternion. -
slerp
Spherical linear interpolation: as t goes from 0 to 1, returned value goes from rot0 to rot1. -
getMatrix
Returns corresponding 4x4 rotation matrix. -
setValue
Sets rotation from a 3x3 rotation matrix. -
decompose
Returns corresponding 3D rotation axis vector and angle in radians. -
setValue
Sets value of vector from 3D rotation axis vector and angle in radians. -
getMatrix3
Returns corresponding 3x3 rotation matrix. -
invert
Changes a rotation to be its inverse. -
inverse
Returns the inverse of a rotation. -
setValue
Sets value of rotation from a rotation matrix. -
getMatrixd
Returns corresponding 4x4 rotation matrix. -
setValue
Sets rotation to rotate one direction vector to another. The rotateFrom and rotateTo arguments are normalized before the rotation is calculated. -
equals
-
equals
Equality comparison within given tolerance - the square of the length of the maximum distance between the two quaternion vectors. -
setValue
Sets rotation from a double precision rotation matrix. -
setValue
Sets rotation from a double precision rotation. -
multiply
Multiplies by another rotation; results in product of rotations.
-