Havok: Add hkVector4f::_setRotatedDir

This commit is contained in:
Léo Lam 2022-01-28 20:07:34 +01:00
parent 907768910f
commit 82286fa560
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
2 changed files with 35 additions and 0 deletions

View File

@ -119,6 +119,9 @@ public:
// ========== Matrix operations (inline)
HK_FORCE_INLINE void _setRotatedDir(const hkMatrix3f& a, hkVector4fParameter b);
HK_FORCE_INLINE void _setRotatedDir(hkQuaternionfParameter quat, hkVector4fParameter vec);
HK_FORCE_INLINE void _setRotatedInverseDir(hkQuaternionfParameter quat,
hkVector4fParameter vec);
HK_FORCE_INLINE void _setTransformedPos(const hkTransformf& a, hkVector4fParameter b);
// ========== Length and normalization

View File

@ -382,6 +382,38 @@ inline void hkVector4f::_setRotatedDir(const hkMatrix3f& a, hkVector4fParameter
#endif
}
inline void hkVector4f::_setRotatedDir(hkQuaternionfParameter quat, hkVector4fParameter vec) {
// Rodrigues' rotation formula
const auto& u = quat.getImag();
const hkSimdFloat32 s = quat.getRealPart();
hkVector4f result;
result.setMul(vec, s * s - hkSimdFloat32::getConstant<HK_QUADREAL_INV_2>());
result.addMul(u, u.dot<3>(vec));
hkVector4f cross;
cross.setCross(u, vec);
result.addMul(cross, s);
setAdd(result, result);
}
inline void hkVector4f::_setRotatedInverseDir(hkQuaternionfParameter quat, hkVector4fParameter vec) {
const auto& u = quat.getImag();
const hkSimdFloat32 s = quat.getRealPart();
hkVector4f result;
result.setMul(vec, s * s - hkSimdFloat32::getConstant<HK_QUADREAL_INV_2>());
result.addMul(u, u.dot<3>(vec));
hkVector4f cross;
cross.setCross(vec, u);
result.addMul(cross, s);
setAdd(result, result);
}
inline void hkVector4f::_setTransformedPos(const hkTransformf& a, hkVector4fParameter b) {
hkVector4f t;
t._setRotatedDir(a.getRotation(), b);