Add HMM_RotateQV3(), for rotating a vec3 by a quaternion

This commit is contained in:
Olivier Perret
2023-10-29 18:32:09 +01:00
parent 98748f702c
commit 149c18d449
2 changed files with 35 additions and 0 deletions

View File

@@ -2528,6 +2528,19 @@ static inline HMM_Quat HMM_QFromAxisAngle_LH(HMM_Vec3 Axis, float AngleOfRotatio
}
// implementation from
// https://blog.molecular-matters.com/2013/05/24/a-faster-quaternion-vector-multiplication/
COVERAGE(HMM_RotateQV3, 1)
static inline HMM_Vec3 HMM_RotateQV3(HMM_Quat Q, HMM_Vec3 V)
{
ASSERT_COVERED(HMM_RotateQV3);
HMM_Vec3 t = HMM_MulV3F(HMM_Cross(Q.XYZ, V), 2);
return HMM_AddV3(V, HMM_AddV3(HMM_MulV3F(t, Q.W), HMM_Cross(Q.XYZ, t)));
}
#ifdef __cplusplus
}
#endif