Class Quaternion
java.lang.Object
com.codename1.gpu.Quaternion
Portable quaternion math used by the 3D, AR and VR APIs. Every operation
works on plain
float[4] arrays laid out as {x, y, z, w} so it behaves
identically on every platform. A quaternion of this form represents a
rotation; {0, 0, 0, 1} is the identity (no rotation). Rotation matrices
produced by toMatrix(float[], float[]) use the same column-major layout
as Matrix4.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidconjugate(float[] q, float[] dst) Stores the conjugate ofq(the inverse rotation for a unit quaternion) intodst.static voidcopy(float[] src, float[] dst) Copies the contents ofsrcintodst.static float[]fromAxisAngle(float angleRadians, float x, float y, float z) Returns a quaternion representing a rotation ofangleRadiansaround the axis(x, y, z).static float[]identity()Allocates a new identity quaternion{0, 0, 0, 1}.static voidintegrateGyro(float[] q, float gx, float gy, float gz, float dtSeconds, float[] dst) Integrates a body-frame angular velocity into the orientation quaternionq, storing the result indst.static voidmultiply(float[] a, float[] b, float[] dst) Multipliesa * b(applybfirst, thena) and stores the result indst.static voidnormalize(float[] q) Normalizesqin place to unit length.static voidrotateVector(float[] q, float[] xyzInOut) Rotates the vector stored inxyzInOut(3 floats) by the unit quaternionq, writing the result back in place.static voidsetAxisAngle(float[] q, float angleRadians, float x, float y, float z) Stores a rotation ofangleRadiansaround the axis(x, y, z)intoq.static voidsetIdentity(float[] q) Resets the supplied quaternion to the identity rotation.static voidslerp(float[] a, float[] b, float t, float[] dst) Spherically interpolates between the unit quaternionsaandbby the factortin[0, 1], storing the result indst.static voidtoMatrix(float[] q, float[] dst16) Writes the rotation matrix equivalent of the unit quaternionqinto the 16 element column-major matrixdst16.
-
Method Details
-
identity
public static float[] identity()Allocates a new identity quaternion{0, 0, 0, 1}. -
setIdentity
public static void setIdentity(float[] q) Resets the supplied quaternion to the identity rotation. -
copy
public static void copy(float[] src, float[] dst) Copies the contents ofsrcintodst. Both arrays must hold 4 floats. -
multiply
public static void multiply(float[] a, float[] b, float[] dst) Multipliesa * b(applybfirst, thena) and stores the result indst.dstmay aliasaorb. -
fromAxisAngle
public static float[] fromAxisAngle(float angleRadians, float x, float y, float z) Returns a quaternion representing a rotation ofangleRadiansaround the axis(x, y, z). The axis need not be normalized; a zero axis returns the identity. -
setAxisAngle
public static void setAxisAngle(float[] q, float angleRadians, float x, float y, float z) Stores a rotation ofangleRadiansaround the axis(x, y, z)intoq. The axis need not be normalized; a zero axis produces the identity. -
normalize
public static void normalize(float[] q) Normalizesqin place to unit length. A zero quaternion is reset to the identity. -
conjugate
public static void conjugate(float[] q, float[] dst) Stores the conjugate ofq(the inverse rotation for a unit quaternion) intodst.dstmay aliasq. -
toMatrix
public static void toMatrix(float[] q, float[] dst16) Writes the rotation matrix equivalent of the unit quaternionqinto the 16 element column-major matrixdst16. The result matchesMatrix4.rotation(float, float, float, float)for the same axis and angle. -
rotateVector
public static void rotateVector(float[] q, float[] xyzInOut) Rotates the vector stored inxyzInOut(3 floats) by the unit quaternionq, writing the result back in place. -
slerp
public static void slerp(float[] a, float[] b, float t, float[] dst) Spherically interpolates between the unit quaternionsaandbby the factortin[0, 1], storing the result indst. Takes the shortest arc; falls back to linear interpolation when the quaternions are nearly parallel. -
integrateGyro
public static void integrateGyro(float[] q, float gx, float gy, float gz, float dtSeconds, float[] dst) Integrates a body-frame angular velocity into the orientation quaternionq, storing the result indst.gx,gyandgzare rotation rates in radians per second around the body X, Y and Z axes (the convention used by gyroscope sensors) anddtSecondsis the integration interval.dstmay aliasq. The result is normalized.
-