From 3d9664ed52e996ba39d939bd681c3f5400dd4e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 13 Jan 2022 02:14:51 +0100 Subject: [PATCH] Havok: Add more hkTransformf functions --- .../Common/Base/Math/Matrix/hkRotationf.h | 14 ++++++- .../Common/Base/Math/Matrix/hkTransformf.h | 40 +++++++++++++++++++ .../Base/Math/Quaternion/hkQuaternionf.h | 2 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h index 1a24fcc6..80d124b0 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h @@ -1,5 +1,17 @@ #pragma once #include +#include -class hkRotationf : public hkMatrix3f {}; +class hkRotationf : public hkMatrix3f { +public: + void set(hkQuaternionfParameter q); + + void setAxisAngle(hkVector4fParameter axis, hkFloat32 angle); + void setAxisAngle(hkVector4fParameter axis, hkSimdFloat32Parameter angle); + + bool isOrthonormal(hkFloat32 epsilon = hkFloat32(1e-5f)) const; + + bool isOk() const; + void renormalize(); +}; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h index cbc0fbb1..0e4dab59 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h @@ -1,16 +1,56 @@ #pragma once #include +#include #include class hkTransformf { public: + HK_FORCE_INLINE hkTransformf() = default; + HK_FORCE_INLINE hkTransformf(const hkTransformf& other); + HK_FORCE_INLINE hkTransformf(const hkRotationf& r, hkVector4fParameter t); + HK_FORCE_INLINE hkTransformf(hkQuaternionfParameter r, hkVector4fParameter t); + + hkTransformf& operator=(const hkTransformf& other) = default; + hkRotationf& getRotation() { return m_rotation; } const hkRotationf& getRotation() const { return m_rotation; } hkVector4f& getTranslation() { return m_translation; } const hkVector4f& getTranslation() const { return m_translation; } + HK_FORCE_INLINE void set(const hkRotationf& r, hkVector4fParameter t); + HK_FORCE_INLINE void set(hkQuaternionfParameter q, hkVector4fParameter t); + hkRotationf m_rotation; hkVector4f m_translation; }; + +inline hkTransformf::hkTransformf(const hkTransformf& other) { + const auto col0 = other.m_rotation.m_col0; + const auto col1 = other.m_rotation.m_col1; + const auto col2 = other.m_rotation.m_col2; + const auto col3 = other.m_translation; + m_rotation.m_col0 = col0; + m_rotation.m_col1 = col1; + m_rotation.m_col2 = col2; + m_translation = col3; +} + +inline hkTransformf::hkTransformf(const hkRotationf& r, const hkVector4f& t) + : m_rotation(r), m_translation(t) {} + +inline hkTransformf::hkTransformf(hkQuaternionfParameter r, const hkVector4f& t) + : m_translation(t) { + m_rotation.set(r); +} + +inline void hkTransformf::set(const hkRotationf& r, const hkVector4f& t) { + m_rotation = r; + m_translation = t; +} + +inline void hkTransformf::set(const hkQuaternionf& q, const hkVector4f& t) { + m_rotation.set(q); + m_translation = t; +} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h index c88e06c4..f404ba78 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h @@ -2,6 +2,8 @@ #include +using hkQuaternionfParameter = const class hkQuaternionf&; + class hkQuaternionf { public: hkQuaternionf() {} // NOLINT(modernize-use-equals-default)