diff --git a/lib/hkStubs/CMakeLists.txt b/lib/hkStubs/CMakeLists.txt index a4a692a4..bf9397ba 100644 --- a/lib/hkStubs/CMakeLists.txt +++ b/lib/hkStubs/CMakeLists.txt @@ -16,12 +16,14 @@ add_library(hkStubs OBJECT Havok/Common/Base/Math/Header/hkMathHeaderConstants.h Havok/Common/Base/Math/Matrix/hkMatrix3.h Havok/Common/Base/Math/Matrix/hkMatrix3f.h + Havok/Common/Base/Math/Matrix/hkMatrix3f.inl Havok/Common/Base/Math/Matrix/hkRotation.h Havok/Common/Base/Math/Matrix/hkRotationf.h Havok/Common/Base/Math/Matrix/hkTransform.h Havok/Common/Base/Math/Matrix/hkTransformf.h Havok/Common/Base/Math/Quaternion/hkQuaternion.h Havok/Common/Base/Math/Quaternion/hkQuaternionf.h + Havok/Common/Base/Math/Quaternion/hkQuaternionf.inl Havok/Common/Base/Math/SweptTransform/hkSweptTransform.h Havok/Common/Base/Math/SweptTransform/hkSweptTransformf.h Havok/Common/Base/Math/SweptTransform/hkSweptTransformfUtil.h @@ -32,6 +34,7 @@ add_library(hkStubs OBJECT Havok/Common/Base/Math/Vector/hkVector4f.inl Havok/Common/Base/Math/Vector/hkVector4Comparison.h Havok/Common/Base/Math/Vector/hkVector4fComparison.h + Havok/Common/Base/Math/Vector/hkVector4fComparison.inl Havok/Common/Base/Memory/Allocator/hkMemoryAllocator.h Havok/Common/Base/Memory/Allocator/Lifo/hkLifoAllocator.h diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h index 9445f303..c1d3fe82 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.h @@ -1,7 +1,5 @@ #pragma once -#include - class hkMatrix3f { public: hkMatrix3f() {} // NOLINT(modernize-use-equals-default) @@ -27,60 +25,3 @@ public: hkVector4f m_col1; hkVector4f m_col2; }; - -inline hkFloat32& hkMatrix3f::operator()(int row, int col) { - return getColumn(col)(row); -} - -inline const hkFloat32& hkMatrix3f::operator()(int row, int col) const { - return getColumn(col)(row); -} - -template -inline hkSimdFloat32 hkMatrix3f::get() const { - return getColumn().template getComponent(); -} - -template -inline void hkMatrix3f::set(hkSimdFloat32Parameter s) { - getColumn().template setComponent(s); -} - -inline hkVector4f& hkMatrix3f::getColumn(int i) { - return (&m_col0)[i]; -} - -inline const hkVector4f& hkMatrix3f::getColumn(int i) const { - return (&m_col0)[i]; -} - -template -inline const hkVector4f& hkMatrix3f::getColumn() const { - return (&m_col0)[I]; -} - -inline void hkMatrix3f::getRows(hkVector4f& r0, hkVector4f& r1, hkVector4f& r2) const { - hkVector4f c0; - c0.set(m_col0(0), m_col1(0), m_col2(0)); - hkVector4f c1; - c1.set(m_col0(1), m_col1(1), m_col2(1)); - hkVector4f c2; - c2.set(m_col0(2), m_col1(2), m_col2(2)); - - r0 = c0; - r1 = c1; - r2 = c2; -} - -inline void hkMatrix3f::setZero() { - m_col0.setZero(); - m_col1.setZero(); - m_col2.setZero(); -} - -inline void hkMatrix3f::setIdentity() { - hkMatrix3f* __restrict d = this; - d->m_col0 = hkVector4f::getConstant(); - d->m_col1 = hkVector4f::getConstant(); - d->m_col2 = hkVector4f::getConstant(); -} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.inl b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.inl new file mode 100644 index 00000000..b55ed805 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkMatrix3f.inl @@ -0,0 +1,56 @@ +inline hkFloat32& hkMatrix3f::operator()(int row, int col) { + return getColumn(col)(row); +} + +inline const hkFloat32& hkMatrix3f::operator()(int row, int col) const { + return getColumn(col)(row); +} + +template +inline hkSimdFloat32 hkMatrix3f::get() const { + return getColumn().template getComponent(); +} + +template +inline void hkMatrix3f::set(hkSimdFloat32Parameter s) { + getColumn().template setComponent(s); +} + +inline hkVector4f& hkMatrix3f::getColumn(int i) { + return (&m_col0)[i]; +} + +inline const hkVector4f& hkMatrix3f::getColumn(int i) const { + return (&m_col0)[i]; +} + +template +inline const hkVector4f& hkMatrix3f::getColumn() const { + return (&m_col0)[I]; +} + +inline void hkMatrix3f::getRows(hkVector4f& r0, hkVector4f& r1, hkVector4f& r2) const { + hkVector4f c0; + c0.set(m_col0(0), m_col1(0), m_col2(0)); + hkVector4f c1; + c1.set(m_col0(1), m_col1(1), m_col2(1)); + hkVector4f c2; + c2.set(m_col0(2), m_col1(2), m_col2(2)); + + r0 = c0; + r1 = c1; + r2 = c2; +} + +inline void hkMatrix3f::setZero() { + m_col0.setZero(); + m_col1.setZero(); + m_col2.setZero(); +} + +inline void hkMatrix3f::setIdentity() { + hkMatrix3f* __restrict d = this; + d->m_col0 = hkVector4f::getConstant(); + d->m_col1 = hkVector4f::getConstant(); + d->m_col2 = hkVector4f::getConstant(); +} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h index 80d124b0..4385fa13 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkRotationf.h @@ -1,8 +1,5 @@ #pragma once -#include -#include - class hkRotationf : public hkMatrix3f { public: void set(hkQuaternionfParameter q); diff --git a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h index 175b3a0c..297e9374 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Matrix/hkTransformf.h @@ -1,9 +1,5 @@ #pragma once -#include -#include -#include - class hkTransformf { public: HK_FORCE_INLINE hkTransformf() = default; diff --git a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h index 32c6c901..c2e2e172 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.h @@ -1,9 +1,5 @@ #pragma once -#include - -using hkQuaternionfParameter = const class hkQuaternionf&; - class hkQuaternionf { public: hkQuaternionf() {} // NOLINT(modernize-use-equals-default) @@ -43,102 +39,3 @@ public: hkVector4f m_vec; }; - -inline hkQuaternionf::hkQuaternionf(hkFloat32 ix, hkFloat32 iy, hkFloat32 iz, hkFloat32 r) { - set(ix, iy, iz, r); -} - -inline void hkQuaternionf::set(hkFloat32 ix, hkFloat32 iy, hkFloat32 iz, hkFloat32 r) { - m_vec.set(ix, iy, iz, r); -} - -inline hkQuaternionf& hkQuaternionf::operator=(const hkQuaternionf& q) { - m_vec = q.m_vec; - return *this; -} - -inline const hkFloat32& hkQuaternionf::operator()(int i) const { - return m_vec(i); -} - -template -inline hkSimdFloat32 hkQuaternionf::getComponent() const { - return m_vec.getComponent(); -} - -inline hkFloat32 hkQuaternionf::getReal() const { - return m_vec(3); -} - -inline hkSimdFloat32 hkQuaternionf::getRealPart() const { - return m_vec.getW(); -} - -inline const hkVector4f& hkQuaternionf::getImag() const { - return m_vec; -} - -inline hkBool32 hkQuaternionf::hasValidAxis() const { - return m_vec.lengthSquared<3>().isGreater(hkSimdFloat32::getConstant()); -} - -void hkQuaternionf::getAxis(hkVector4f& axis) const { - hkVector4f result = getImag(); - result.normalize<3>(); - axis.setFlipSign(result, getRealPart().lessZero()); -} - -inline hkFloat32 hkQuaternionf::getAngle() const { - return getAngleSr().val(); -} - -inline void hkQuaternionf::mul(hkQuaternionfParameter q) { - setMul(*this, q); -} - -inline void hkQuaternionf::setMul(hkQuaternionfParameter r, hkQuaternionfParameter q) { - const auto rImag = r.getImag(); - const auto qImag = q.getImag(); - const auto rReal = r.getRealPart(); - const auto qReal = q.getRealPart(); - - hkVector4f vec; - vec.setCross(rImag, qImag); - vec.addMul(rReal, qImag); - vec.addMul(qReal, rImag); - m_vec.setXYZ_W(vec, (rReal * qReal) - rImag.dot<3>(qImag)); -} - -inline void hkQuaternionf::setMulInverse(hkQuaternionfParameter r, hkQuaternionfParameter q) { - const auto rImag = r.getImag(); - const auto qImag = q.getImag(); - - hkVector4f vec; - vec.setCross(qImag, rImag); - vec.subMul(r.getRealPart(), qImag); - vec.addMul(q.getRealPart(), rImag); - m_vec.setXYZ_W(vec, rImag.dot<4>(qImag)); -} - -inline void hkQuaternionf::setInverseMul(hkQuaternionfParameter r, hkQuaternionfParameter q) { - const auto rImag = r.getImag(); - const auto qImag = q.getImag(); - - hkVector4f vec; - vec.setCross(qImag, rImag); - vec.addMul(r.getRealPart(), qImag); - vec.subMul(q.getRealPart(), rImag); - m_vec.setXYZ_W(vec, rImag.dot<4>(qImag)); -} - -inline void hkQuaternionf::setInverse(const hkQuaternionf& q) { - m_vec.setNeg<3>(q.getImag()); -} - -inline void hkQuaternionf::normalize() { - m_vec.normalizeUnsafe<4>(); -} - -inline const hkQuaternionf& hkQuaternionf::getIdentity() { - return reinterpret_cast(g_vectorfConstants[HK_QUADREAL_0001]); -} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.inl b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.inl new file mode 100644 index 00000000..72c9a026 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Quaternion/hkQuaternionf.inl @@ -0,0 +1,100 @@ +#pragma once + +inline hkQuaternionf::hkQuaternionf(hkFloat32 ix, hkFloat32 iy, hkFloat32 iz, hkFloat32 r) { + set(ix, iy, iz, r); +} + +inline void hkQuaternionf::set(hkFloat32 ix, hkFloat32 iy, hkFloat32 iz, hkFloat32 r) { + m_vec.set(ix, iy, iz, r); +} + +inline hkQuaternionf& hkQuaternionf::operator=(const hkQuaternionf& q) { + m_vec = q.m_vec; + return *this; +} + +inline const hkFloat32& hkQuaternionf::operator()(int i) const { + return m_vec(i); +} + +template +inline hkSimdFloat32 hkQuaternionf::getComponent() const { + return m_vec.getComponent(); +} + +inline hkFloat32 hkQuaternionf::getReal() const { + return m_vec(3); +} + +inline hkSimdFloat32 hkQuaternionf::getRealPart() const { + return m_vec.getW(); +} + +inline const hkVector4f& hkQuaternionf::getImag() const { + return m_vec; +} + +inline hkBool32 hkQuaternionf::hasValidAxis() const { + return m_vec.lengthSquared<3>().isGreater(hkSimdFloat32::getConstant()); +} + +void hkQuaternionf::getAxis(hkVector4f& axis) const { + hkVector4f result = getImag(); + result.normalize<3>(); + axis.setFlipSign(result, getRealPart().lessZero()); +} + +inline hkFloat32 hkQuaternionf::getAngle() const { + return getAngleSr().val(); +} + +inline void hkQuaternionf::mul(hkQuaternionfParameter q) { + setMul(*this, q); +} + +inline void hkQuaternionf::setMul(hkQuaternionfParameter r, hkQuaternionfParameter q) { + const auto rImag = r.getImag(); + const auto qImag = q.getImag(); + const auto rReal = r.getRealPart(); + const auto qReal = q.getRealPart(); + + hkVector4f vec; + vec.setCross(rImag, qImag); + vec.addMul(rReal, qImag); + vec.addMul(qReal, rImag); + m_vec.setXYZ_W(vec, (rReal * qReal) - rImag.dot<3>(qImag)); +} + +inline void hkQuaternionf::setMulInverse(hkQuaternionfParameter r, hkQuaternionfParameter q) { + const auto rImag = r.getImag(); + const auto qImag = q.getImag(); + + hkVector4f vec; + vec.setCross(qImag, rImag); + vec.subMul(r.getRealPart(), qImag); + vec.addMul(q.getRealPart(), rImag); + m_vec.setXYZ_W(vec, rImag.dot<4>(qImag)); +} + +inline void hkQuaternionf::setInverseMul(hkQuaternionfParameter r, hkQuaternionfParameter q) { + const auto rImag = r.getImag(); + const auto qImag = q.getImag(); + + hkVector4f vec; + vec.setCross(qImag, rImag); + vec.addMul(r.getRealPart(), qImag); + vec.subMul(q.getRealPart(), rImag); + m_vec.setXYZ_W(vec, rImag.dot<4>(qImag)); +} + +inline void hkQuaternionf::setInverse(const hkQuaternionf& q) { + m_vec.setNeg<3>(q.getImag()); +} + +inline void hkQuaternionf::normalize() { + m_vec.normalizeUnsafe<4>(); +} + +inline const hkQuaternionf& hkQuaternionf::getIdentity() { + return reinterpret_cast(g_vectorfConstants[HK_QUADREAL_0001]); +} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h index 2ec08fc7..0c3a08ca 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkSimdFloat32.h @@ -11,8 +11,6 @@ #include #endif -using hkSimdFloat32Parameter = const class hkSimdFloat32&; - class hkSimdFloat32 { public: #ifdef HK_SIMD_FLOAT32_AARCH64_NEON diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h index 54556ae6..e276a66b 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4f.h @@ -9,12 +9,6 @@ #error "Include or hkBase.h" #endif -using hkVector4fParameter = const class hkVector4f&; -using hkVector4fComparisonParameter = const class hkVector4fComparison&; - -class hkMatrix3f; -class hkTransformf; - class hkVector4f { public: HK_DECLARE_CLASS_ALLOCATOR(hkVector4f) diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h index c98fad4b..2f449763 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.h @@ -65,59 +65,3 @@ public: m128u m_mask; }; - -inline void hkVector4fComparison::setAnd(hkVector4fComparisonParameter a, - hkVector4fComparisonParameter b) { - m_mask = a.m_mask & b.m_mask; -} - -inline void hkVector4fComparison::setAndNot(hkVector4fComparisonParameter a, - hkVector4fComparisonParameter b) { - m_mask = a.m_mask & ~b.m_mask; -} - -inline void hkVector4fComparison::setXor(hkVector4fComparisonParameter a, - hkVector4fComparisonParameter b) { - m_mask = a.m_mask ^ b.m_mask; -} - -inline void hkVector4fComparison::setOr(hkVector4fComparisonParameter a, - hkVector4fComparisonParameter b) { - m_mask = a.m_mask | b.m_mask; -} - -inline void hkVector4fComparison::setNot(hkVector4fComparisonParameter a) { - m_mask = ~a.m_mask; -} - -inline void hkVector4fComparison::setSelect(hkVector4fComparisonParameter comp, - hkVector4fComparisonParameter trueValue, - hkVector4fComparisonParameter falseValue) { -#ifdef HK_VECTOR4F_AARCH64_NEON - m_mask = vbslq_u32(comp.m_mask, trueValue.m_mask, falseValue.m_mask); -#else - m_mask = (comp.m_mask & trueValue.m_mask) | (comp.m_mask & ~falseValue.m_mask); -#endif -} - -template -inline hkBool32 hkVector4fComparison::allAreSet() const { - return ((m & MASK_X) == 0 || m_mask[0] != 0) && ((m & MASK_Y) == 0 || m_mask[1] != 0) && - ((m & MASK_Z) == 0 || m_mask[2] != 0) && ((m & MASK_W) == 0 || m_mask[3] != 0); -} - -inline hkBool32 hkVector4fComparison::allAreSet(hkVector4fComparison::Mask m) const { - return ((m & MASK_X) == 0 || m_mask[0] != 0) && ((m & MASK_Y) == 0 || m_mask[1] != 0) && - ((m & MASK_Z) == 0 || m_mask[2] != 0) && ((m & MASK_W) == 0 || m_mask[3] != 0); -} - -template -inline hkBool32 hkVector4fComparison::anyIsSet() const { - return ((m & MASK_X) != 0 && m_mask[0] != 0) || ((m & MASK_Y) != 0 && m_mask[1] != 0) || - ((m & MASK_Z) != 0 && m_mask[2] != 0) || ((m & MASK_W) != 0 && m_mask[3] != 0); -} - -inline hkBool32 hkVector4fComparison::anyIsSet(Mask m) const { - return ((m & MASK_X) != 0 && m_mask[0] != 0) || ((m & MASK_Y) != 0 && m_mask[1] != 0) || - ((m & MASK_Z) != 0 && m_mask[2] != 0) || ((m & MASK_W) != 0 && m_mask[3] != 0); -} diff --git a/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.inl b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.inl new file mode 100644 index 00000000..ccd3baf8 --- /dev/null +++ b/lib/hkStubs/Havok/Common/Base/Math/Vector/hkVector4fComparison.inl @@ -0,0 +1,57 @@ +#pragma once + +inline void hkVector4fComparison::setAnd(hkVector4fComparisonParameter a, + hkVector4fComparisonParameter b) { + m_mask = a.m_mask & b.m_mask; +} + +inline void hkVector4fComparison::setAndNot(hkVector4fComparisonParameter a, + hkVector4fComparisonParameter b) { + m_mask = a.m_mask & ~b.m_mask; +} + +inline void hkVector4fComparison::setXor(hkVector4fComparisonParameter a, + hkVector4fComparisonParameter b) { + m_mask = a.m_mask ^ b.m_mask; +} + +inline void hkVector4fComparison::setOr(hkVector4fComparisonParameter a, + hkVector4fComparisonParameter b) { + m_mask = a.m_mask | b.m_mask; +} + +inline void hkVector4fComparison::setNot(hkVector4fComparisonParameter a) { + m_mask = ~a.m_mask; +} + +inline void hkVector4fComparison::setSelect(hkVector4fComparisonParameter comp, + hkVector4fComparisonParameter trueValue, + hkVector4fComparisonParameter falseValue) { +#ifdef HK_VECTOR4F_AARCH64_NEON + m_mask = vbslq_u32(comp.m_mask, trueValue.m_mask, falseValue.m_mask); +#else + m_mask = (comp.m_mask & trueValue.m_mask) | (comp.m_mask & ~falseValue.m_mask); +#endif +} + +template +inline hkBool32 hkVector4fComparison::allAreSet() const { + return ((m & MASK_X) == 0 || m_mask[0] != 0) && ((m & MASK_Y) == 0 || m_mask[1] != 0) && + ((m & MASK_Z) == 0 || m_mask[2] != 0) && ((m & MASK_W) == 0 || m_mask[3] != 0); +} + +inline hkBool32 hkVector4fComparison::allAreSet(hkVector4fComparison::Mask m) const { + return ((m & MASK_X) == 0 || m_mask[0] != 0) && ((m & MASK_Y) == 0 || m_mask[1] != 0) && + ((m & MASK_Z) == 0 || m_mask[2] != 0) && ((m & MASK_W) == 0 || m_mask[3] != 0); +} + +template +inline hkBool32 hkVector4fComparison::anyIsSet() const { + return ((m & MASK_X) != 0 && m_mask[0] != 0) || ((m & MASK_Y) != 0 && m_mask[1] != 0) || + ((m & MASK_Z) != 0 && m_mask[2] != 0) || ((m & MASK_W) != 0 && m_mask[3] != 0); +} + +inline hkBool32 hkVector4fComparison::anyIsSet(Mask m) const { + return ((m & MASK_X) != 0 && m_mask[0] != 0) || ((m & MASK_Y) != 0 && m_mask[1] != 0) || + ((m & MASK_Z) != 0 && m_mask[2] != 0) || ((m & MASK_W) != 0 && m_mask[3] != 0); +} diff --git a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h index 9f40f9be..32c42ab1 100644 --- a/lib/hkStubs/Havok/Common/Base/Math/hkMath.h +++ b/lib/hkStubs/Havok/Common/Base/Math/hkMath.h @@ -2,18 +2,43 @@ #define HK_MATH_H -#include +// Note: these headers have to be included in a specific order. +// clang-format off +#include #include + +// Forward declarations +class hkVector4f; +class hkVector4fComparison; +class hkSimdFloat32; +class hkQuaternionf; +class hkMatrix3f; +class hkRotationf; +class hkTransformf; + +// Type aliases +using hkVector4fParameter = const hkVector4f&; +using hkVector4fComparisonParameter = const hkVector4fComparison&; +using hkSimdFloat32Parameter = const hkSimdFloat32&; +using hkQuaternionfParameter = const hkQuaternionf&; + +// Headers +#include +#include +#include +#include #include #include #include -#include -#include -#include -#include +// Implementations #include +#include +#include +#include + +// clang-format on namespace hkMath {