diff options
| author | ThePixelGamer <thepixelmaster2354@gmail.com> | 2024-07-26 18:00:57 -0500 |
|---|---|---|
| committer | ThePixelGamer <thepixelmaster2354@gmail.com> | 2024-07-26 18:00:57 -0500 |
| commit | de0fd08acc676caad7dd2f445f221473d7cd4b75 (patch) | |
| tree | 0808bc291b399ccbe9c8fe00b328f94a8da04aff /src/KingSystem/Physics | |
| parent | 96f611fa5d1c2704d91e5c490662ec8c0a741279 (diff) | |
Update libraries and adjust code to match again
Diffstat (limited to 'src/KingSystem/Physics')
4 files changed, 25 insertions, 31 deletions
diff --git a/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.cpp b/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.cpp index 1226372b..1ded03e0 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.cpp +++ b/src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.cpp @@ -11,9 +11,9 @@ BoxShape* BoxShape::make(const BoxShapeParam& param, sead::Heap* heap) { hkpBoxShape* box = nullptr; if (auto* storage = util::allocStorage<hkpBoxShape>(heap)) { const auto radius = param.convex_radius; - const hkVector4f half_extents{sead::Mathf::max(param.extents.x / 2 - radius, 0.001), - sead::Mathf::max(param.extents.y / 2 - radius, 0.001), - sead::Mathf::max(param.extents.z / 2 - radius, 0.001)}; + const hkVector4f half_extents{sead::Mathf::clampMin(param.extents.x / 2 - radius, 0.001), + sead::Mathf::clampMin(param.extents.y / 2 - radius, 0.001), + sead::Mathf::clampMin(param.extents.z / 2 - radius, 0.001)}; box = new (storage) hkpBoxShape(half_extents, radius); } @@ -122,9 +122,10 @@ const hkpShape* BoxShape::updateHavokShape() { if (mFlags.isOn(Flag::Dirty)) { { const auto radius = mHavokShape->getRadius(); - const sead::Vector3f half_extents{sead::Mathf::max(mExtents.x / 2 - radius, 0.001), - sead::Mathf::max(mExtents.y / 2 - radius, 0.001), - sead::Mathf::max(mExtents.z / 2 - radius, 0.001)}; + const sead::Vector3f half_extents{ + sead::Mathf::clampMin(mExtents.x / 2 - radius, 0.001), + sead::Mathf::clampMin(mExtents.y / 2 - radius, 0.001), + sead::Mathf::clampMin(mExtents.z / 2 - radius, 0.001)}; const auto ref_count = mHavokShape->getReferenceCount(); mHavokShape = new (mHavokShape) hkpBoxShape(toHkVec4(half_extents), radius); mHavokShape->setReferenceCount(ref_count); diff --git a/src/KingSystem/Physics/RigidBody/physRigidBody.cpp b/src/KingSystem/Physics/RigidBody/physRigidBody.cpp index 5a67d445..175dac29 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBody.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBody.cpp @@ -84,9 +84,9 @@ bool RigidBody::initMotionAccessorForDynamicMotion(sead::Heap* heap) { hkMatrix3 inertia; body->getInertiaLocal(inertia); - param.inertia = {sead::Mathf::max(inertia(0, 0), MinInertia), - sead::Mathf::max(inertia(1, 1), MinInertia), - sead::Mathf::max(inertia(2, 2), MinInertia)}; + param.inertia = {sead::Mathf::clampMin(inertia(0, 0), MinInertia), + sead::Mathf::clampMin(inertia(1, 1), MinInertia), + sead::Mathf::clampMin(inertia(2, 2), MinInertia)}; param.center_of_mass = toVec3(body->getCenterOfMassLocal()); param.linear_damping = body->getLinearDamping(); param.angular_damping = body->getAngularDamping(); @@ -126,9 +126,9 @@ bool RigidBody::createMotion(hkpMaxSizeMotion* motion, MotionType motion_type, case MotionType::Dynamic: { hkMatrix3f inertia_local; - inertia_local.m_col0.set(sead::Mathf::max(param.inertia.x, MinInertia), 0, 0); - inertia_local.m_col1.set(0, sead::Mathf::max(param.inertia.y, MinInertia), 0); - inertia_local.m_col2.set(0, 0, sead::Mathf::max(param.inertia.z, MinInertia)); + inertia_local.m_col0.set(sead::Mathf::clampMin(param.inertia.x, MinInertia), 0, 0); + inertia_local.m_col1.set(0, sead::Mathf::clampMin(param.inertia.y, MinInertia), 0); + inertia_local.m_col2.set(0, 0, sead::Mathf::clampMin(param.inertia.z, MinInertia)); hkpRigidBody::createDynamicRigidMotion( hkpMotion::MOTION_DYNAMIC, position, rotation, param.mass, inertia_local, @@ -1630,7 +1630,7 @@ bool RigidBody::isEntityMotionFlag80On() const { void RigidBody::setColImpulseScale(float scale) { if (!isEntity()) return; - scale = sead::Mathf::max(scale, 0.0); + scale = sead::Mathf::clampMin(scale, 0.0); getEntityMotionAccessor()->setColImpulseScale(scale); } diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyMotionEntity.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyMotionEntity.cpp index 3be3e533..9820d86b 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyMotionEntity.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyMotionEntity.cpp @@ -300,14 +300,6 @@ float RigidBodyMotionEntity::getMassInv() const { return mMotion->getMassInv(); } -static inline float max3(float a, float b, float c) { - return sead::Mathf::max(c, a > b ? a : b); -} - -static inline float min3(float a, float b, float c) { - return sead::Mathf::min(a < b ? a : b, c); -} - void RigidBodyMotionEntity::setInertiaLocal(const sead::Vector3f& inertia) { if (mBody->isCharacterControllerType()) return; @@ -317,8 +309,8 @@ void RigidBodyMotionEntity::setInertiaLocal(const sead::Vector3f& inertia) { return; } - const float max = max3(inertia.x, inertia.y, inertia.z); - const float min = min3(inertia.x, inertia.y, inertia.z); + const float max = sead::Mathf::max3(inertia.x, inertia.y, inertia.z); + const float min = sead::Mathf::min3(inertia.x, inertia.y, inertia.z); const float threshold = max * 0.8f; bool need_to_recreate_motion = false; diff --git a/src/KingSystem/Physics/System/physContactMgr.cpp b/src/KingSystem/Physics/System/physContactMgr.cpp index ccc25385..7872f3ef 100644 --- a/src/KingSystem/Physics/System/physContactMgr.cpp +++ b/src/KingSystem/Physics/System/physContactMgr.cpp @@ -551,19 +551,20 @@ void ContactMgr::setImpulseEntryContactInfo(RigidBody* body_a, RigidBody* body_b const auto relative_vel = linvel_a - linvel_b; const auto dot_neg = [&](const auto& vec) { return vec.dot(-contact_point_normal); }; - float magnitude = is_flag_off ? sead::Mathf::max(0.0, relative_vel.dot(-contact_point_normal)) : - sead::Mathf::max(0.0, relative_vel.length()); + float magnitude = is_flag_off ? + sead::Mathf::clampMin(0.0, relative_vel.dot(-contact_point_normal)) : + sead::Mathf::clampMin(0.0, relative_vel.length()); if (magnitude >= entry->magnitude) { float i1, i2; if (is_flag_off) { - i1 = sead::Mathf::min(sead::Mathf::max(0.0, dot_neg(linvel_a)), magnitude); - i2 = sead::Mathf::min(sead::Mathf::max(0.0, linvel_b.dot(contact_point_normal)), - sead::Mathf::max(0.0, dot_neg(relative_vel))); + i1 = sead::Mathf::min(sead::Mathf::clampMin(0.0, dot_neg(linvel_a)), magnitude); + i2 = sead::Mathf::min(sead::Mathf::clampMin(0.0, linvel_b.dot(contact_point_normal)), + sead::Mathf::clampMin(0.0, dot_neg(relative_vel))); } else { - i1 = sead::Mathf::min(sead::Mathf::max(0.0, linvel_a.length()), magnitude); - i2 = sead::Mathf::min(sead::Mathf::max(0.0, linvel_b.length()), - sead::Mathf::max(0.0, relative_vel.length())); + i1 = sead::Mathf::min(sead::Mathf::clampMin(0.0, linvel_a.length()), magnitude); + i2 = sead::Mathf::min(sead::Mathf::clampMin(0.0, linvel_b.length()), + sead::Mathf::clampMin(0.0, relative_vel.length())); } entry->magnitude = magnitude; |
