ksys/phys: Use named bools in RigidBody to improve call site readability

This commit is contained in:
Léo Lam 2022-12-17 22:10:38 +01:00
parent 294666ba13
commit 7934e14ad6
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
9 changed files with 98 additions and 69 deletions

View File

@ -82992,9 +82992,9 @@ Address,Quality,Size,Name
0x0000007100f8e3fc,U,000816,phys::RigidBody::x_11 0x0000007100f8e3fc,U,000816,phys::RigidBody::x_11
0x0000007100f8e72c,O,000136,_ZN4ksys4phys9RigidBody16setCollisionInfoEPNS0_13CollisionInfoE 0x0000007100f8e72c,O,000136,_ZN4ksys4phys9RigidBody16setCollisionInfoEPNS0_13CollisionInfoE
0x0000007100f8e7b4,O,000052,_ZN4ksys4phys9RigidBody19setContactPointInfoEPNS0_16ContactPointInfoE 0x0000007100f8e7b4,O,000052,_ZN4ksys4phys9RigidBody19setContactPointInfoEPNS0_16ContactPointInfoE
0x0000007100f8e7e8,O,000264,_ZN4ksys4phys9RigidBody26setFixedAndPreserveImpulseEbb 0x0000007100f8e7e8,O,000264,_ZN4ksys4phys9RigidBody26setFixedAndPreserveImpulseENS0_5FixedENS0_20MarkLinearVelAsDirtyE
0x0000007100f8e8f0,O,000460,_ZN4ksys4phys9RigidBody6freezeEbbb 0x0000007100f8e8f0,O,000460,_ZN4ksys4phys9RigidBody6freezeENS0_12ShouldFreezeENS0_18PreserveVelocitiesENS0_18PreserveMaxImpulseE
0x0000007100f8eabc,O,000384,_ZN4ksys4phys9RigidBody8setFixedEbb 0x0000007100f8eabc,O,000384,_ZN4ksys4phys9RigidBody8setFixedENS0_5FixedENS0_18PreserveVelocitiesE
0x0000007100f8ec3c,O,000312,_ZN4ksys4phys9RigidBody17setLinearVelocityERKN4sead7Vector3IfEEf 0x0000007100f8ec3c,O,000312,_ZN4ksys4phys9RigidBody17setLinearVelocityERKN4sead7Vector3IfEEf
0x0000007100f8ed74,O,000196,_ZN4ksys4phys9RigidBody18setAngularVelocityERKN4sead7Vector3IfEEf 0x0000007100f8ed74,O,000196,_ZN4ksys4phys9RigidBody18setAngularVelocityERKN4sead7Vector3IfEEf
0x0000007100f8ee38,O,000024,_ZN4ksys4phys9RigidBody16resetFrozenStateEv 0x0000007100f8ee38,O,000024,_ZN4ksys4phys9RigidBody16resetFrozenStateEv
@ -83026,8 +83026,8 @@ Address,Quality,Size,Name
0x0000007100f8faa0,O,000056,_ZN4ksys4phys9RigidBody28addGroundTypeToGroundHitMaskENS0_9GroundHitE 0x0000007100f8faa0,O,000056,_ZN4ksys4phys9RigidBody28addGroundTypeToGroundHitMaskENS0_9GroundHitE
0x0000007100f8fad8,O,000044,_ZNK4ksys4phys9RigidBody16getGroundHitTypeEv 0x0000007100f8fad8,O,000044,_ZNK4ksys4phys9RigidBody16getGroundHitTypeEv
0x0000007100f8fb04,O,000004,_ZN4ksys4phys9RigidBody8setColorERKN4sead7Color4fEPKvb 0x0000007100f8fb04,O,000004,_ZN4ksys4phys9RigidBody8setColorERKN4sead7Color4fEPKvb
0x0000007100f8fb08,O,000360,_ZN4ksys4phys9RigidBody12setTransformERKN4sead8Matrix34IfEEb 0x0000007100f8fb08,O,000360,_ZN4ksys4phys9RigidBody12setTransformERKN4sead8Matrix34IfEENS0_24PropagateToLinkedMotionsE
0x0000007100f8fc70,O,000196,_ZN4ksys4phys9RigidBody11setPositionERKN4sead7Vector3IfEEb 0x0000007100f8fc70,O,000196,_ZN4ksys4phys9RigidBody11setPositionERKN4sead7Vector3IfEENS0_24PropagateToLinkedMotionsE
0x0000007100f8fd34,O,000012,_ZNK4ksys4phys9RigidBody16isTransformDirtyEv 0x0000007100f8fd34,O,000012,_ZNK4ksys4phys9RigidBody16isTransformDirtyEv
0x0000007100f8fd40,O,000124,_ZN4ksys4phys9RigidBody8setScaleEf 0x0000007100f8fd40,O,000124,_ZN4ksys4phys9RigidBody8setScaleEf
0x0000007100f8fdbc,O,000328,_ZN4ksys4phys9RigidBody11updateShapeEv 0x0000007100f8fdbc,O,000328,_ZN4ksys4phys9RigidBody11updateShapeEv
@ -83052,13 +83052,13 @@ Address,Quality,Size,Name
0x0000007100f91378,O,000040,_ZNK4ksys4phys9RigidBody22getCenterOfMassInWorldEv 0x0000007100f91378,O,000040,_ZNK4ksys4phys9RigidBody22getCenterOfMassInWorldEv
0x0000007100f913a0,O,000992,_ZN4ksys4phys9RigidBody25changePositionAndRotationERKN4sead8Matrix34IfEEf 0x0000007100f913a0,O,000992,_ZN4ksys4phys9RigidBody25changePositionAndRotationERKN4sead8Matrix34IfEEf
0x0000007100f91780,O,000672,_ZN4ksys4phys9RigidBody17computeVelocitiesEP10hkVector4fS3_RKS2_RK13hkQuaternionff 0x0000007100f91780,O,000672,_ZN4ksys4phys9RigidBody17computeVelocitiesEP10hkVector4fS3_RKS2_RK13hkQuaternionff
0x0000007100f91a20,O,000580,_ZN4ksys4phys9RigidBody14changePositionERKN4sead7Vector3IfEEbf 0x0000007100f91a20,O,000580,_ZN4ksys4phys9RigidBody14changePositionERKN4sead7Vector3IfEENS0_19KeepAngularVelocityEf
0x0000007100f91c64,O,000536,_ZN4ksys4phys9RigidBody14changeRotationERKN4sead4QuatIfEEf 0x0000007100f91c64,O,000536,_ZN4ksys4phys9RigidBody14changeRotationERKN4sead4QuatIfEEf
0x0000007100f91e7c,O,000656,_ZN4ksys4phys9RigidBody14changeRotationERKN4sead8Matrix34IfEEf 0x0000007100f91e7c,O,000656,_ZN4ksys4phys9RigidBody14changeRotationERKN4sead8Matrix34IfEEf
0x0000007100f9210c,O,000968,_ZN4ksys4phys9RigidBody17computeVelocitiesEPN4sead7Vector3IfEES5_RKNS2_8Matrix34IfEE 0x0000007100f9210c,O,000968,_ZN4ksys4phys9RigidBody17computeVelocitiesEPN4sead7Vector3IfEES5_RKNS2_8Matrix34IfEE
0x0000007100f924d4,O,000644,_ZNK4ksys4phys9RigidBody22computeAngularVelocityEPN4sead7Vector3IfEERKNS2_8Matrix34IfEE 0x0000007100f924d4,O,000644,_ZNK4ksys4phys9RigidBody22computeAngularVelocityEPN4sead7Vector3IfEERKNS2_8Matrix34IfEE
0x0000007100f92758,O,000528,_ZNK4ksys4phys9RigidBody22computeAngularVelocityEPN4sead7Vector3IfEERKNS2_4QuatIfEE 0x0000007100f92758,O,000528,_ZNK4ksys4phys9RigidBody22computeAngularVelocityEPN4sead7Vector3IfEERKNS2_4QuatIfEE
0x0000007100f92968,O,000524,_ZNK4ksys4phys9RigidBody21computeLinearVelocityEPN4sead7Vector3IfEERKS4_b 0x0000007100f92968,O,000524,_ZNK4ksys4phys9RigidBody21computeLinearVelocityEPN4sead7Vector3IfEERKS4_NS0_30TakeAngularVelocityIntoAccountE
0x0000007100f92b74,O,000140,_ZN4ksys4phys9RigidBody17computeVelocitiesEP10hkVector4fS3_RKS2_RK13hkQuaternionf 0x0000007100f92b74,O,000140,_ZN4ksys4phys9RigidBody17computeVelocitiesEP10hkVector4fS3_RKS2_RK13hkQuaternionf
0x0000007100f92c00,O,000128,_ZN4ksys4phys9RigidBody22setCenterOfMassInLocalERKN4sead7Vector3IfEE 0x0000007100f92c00,O,000128,_ZN4ksys4phys9RigidBody22setCenterOfMassInLocalERKN4sead7Vector3IfEE
0x0000007100f92c80,O,000016,_ZNK4ksys4phys9RigidBody22getCenterOfMassInLocalEPN4sead7Vector3IfEE 0x0000007100f92c80,O,000016,_ZNK4ksys4phys9RigidBody22getCenterOfMassInLocalEPN4sead7Vector3IfEE
@ -83493,12 +83493,12 @@ Address,Quality,Size,Name
0x0000007100fa8d24,O,000044,_ZN4ksys4phys12RigidBodySetC1ERKN4sead14SafeStringBaseIcEE 0x0000007100fa8d24,O,000044,_ZN4ksys4phys12RigidBodySetC1ERKN4sead14SafeStringBaseIcEE
0x0000007100fa8d50,O,000020,_ZN4ksys4phys12RigidBodySetD1Ev 0x0000007100fa8d50,O,000020,_ZN4ksys4phys12RigidBodySetD1Ev
0x0000007100fa8d64,O,000004,_ZN4ksys4phys12RigidBodySetD0Ev 0x0000007100fa8d64,O,000004,_ZN4ksys4phys12RigidBodySetD0Ev
0x0000007100fa8d68,O,000080,_ZN4ksys4phys12RigidBodySet26setFixedAndPreserveImpulseEbb 0x0000007100fa8d68,O,000080,_ZN4ksys4phys12RigidBodySet26setFixedAndPreserveImpulseENS0_5FixedENS0_20MarkLinearVelAsDirtyE
0x0000007100fa8db8,O,000056,_ZN4ksys4phys12RigidBodySet16resetFrozenStateEv 0x0000007100fa8db8,O,000056,_ZN4ksys4phys12RigidBodySet16resetFrozenStateEv
0x0000007100fa8df0,O,000180,_ZN4ksys4phys12RigidBodySet22setUseSystemTimeFactorEb 0x0000007100fa8df0,O,000180,_ZN4ksys4phys12RigidBodySet22setUseSystemTimeFactorEb
0x0000007100fa8ea4,O,000180,_ZN4ksys4phys12RigidBodySet15clearFlag400000Eb 0x0000007100fa8ea4,O,000180,_ZN4ksys4phys12RigidBodySet15clearFlag400000Eb
0x0000007100fa8f58,O,000072,_ZN4ksys4phys12RigidBodySet22setEntityMotionFlag200Eb 0x0000007100fa8f58,O,000072,_ZN4ksys4phys12RigidBodySet22setEntityMotionFlag200Eb
0x0000007100fa8fa0,O,000080,_ZN4ksys4phys12RigidBodySet8setFixedEbb 0x0000007100fa8fa0,O,000080,_ZN4ksys4phys12RigidBodySet8setFixedENS0_5FixedENS0_18PreserveVelocitiesE
0x0000007100fa8ff0,O,000056,_ZN4ksys4phys12RigidBodySet28updateMotionTypeRelatedFlagsEv 0x0000007100fa8ff0,O,000056,_ZN4ksys4phys12RigidBodySet28updateMotionTypeRelatedFlagsEv
0x0000007100fa9028,O,000056,_ZN4ksys4phys12RigidBodySet32triggerScheduledMotionTypeChangeEv 0x0000007100fa9028,O,000056,_ZN4ksys4phys12RigidBodySet32triggerScheduledMotionTypeChangeEv
0x0000007100fa9060,O,000084,_ZNK4ksys4phys12RigidBodySet19hasActiveEntityBodyEv 0x0000007100fa9060,O,000084,_ZNK4ksys4phys12RigidBodySet19hasActiveEntityBodyEv

