|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.math.Quaternion4f
public class Quaternion4f
Defines a 4-element quaternion that represents the orientation of an object in space.
Quaternions are typically used as a replacement for euler angles and rotation matrices as a way to achieve smooth interpolation and avoid gimbal lock.
Note that this quaternion class does not automatically keep the quaternion
normalized. Therefore, care must be taken to normalize the quaternion when
neccessary, by calling the normalize
method.
The package provides three methods for doing quaternion interpolation: lerp, slerp, and squad.
squad
is continuously differentiable, it remedies the first and third problems mentioned above.
The slerp
method provided here is intended for interpolation of principal rotations. It treats
+q
and -q
as the same principal rotation and is at liberty to use the negative of
either input. The resulting path is always the shorter arc.
The lerp
method provided here interpolates strictly in quaternion space. Note that the resulting
path may pass through the origin if interpolating between a quaternion and its exact negative.
As an example, consider the following quaternions
p = (1.0, 1.0, 1.0)
, the following figures show the trajectories of p
using lerp
,
slerp
, and squad
.
Field Summary | ||
---|---|---|
static int |
ANIMATION_PROPERTY_QUATERNION
Used to animate the quaternion. |
|
float |
w
The scalar component of the quaternion. |
|
float |
x
The x-value of the quaternion's vector component. |
|
float |
y
The y-value of the quaternion's vector component. |
|
float |
z
The z-value of the quaternion's vector component. |
Constructor Summary | ||
---|---|---|
Quaternion4f()
Constructs a quaternion initialized to (0, 0, 0, 1). |
||
Quaternion4f(float x,
float y,
float z,
float w)
Constructs a new quaternion. |
||
Quaternion4f(float[] array,
int offset)
Constructs a new quaternion from the values in the specified array. |
||
Quaternion4f(Matrix4f m)
Constructs a new quaternion equal to the rotational part of the specified matrix. |
||
Quaternion4f(Quaternion4f q)
Constructs a new quaternion that is a copy of the specified one. |
||
Quaternion4f(Vector3f axis,
float angle)
Constructs a new quaternion equal to the rotation from the specified axis and angle. |
Method Summary | ||
---|---|---|
void |
conjugate()
Sets this quaternion to the conjugate of itself. |
|
void |
conjugate(Quaternion4f dst)
Gets the conjugate of this quaternion in dst . |
|
static void |
controlPoints(Quaternion4f[] quats,
Quaternion4f[] cps)
Computes the control points for the input Quaternion4f . |
|
boolean |
equals(Object obj)
Determines if the specified object is equal to this quaternion. |
|
boolean |
equals(Quaternion4f q)
Determines if the specified quaternion is equal to this one. |
|
int |
getAnimationPropertyComponentCount(int property)
Gets the number of components of the specified property. |
|
void |
getAnimationValue(int property,
AnimationValue value)
Gets the value or values of the specified property. |
|
int |
hashCode()
Returns the hash code of the quaternion, based on the values stored in it. |
|
boolean |
inverse()
Sets this quaternion to the inverse of itself. |
|
boolean |
inverse(Quaternion4f dst)
Gets the inverse of this quaternion in dst . |
|
boolean |
isIdentity()
Determines if this quaterion is equal to the identity quaternion. |
|
static void |
lerp(Quaternion4f q1,
Quaternion4f q2,
float t,
Quaternion4f dst)
Interpolates between two quaternions using linear interpolation. |
|
void |
multiply(Quaternion4f q)
Multiplies this quaternion by the specified one and stores the result in this quaternion. |
|
static void |
multiply(Quaternion4f q1,
Quaternion4f q2,
Quaternion4f dst)
Multiplies the specified quaternions and stores the result in dst . |
|
void |
normalize()
Normalizes this quaternion to have unit length. |
|
void |
normalize(Quaternion4f dst)
Normalizes this quaternion and stores the result in dst . |
|
void |
set(float x,
float y,
float z,
float w)
Sets the elements of the quaternion to the specified values. |
|
void |
set(float[] array,
int offset)
Sets the elements of the quaternion from the values in the specified array. |
|
void |
set(Matrix4f m)
Sets this quaternion equal to the rotational part of the specified matrix. |
|
void |
set(Quaternion4f q)
Sets the elements of this quaternion to a copy of the specified quaternion. |
|
void |
set(Vector3f axis,
float angle)
Sets this quaternion equal to the rotation from the specified axis and angle. |
|
void |
setAnimationValue(int property,
AnimationValue value)
Sets the value or values of the specified property. |
|
void |
setIdentity()
Sets this quaternion to be equal to the identity quaternion. |
|
static void |
slerp(Quaternion4f q1,
Quaternion4f q2,
float t,
Quaternion4f dst)
Interpolates between two quaternions using spherical linear interpolation. |
|
static void |
squad(Quaternion4f q1,
Quaternion4f q2,
Quaternion4f s1,
Quaternion4f s2,
float t,
Quaternion4f dst)
Interpolates over a series of quaternions using spherical spline interpolation. |
|
float |
toAxisAngle(Vector3f e)
Converts this Quaternion4f to axis-angle notation. |
|
String |
toString()
Returns a String representation of the elements of this quaternion. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public float x
public float y
public float z
public float w
public static final int ANIMATION_PROPERTY_QUATERNION
Required AnimationKeyframeSequence data format:
float[] data = { rotation.x, rotation.y, rotation.z, rotation.w }
Constructor Detail |
---|
public Quaternion4f()
public Quaternion4f(float x, float y, float z, float w)
x
- the x-valuey
- the y-valuez
- the z-valuew
- the w-valuepublic Quaternion4f(float[] array, int offset)
array
- an array containing the elements of the quaternion in the order x, y, z, w.offset
- the offset into the array of the x
element
IllegalArgumentException
- If offset
is less than zero or
offset + 3
is greater than or equal to array.length
.
NullPointerException
- If array
is null
.public Quaternion4f(Matrix4f m)
m
- the matrix
NullPointerException
- If m
is null
.public Quaternion4f(Quaternion4f q)
q
- the quaternion to copy
NullPointerException
- If q
is null
.public Quaternion4f(Vector3f axis, float angle)
axis
- a vector describing the axis of rotationangle
- the angle of rotation, in radians
NullPointerException
- If axis
is null
.Method Detail |
---|
public final void conjugate()
public final void conjugate(Quaternion4f dst)
dst
.
dst
- a quaternion to store the conjugate in
NullPointerException
- If dst
is null
.public final boolean inverse()
Note that the inverse of a quaternion is equal to its conjugate
when the quaternion is unit-length. For this reason, it is more
efficient to use the conjugate
method directly
when you know your quaternion is already unit-length.
public final boolean inverse(Quaternion4f dst)
dst
.
Note that the inverse of a quaternion is equal to its conjugate
when the quaternion is unit-length. For this reason, it is more
efficient to use the conjugate
method directly
when you know your quaternion is already unit-length.
dst
- a quaternion to store the inverse in
NullPointerException
- If dst
is null
.public final boolean isIdentity()
public final void multiply(Quaternion4f q)
q
- the quaternion to multiply
NullPointerException
- If q
is null
.public static void multiply(Quaternion4f q1, Quaternion4f q2, Quaternion4f dst)
dst
.
q1
- the first quaternionq2
- the second quaterniondst
- a quaternion to store the result in
NullPointerException
- If q1
, q2
, or dst
is null
.public final void normalize()
If the quaternion already has unit length or if the length of the quaternion is zero, this method does nothing.
public final void normalize(Quaternion4f dst)
dst
.
If the quaternion already has unit length or if the length of the
quaternion is zero, this method simply copies this vector into dst
.
dst
- a quaternion to store the result in
NullPointerException
- If dst
is null
.public final void set(float x, float y, float z, float w)
x
- the new x-valuey
- the new y-valuez
- the new z-valuew
- the new w-valuepublic final void set(float[] array, int offset)
array
- an array containing the elements of the quaternion in the order x, y, z, w.offset
- the offset into the array of the x
element
IllegalArgumentException
- If offset
is less than zero or
offset + 3
is greater than or equal to array.length
.
NullPointerException
- If array
is null
.public final void set(Matrix4f m)
m
- the matrix
NullPointerException
- If m
is null
.public final void set(Quaternion4f q)
q
- the quaternion to copy
NullPointerException
- If q
is null
.public final void set(Vector3f axis, float angle)
axis
- a vector describing the axis of rotationangle
- the angle of rotation, in radians
NullPointerException
- If axis
is null
.public final void setIdentity()
public static void slerp(Quaternion4f q1, Quaternion4f q2, float t, Quaternion4f dst)
Spherical linear interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be at (or close to)
unit length. This method does not automatically normalize the input quaternions, so it
is up to the caller to ensure they call normalize
beforehand, if necessary.
q1
- the first quaternionq2
- the second quaterniont
- the interpolation coefficientdst
- a quaternion to store the result in
NullPointerException
- If q1
, q2
, or dst
is null
.public boolean equals(Object obj)
obj
- the object to compare
obj
is an instance of Quaternion4f and if
all its components equal this one
NullPointerException
- If obj
is null
.Boolean.hashCode()
,
Hashtable
public boolean equals(Quaternion4f q)
q
- the quaternion to compare
NullPointerException
- If q
is null
.public int hashCode()
Object.equals(java.lang.Object)
,
Hashtable
public String toString()
public void getAnimationValue(int property, AnimationValue value)
Animatable
Gets the value or values of the specified property.
Used by the Animation framework to get the values of the specified property on the Animatable
.
The implementer must set the value of the specified target property in the AnimationValue
parameter.
getAnimationValue
in interface Animatable
property
- The property to get the current value or values of.value
- An AnimationValue
used to store the returned property values.Animatable.getAnimationValue(int,AnimationValue)
public void setAnimationValue(int property, AnimationValue value)
Animatable
Sets the value or values of the specified property.
Used by the Animation framework to update the value or values of the specified target property on the Animatable
with the currently calculated animation value. The implementer must update the current value or values of the given target property
with the values in the AnimationValue
parameter.
setAnimationValue
in interface Animatable
property
- The property to set the current value or values of.value
- The AnimationValue
used to specify the value or values to set.Animatable.setAnimationValue(int,AnimationValue)
public int getAnimationPropertyComponentCount(int property)
Animatable
Gets the number of components of the specified property.
The implementer must define the component size of every animatable property defined for theAnimatable
.
getAnimationPropertyComponentCount
in interface Animatable
property
- The property to retrieve the component count for.
Animatable.getAnimationPropertyComponentCount(int)
public float toAxisAngle(Vector3f e)
Quaternion4f
to axis-angle notation. The axis is normalized.
e
- the Vector3f
which stores the axis.
NullPointerException
- If e
is null
.public static void lerp(Quaternion4f q1, Quaternion4f q2, float t, Quaternion4f dst)
The interpolation curve for linear interpolation between quaternions gives a straight line in quaternion space.
q1
- the first quaternionq2
- the second quaterniont
- the interpolation coefficientdst
- a quaternion to store the result in
NullPointerException
- If q1
, q2
, or dst
is null
.public static void squad(Quaternion4f q1, Quaternion4f q2, Quaternion4f s1, Quaternion4f s2, float t, Quaternion4f dst)
Spherical spline interpolation provides smooth transitions between different orientations and is often useful for animating models or cameras in 3D.
Note: For accurate interpolation, the input quaternions must be unit.
This method does not automatically normalize the input quaternions, so it
is up to the caller to ensure they call normalize
beforehand, if necessary.
q1
- the first quaternionq2
- the second quaternions1
- the first control points2
- the second control pointt
- the interpolation coefficientdst
- a quaternion to store the result in
NullPointerException
- If q1
, q2
,
s1
, s2
, or dst
is null
.
Quaternion4f.controlPoints(Quaternion4f[], Quaternion4f[])
public static void controlPoints(Quaternion4f[] quats, Quaternion4f[] cps)
Quaternion4f
. These control points
are needed in squad
computation.
quats
- the array storing the Quarternion4f'scps
- the array storing the computed control points each of which is a Quaternion4f
- Throws:
NullPointerException
- if either quats
or cps
is null
IllegalArgumentException
- if the quats.length < 3
or if
quats.length != cps.length
Note that cps[0] = quats[0]
, and cps[n-1] = quats[n-1]
where n = quats.length
.
- Since:
- BlackBerry API 6.0.0
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal