WVR_ConvertMatrixQuaternion¶
- WVR_EXPORT void WVR_ConvertMatrixQuaternion(WVR_Matrix4f_t * mat, WVR_Quatf_t * quat, bool m2q)
Function to transform between rotation Matrix and Quaternion.
Convenience utility to apply the specified transform between rotation Matrix and Quaternion.
- Parameters
- mat -
input rotation matrix. (refer to WVR_Matrix4f)
- quat -
input Quaternion. (refer to WVR_Quatf)
- m2q -
true to convert matrix to Quaternion, false to do opposite.
- mat -
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]
// So, you can obtain the Rotation Matrix by this Conversion:
// Quaternion ===> Rotation Matrix
// w = 1 [ 1 0 0 ]
// x = 0 [ 0 1 0 ]
// y = 0 [ 0 0 1 ]
// z = 0