Can't render this file because it is too large.

View File

@ -33,7 +33,7 @@ void KorokTargetMove::calc_() {
auto* actor = mActor; auto* actor = mActor;
auto* body = actor->getMainBody(); auto* body = actor->getMainBody();
if (*mIsBezier_d || *mIsTargetWarp_m) { if (*mIsBezier_d || *mIsTargetWarp_m) {
body->setPosition(*mTargetPos_d, true); body->setPosition(*mTargetPos_d);
setFinished(); setFinished();
return; return;
} }
@ -42,7 +42,7 @@ void KorokTargetMove::calc_() {
sead::Vector3f pos(mtx(0, 3), mtx(1, 3), mtx(2, 3)); sead::Vector3f pos(mtx(0, 3), mtx(1, 3), mtx(2, 3));
ksys::VFR::chaseVec(&pos, *mTargetPos_d, *mSpeed_d); ksys::VFR::chaseVec(&pos, *mTargetPos_d, *mSpeed_d);
body->changePosition(pos, true); body->changePosition(pos, ksys::phys::KeepAngularVelocity{true});
sead::Vector3f t = pos - *mTargetPos_d; sead::Vector3f t = pos - *mTargetPos_d;
if (t.length() < *mSpeed_d) { if (t.length() < *mSpeed_d) {

View File

@ -139,7 +139,7 @@ void RagdollController::setTransform(const hkQsTransformf& transform) {
if (mExtraRigidBody) { if (mExtraRigidBody) {
sead::Matrix34f old_transform; sead::Matrix34f old_transform;
mRigidBodies[mRigidBodyIndex]->getTransform(&old_transform); mRigidBodies[mRigidBodyIndex]->getTransform(&old_transform);
mExtraRigidBody->setTransform(old_transform, true); mExtraRigidBody->setTransform(old_transform);
if (mGroupHandler) { if (mGroupHandler) {
mExtraRigidBody->setCollisionFilterInfo( mExtraRigidBody->setCollisionFilterInfo(

View File

@ -476,9 +476,10 @@ void RigidBody::setContactPointInfo(ContactPointInfo* info) {
System::instance()->registerContactPointInfo(info); System::instance()->registerContactPointInfo(info);
} }
void RigidBody::freeze(bool should_freeze, bool preserve_velocities, bool preserve_max_impulse) { void RigidBody::freeze(ShouldFreeze should_freeze, PreserveVelocities preserve_velocities,
if (hasFlag(Flag::Frozen) == should_freeze) { PreserveMaxImpulse preserve_max_impulse) {
if (should_freeze) { if (hasFlag(Flag::Frozen) == bool(should_freeze)) {
if (bool(should_freeze)) {
setLinearVelocity(sead::Vector3f::zero); setLinearVelocity(sead::Vector3f::zero);
setAngularVelocity(sead::Vector3f::zero); setAngularVelocity(sead::Vector3f::zero);
} }
@ -486,41 +487,43 @@ void RigidBody::freeze(bool should_freeze, bool preserve_velocities, bool preser
} }
if (!mMotionAccessor) { if (!mMotionAccessor) {
mFlags.change(Flag::Frozen, should_freeze); mFlags.change(Flag::Frozen, bool(should_freeze));
return; return;
} }
if (should_freeze) { if (bool(should_freeze)) {
mMotionAccessor->freeze(true, preserve_velocities, preserve_max_impulse); mMotionAccessor->freeze(true, bool(preserve_velocities), bool(preserve_max_impulse));
mFlags.set(Flag::Frozen); mFlags.set(Flag::Frozen);
} else { } else {
mFlags.reset(Flag::Frozen); mFlags.reset(Flag::Frozen);
mMotionAccessor->freeze(false, preserve_velocities, preserve_max_impulse); mMotionAccessor->freeze(false, bool(preserve_velocities), bool(preserve_max_impulse));
} }
} }
void RigidBody::setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty) { void RigidBody::setFixedAndPreserveImpulse(Fixed fixed,
if (hasFlag(Flag::FixedWithImpulsePreserved) != fixed) { MarkLinearVelAsDirty mark_linear_vel_as_dirty) {
mFlags.change(Flag::FixedWithImpulsePreserved, fixed); if (hasFlag(Flag::FixedWithImpulsePreserved) != bool(fixed)) {
if (!fixed && mark_linear_vel_as_dirty) { mFlags.change(Flag::FixedWithImpulsePreserved, bool(fixed));
if (!bool(fixed) && bool(mark_linear_vel_as_dirty)) {
setMotionFlag(MotionFlag::DirtyLinearVelocity); setMotionFlag(MotionFlag::DirtyLinearVelocity);
} }
} }
freeze(hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed), true, true); freeze(ShouldFreeze{hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed)},
PreserveVelocities{true}, PreserveMaxImpulse{true});
} }
void RigidBody::setFixed(bool fixed, bool preserve_velocities) { void RigidBody::setFixed(Fixed fixed, PreserveVelocities preserve_velocities) {
if (hasFlag(Flag::Fixed) != fixed) { if (hasFlag(Flag::Fixed) != bool(fixed)) {
mFlags.change(Flag::Fixed, fixed); mFlags.change(Flag::Fixed, bool(fixed));
if (!fixed) { if (!bool(fixed)) {
setMotionFlag(MotionFlag::DirtyLinearVelocity); setMotionFlag(MotionFlag::DirtyLinearVelocity);
setMotionFlag(MotionFlag::_40000); setMotionFlag(MotionFlag::_40000);
} }
} }
freeze(hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed), preserve_velocities, freeze(ShouldFreeze{hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed)},
false); preserve_velocities, PreserveMaxImpulse{false});
} }
void RigidBody::resetFrozenState() { void RigidBody::resetFrozenState() {
@ -835,13 +838,14 @@ void RigidBody::setColor(const sead::Color4f& color, const void* a, bool b) {
// (which are normally invisible). // (which are normally invisible).
} }
void RigidBody::setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions) { void RigidBody::setPosition(const sead::Vector3f& position,
PropagateToLinkedMotions propagate_to_linked_motions) {
if (util::isVectorInvalid(position)) { if (util::isVectorInvalid(position)) {
onInvalidParameter(); onInvalidParameter();
return; return;
} }
mMotionAccessor->setPosition(position, propagate_to_linked_motions); mMotionAccessor->setPosition(position, bool(propagate_to_linked_motions));
} }
void RigidBody::getPosition(sead::Vector3f* position) const { void RigidBody::getPosition(sead::Vector3f* position) const {
@ -888,13 +892,14 @@ sead::Matrix34f RigidBody::getTransform() const {
return transform; return transform;
} }
void RigidBody::setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions) { void RigidBody::setTransform(const sead::Matrix34f& mtx,
PropagateToLinkedMotions propagate_to_linked_motions) {
if (util::isMatrixInvalid(mtx)) { if (util::isMatrixInvalid(mtx)) {
onInvalidParameter(); onInvalidParameter();
return; return;
} }
mMotionAccessor->setTransform(mtx, propagate_to_linked_motions); mMotionAccessor->setTransform(mtx, bool(propagate_to_linked_motions));
} }
bool RigidBody::isTransformDirty() const { bool RigidBody::isTransformDirty() const {
@ -1111,14 +1116,15 @@ void RigidBody::changePositionAndRotation(const sead::Matrix34f& transform, floa
mMotionAccessor->setAngularVelocity(angular_velocity, epsilon); mMotionAccessor->setAngularVelocity(angular_velocity, epsilon);
} }
void RigidBody::changePosition(const sead::Vector3f& target_position, bool keep_angular_velocity, void RigidBody::changePosition(const sead::Vector3f& target_position,
float epsilon) { KeepAngularVelocity keep_angular_velocity, float epsilon) {
hkVector4f velocity; hkVector4f velocity;
computeLinearVelocity(&velocity, target_position, keep_angular_velocity); computeLinearVelocity(&velocity, target_position,
TakeAngularVelocityIntoAccount{bool(keep_angular_velocity)});
mMotionAccessor->setLinearVelocity(velocity, epsilon); mMotionAccessor->setLinearVelocity(velocity, epsilon);
if (!keep_angular_velocity) if (!bool(keep_angular_velocity))
mMotionAccessor->setAngularVelocity(sead::Vector3f::zero, epsilon); mMotionAccessor->setAngularVelocity(sead::Vector3f::zero, epsilon);
} }
@ -1189,13 +1195,13 @@ void RigidBody::computeLinearVelocity(hkVector4f* velocity, const hkVector4f& ta
velocity->mul(inv_delta_time); velocity->mul(inv_delta_time);
} }
KSYS_ALWAYS_INLINE void RigidBody::computeLinearVelocity(hkVector4f* velocity, KSYS_ALWAYS_INLINE void
const hkVector4f& target_position, RigidBody::computeLinearVelocity(hkVector4f* velocity, const hkVector4f& target_position,
bool take_angular_velocity_into_account, TakeAngularVelocityIntoAccount take_angular_velocity_into_account,
float inv_delta_time) const { float inv_delta_time) const {
auto hk_current_pos = toHkVec4(getPosition()); auto hk_current_pos = toHkVec4(getPosition());
if (take_angular_velocity_into_account) { if (bool(take_angular_velocity_into_account)) {
const auto center = getCenterOfMassInLocal(); const auto center = getCenterOfMassInLocal();
if (center.x == 0 && center.y == 0 && center.z == 0) { if (center.x == 0 && center.y == 0 && center.z == 0) {
hkVector4f rel_pos; hkVector4f rel_pos;
@ -1212,18 +1218,18 @@ KSYS_ALWAYS_INLINE void RigidBody::computeLinearVelocity(hkVector4f* velocity,
velocity->mul(inv_delta_time); velocity->mul(inv_delta_time);
} }
KSYS_ALWAYS_INLINE void KSYS_ALWAYS_INLINE void RigidBody::computeLinearVelocity(
RigidBody::computeLinearVelocity(hkVector4f* velocity, const sead::Vector3f& target_position, hkVector4f* velocity, const sead::Vector3f& target_position,
bool take_angular_velocity_into_account) const { TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const {
const float inv_delta_time = getInvDeltaTime(); const float inv_delta_time = getInvDeltaTime();
const auto hk_target_pos = toHkVec4(target_position); const auto hk_target_pos = toHkVec4(target_position);
computeLinearVelocity(velocity, hk_target_pos, take_angular_velocity_into_account, computeLinearVelocity(velocity, hk_target_pos, take_angular_velocity_into_account,
inv_delta_time); inv_delta_time);
} }
void RigidBody::computeLinearVelocity(sead::Vector3f* velocity, void RigidBody::computeLinearVelocity(
const sead::Vector3f& target_position, sead::Vector3f* velocity, const sead::Vector3f& target_position,
bool take_angular_velocity_into_account) const { TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const {
hkVector4f result; hkVector4f result;
computeLinearVelocity(&result, target_position, take_angular_velocity_into_account); computeLinearVelocity(&result, target_position, take_angular_velocity_into_account);
storeToVec3(velocity, result); storeToVec3(velocity, result);
@ -1744,7 +1750,7 @@ void* RigidBody::m11() {
void RigidBody::onMaxPositionExceeded() { void RigidBody::onMaxPositionExceeded() {
// debug logging? // debug logging?
[[maybe_unused]] sead::Vector3f position = getPosition(); [[maybe_unused]] sead::Vector3f position = getPosition();
setPosition(sead::Vector3f::zero, true); setPosition(sead::Vector3f::zero, PropagateToLinkedMotions{true});
} }
const char* RigidBody::getName() { const char* RigidBody::getName() {

View File

@ -34,6 +34,15 @@ class RigidBodyMotionSensor;
class SystemGroupHandler; class SystemGroupHandler;
class UserTag; class UserTag;
enum class ShouldFreeze : bool;
enum class PreserveVelocities : bool;
enum class PreserveMaxImpulse : bool;
enum class Fixed : bool;
enum class MarkLinearVelAsDirty : bool;
enum class PropagateToLinkedMotions : bool;
enum class KeepAngularVelocity : bool;
enum class TakeAngularVelocityIntoAccount : bool;
class RigidBase { class RigidBase {
public: public:
virtual ~RigidBase() = default; virtual ~RigidBase() = default;
@ -201,9 +210,10 @@ public:
ContactPointInfo* getContactPointInfo() const { return mContactPointInfo; } ContactPointInfo* getContactPointInfo() const { return mContactPointInfo; }
void setContactPointInfo(ContactPointInfo* info); void setContactPointInfo(ContactPointInfo* info);
void freeze(bool should_freeze, bool preserve_velocities, bool preserve_max_impulse); void freeze(ShouldFreeze should_freeze, PreserveVelocities preserve_velocities,
void setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty); PreserveMaxImpulse preserve_max_impulse);
void setFixed(bool fixed, bool preserve_velocities); void setFixedAndPreserveImpulse(Fixed fixed, MarkLinearVelAsDirty mark_linear_vel_as_dirty);
void setFixed(Fixed fixed, PreserveVelocities preserve_velocities);
void resetFrozenState(); void resetFrozenState();
// 0x0000007100f8ee50 - FIXME: figure out what type is // 0x0000007100f8ee50 - FIXME: figure out what type is
@ -282,7 +292,9 @@ public:
void setColor(const sead::Color4f& color, const void* a, bool b); void setColor(const sead::Color4f& color, const void* a, bool b);
void setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions); void setPosition(
const sead::Vector3f& position,
PropagateToLinkedMotions propagate_to_linked_motions = PropagateToLinkedMotions{true});
void getPosition(sead::Vector3f* position) const; void getPosition(sead::Vector3f* position) const;
sead::Vector3f getPosition() const; sead::Vector3f getPosition() const;
virtual void onImpulse(RigidBody* body_b, float impulse) const; virtual void onImpulse(RigidBody* body_b, float impulse) const;
@ -296,7 +308,9 @@ public:
void getTransform(sead::Matrix34f* mtx) const; void getTransform(sead::Matrix34f* mtx) const;
sead::Matrix34f getTransform() const; sead::Matrix34f getTransform() const;
void setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions); void setTransform(
const sead::Matrix34f& mtx,
PropagateToLinkedMotions propagate_to_linked_motions = PropagateToLinkedMotions{true});
bool isTransformDirty() const; bool isTransformDirty() const;
void updateShape(); void updateShape();
@ -332,7 +346,8 @@ public:
/// Modify the body's position by changing the linear velocity. /// Modify the body's position by changing the linear velocity.
/// This is preferable to setting the position directly (see changePositionAndRotation for an /// This is preferable to setting the position directly (see changePositionAndRotation for an
/// explanation). /// explanation).
void changePosition(const sead::Vector3f& target_position, bool keep_angular_velocity, void changePosition(const sead::Vector3f& target_position,
KeepAngularVelocity keep_angular_velocity,
float epsilon = sead::Mathf::epsilon()); float epsilon = sead::Mathf::epsilon());
/// Modify the body's rotation by changing the angular velocity. /// Modify the body's rotation by changing the angular velocity.
@ -361,13 +376,16 @@ public:
const hkQuaternionf& rotation, float inv_delta_time) const; const hkQuaternionf& rotation, float inv_delta_time) const;
/// Compute the linear velocity that would be necessary to instantly reach the target position. /// Compute the linear velocity that would be necessary to instantly reach the target position.
void computeLinearVelocity(hkVector4f* velocity, const hkVector4f& target_position, void computeLinearVelocity(hkVector4f* velocity, const hkVector4f& target_position,
bool take_angular_velocity_into_account, float inv_delta_time) const; TakeAngularVelocityIntoAccount take_angular_velocity_into_account,
float inv_delta_time) const;
/// Compute the linear velocity that would be necessary to instantly reach the target position. /// Compute the linear velocity that would be necessary to instantly reach the target position.
void computeLinearVelocity(hkVector4f* velocity, const sead::Vector3f& target_position, void
bool take_angular_velocity_into_account) const; computeLinearVelocity(hkVector4f* velocity, const sead::Vector3f& target_position,
TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const;
/// Compute the linear velocity that would be necessary to instantly reach the target position. /// Compute the linear velocity that would be necessary to instantly reach the target position.
void computeLinearVelocity(sead::Vector3f* velocity, const sead::Vector3f& target_position, void
bool take_angular_velocity_into_account) const; computeLinearVelocity(sead::Vector3f* velocity, const sead::Vector3f& target_position,
TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const;
/// Compute the linear and angular velocities that would be necessary to instantly reach the /// Compute the linear and angular velocities that would be necessary to instantly reach the
/// target position and rotation. /// target position and rotation.

View File

@ -624,7 +624,7 @@ void RigidBodyMotionEntity::copyTransformToAllLinkedBodies() {
if (!body->isAddedToWorld() && body->isAddingBodyToWorld()) { if (!body->isAddedToWorld() && body->isAddingBodyToWorld()) {
sead::Matrix34f transform; sead::Matrix34f transform;
mBody->getTransform(&transform); mBody->getTransform(&transform);
body->setTransform(transform, true); body->setTransform(transform);
} }
} }
} }

View File

@ -11,7 +11,8 @@ RigidBodySet::~RigidBodySet() {
util::PrintDebug("~RigidBodySet"); util::PrintDebug("~RigidBodySet");
} }
void RigidBodySet::setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty) { void RigidBodySet::setFixedAndPreserveImpulse(Fixed fixed,
MarkLinearVelAsDirty mark_linear_vel_as_dirty) {
for (auto& body : mRigidBodies) for (auto& body : mRigidBodies)
body.setFixedAndPreserveImpulse(fixed, mark_linear_vel_as_dirty); body.setFixedAndPreserveImpulse(fixed, mark_linear_vel_as_dirty);
} }
@ -36,7 +37,7 @@ void RigidBodySet::setEntityMotionFlag200(bool set) {
body.setEntityMotionFlag200(set); body.setEntityMotionFlag200(set);
} }
void RigidBodySet::setFixed(bool fixed, bool preserve_velocities) { void RigidBodySet::setFixed(Fixed fixed, PreserveVelocities preserve_velocities) {
for (auto& body : mRigidBodies) for (auto& body : mRigidBodies)
body.setFixed(fixed, preserve_velocities); body.setFixed(fixed, preserve_velocities);
} }
@ -107,7 +108,7 @@ void RigidBodySet::setSystemGroupHandler(SystemGroupHandler* handler, ContactLay
void RigidBodySet::setTransform(const sead::Matrix34f& mtx) { void RigidBodySet::setTransform(const sead::Matrix34f& mtx) {
for (auto& body : mRigidBodies) for (auto& body : mRigidBodies)
body.setTransform(mtx, true); body.setTransform(mtx);
} }
void RigidBodySet::enableContactLayer(ContactLayer layer) { void RigidBodySet::enableContactLayer(ContactLayer layer) {

View File

@ -13,6 +13,10 @@ class RigidBody;
class SystemGroupHandler; class SystemGroupHandler;
class UserTag; class UserTag;
enum class Fixed : bool;
enum class MarkLinearVelAsDirty : bool;
enum class PreserveVelocities : bool;
class RigidBodySet : public sead::hostio::Node { class RigidBodySet : public sead::hostio::Node {
public: public:
explicit RigidBodySet(const sead::SafeString& name); explicit RigidBodySet(const sead::SafeString& name);
@ -24,12 +28,12 @@ public:
const sead::PtrArray<RigidBody>& getRigidBodies() const { return mRigidBodies; } const sead::PtrArray<RigidBody>& getRigidBodies() const { return mRigidBodies; }
RigidBody* getRigidBody(int idx) const { return mRigidBodies[idx]; } RigidBody* getRigidBody(int idx) const { return mRigidBodies[idx]; }
void setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty); void setFixedAndPreserveImpulse(Fixed fixed, MarkLinearVelAsDirty mark_linear_vel_as_dirty);
void resetFrozenState(); void resetFrozenState();
void setUseSystemTimeFactor(bool use); void setUseSystemTimeFactor(bool use);
void clearFlag400000(bool clear); void clearFlag400000(bool clear);
void setEntityMotionFlag200(bool set); void setEntityMotionFlag200(bool set);
void setFixed(bool fixed, bool preserve_velocities); void setFixed(Fixed fixed, PreserveVelocities preserve_velocities);
void updateMotionTypeRelatedFlags(); void updateMotionTypeRelatedFlags();
void triggerScheduledMotionTypeChange(); void triggerScheduledMotionTypeChange();

View File

@ -126,7 +126,7 @@ void StaticCompoundRigidBodyGroup::addToWorld() {
auto lock = body->makeScopedLock(); auto lock = body->makeScopedLock();
body->setTransform(getTransform(), true); body->setTransform(getTransform());
if (body->getMotionFlags().isOn(RigidBody::MotionFlag::BodyRemovalRequested)) { if (body->getMotionFlags().isOn(RigidBody::MotionFlag::BodyRemovalRequested)) {
body->resetMotionFlagDirect(RigidBody::MotionFlag::BodyRemovalRequested); body->resetMotionFlagDirect(RigidBody::MotionFlag::BodyRemovalRequested);
@ -204,7 +204,7 @@ void StaticCompoundRigidBodyGroup::applyExtraTransforms() {
} }
for (int i = 0, n = mRigidBodies.size(); i < n; ++i) { for (int i = 0, n = mRigidBodies.size(); i < n; ++i) {
mRigidBodies[i]->setTransform(getTransform(), true); mRigidBodies[i]->setTransform(getTransform());
} }
} }