GLUtil Class Reference
Inherits from | NSObject |
---|---|
Declared in | GLUtil.h GLUtil.m |
+ getRotationMatrixFromQuaternion:
Helper function to convert a rotation vector to a rotation matrix. Given a rotation vector (presumably from a ROTATION_VECTOR sensor), returns a 9 or 16 element rotation matrix in the array R. R must have length 9 or 16. If R.length == 9, the following matrix is returned:
/ R[ 0] R[ 1] R[ 2] \ | R[ 3] R[ 4] R[ 5] | \ R[ 6] R[ 7] R[ 8] /
If R.length == 16, the following matrix is returned:
/ R[ 0] R[ 1] R[ 2] 0 \ | R[ 4] R[ 5] R[ 6] 0 | | R[ 8] R[ 9] R[10] 0 | \ 0 0 0 1 /
+ (GLKMatrix4)getRotationMatrixFromQuaternion:(CMQuaternion *)quaternion
Parameters
rotationVector |
the rotation vector to convert |
---|---|
R |
an array of floats in which to store the rotation matrix |
Discussion
Helper function to convert a rotation vector to a rotation matrix. Given a rotation vector (presumably from a ROTATION_VECTOR sensor), returns a 9 or 16 element rotation matrix in the array R. R must have length 9 or 16. If R.length == 9, the following matrix is returned:
/ R[ 0] R[ 1] R[ 2] \ | R[ 3] R[ 4] R[ 5] | \ R[ 6] R[ 7] R[ 8] /
If R.length == 16, the following matrix is returned:
/ R[ 0] R[ 1] R[ 2] 0 \ | R[ 4] R[ 5] R[ 6] 0 | | R[ 8] R[ 9] R[10] 0 | \ 0 0 0 1 /
Declared In
GLUtil.m
+ remapCoordinateSystem:X:Y:
Rotates the supplied rotation matrix so it is expressed in a different coordinate system. This is typically used when an application needs to compute the three orientation angles of the device (see {@link #getOrientation}) in a different coordinate system.
+ (GLKMatrix4)remapCoordinateSystem:(float *)inR X:(int)X Y:(int)Y
Return Value
true
on success. false
if the input
parameters are incorrect, for instance if X and Y define the same
axis. Or if inR and outR don’t have the same length.
Discussion
Rotates the supplied rotation matrix so it is expressed in a different coordinate system. This is typically used when an application needs to compute the three orientation angles of the device (see {@link #getOrientation}) in a different coordinate system.
When the rotation matrix is used for drawing (for instance with OpenGL ES), it usually doesn't need to be transformed by this function, unless the screen is physically rotated, in which case you can use {@link android.view.Display#getRotation() Display.getRotation()} to retrieve the current rotation of the screen. Note that because the user is generally free to rotate their screen, you often should consider the rotation in deciding the parameters to use here.
Examples:
- Using the camera (Y axis along the camera’s axis) for an augmented reality application where the rotation angles are needed:
- Using the device as a mechanical compass when rotation is {@link android.view.Surface#ROTATION_90 Surface.ROTATION_90}:
remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);
remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);
Beware of the above example. This call is needed only to account for a rotation from its natural orientation when calculating the rotation angles (see {@link #getOrientation}). If the rotation matrix is also used for rendering, it may not need to be transformed, for instance if your {@link android.app.Activity Activity} is running in landscape mode.
Since the resulting coordinate system is orthonormal, only two axes need to be specified.
@param inR the rotation matrix to be transformed. Usually it is the matrix returned by {@link #getRotationMatrix}.
@param X defines the axis of the new cooridinate system that coincide with the X axis of the original coordinate system.
@param Y defines the axis of the new cooridinate system that coincide with the Y axis of the original coordinate system.
@param outR the transformed rotation matrix. inR and outR should not be the same array.
Declared In
GLUtil.m