WVR_ConvertMatrixQuaternion¶
-
WVR_EXPORT void WVR_ConvertMatrixQuaternion(WVR_Matrix4f_t * mat, WVR_Quatf_t * quat, bool m2q)
Function to transform between the rotation matrix and quaternion.
A convenient utility to apply the specified transform between the rotation matrix and quaternion.
- Version
- API Level 1
- Parameters
mat
: Input rotation matrix. (refer to WVR_Matrix4f)quat
: Input quaternion. (refer to WVR_Quatf)m2q
: True converts the rotation matrix to quaternion, false converts the quaternion to rotation matrix.
How to use¶
Here is an example for the function:
#include <wvr/wvr_device.h>
WVR_Quatf_t hvrQuat;
WVR_Matrix4f_t Matrix4;
bool M2Q = false; // true: Matrix to Quaternion, flase: Quaternion to Matrix
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
Matrix4.m[i][j] = 0.0f;
}
}
hvrQuat.w = 1.0f;
hvrQuat.x = 0.0f;
hvrQuat.y = 0.0f;
hvrQuat.z = 0.0f;
WVR_ConvertMatrixQuaternion(&Matrix4, &hvrQuat, M2Q);
// After conversion, Matrix4.m[i][j] will be:
// [ 1 0 0 x]
// [ 0 1 0 y]
// [ 0 0 1 z]
// [ 0 0 0 1]
// The rotation matrix can be obtained by this conversion:
// Quaternion ===> Rotation Matrix
// w = 1 [ 1 0 0 ]
// x = 0 [ 0 1 0 ]
// y = 0 [ 0 0 1 ]
// z = 0