22 #ifndef PLAYRHO_DYNAMICS_BODY_HPP
23 #define PLAYRHO_DYNAMICS_BODY_HPP
84 using Joints = std::vector<KeyedJointPtr>;
173 bool resetMassData =
true);
468 bool IsIslanded() const noexcept;
471 void SetIslandedFlag() noexcept;
474 void UnsetIslandedFlag() noexcept;
480 void SetAwakeFlag() noexcept;
483 void UnsetAwakeFlag() noexcept;
491 void Advance(
Real alpha) noexcept;
494 void SetMassDataDirty() noexcept;
497 void UnsetMassDataDirty() noexcept;
500 void SetEnabledFlag() noexcept;
503 void UnsetEnabledFlag() noexcept;
509 bool Insert(
Joint* joint);
512 bool Erase(const
Contact* contact);
515 bool Erase(const
Joint* joint);
518 void ClearContacts();
548 World*
const m_world;
577 Time m_underActiveTime = 0;
654 return m_linearDamping;
659 m_linearDamping = linearDamping;
664 return m_angularDamping;
669 m_angularDamping = angularDamping;
676 m_flags |= e_impenetrableFlag;
680 m_flags &= ~e_impenetrableFlag;
689 inline void Body::SetAwakeFlag() noexcept
697 inline void Body::UnsetAwakeFlag() noexcept
719 m_underActiveTime = 0;
731 return m_underActiveTime;
736 if ((value == 0_s) || IsAccelerable())
738 m_underActiveTime = value;
744 m_underActiveTime = 0_s;
771 m_flags |= e_autoSleepFlag;
773 else if (IsSpeedable())
775 m_flags &= ~e_autoSleepFlag;
777 ResetUnderActiveTime();
788 return {begin(m_fixtures), end(m_fixtures),
size(m_fixtures)};
793 return {begin(m_fixtures), end(m_fixtures),
size(m_fixtures)};
798 return {begin(m_joints), end(m_joints),
size(m_joints)};
803 return {begin(m_joints), end(m_joints),
size(m_joints)};
808 return {begin(m_contacts), end(m_contacts),
size(m_contacts)};
823 return m_linearAcceleration;
828 return m_angularAcceleration;
831 inline void Body::Advance(
Real alpha) noexcept
834 assert(IsSpeedable() || m_sweep.pos1 == m_sweep.pos0);
837 m_sweep.Advance0(alpha);
838 m_sweep.pos1 = m_sweep.pos0;
847 inline void Body::SetMassDataDirty() noexcept
852 inline void Body::UnsetMassDataDirty() noexcept
862 inline void Body::SetEnabledFlag() noexcept
867 inline void Body::UnsetEnabledFlag() noexcept
872 inline bool Body::IsIslanded() const noexcept
877 inline void Body::SetIslandedFlag() noexcept
882 inline void Body::UnsetIslandedFlag() noexcept
894 return Acceleration{body.GetLinearAcceleration(), body.GetAngularAcceleration()};
905 body.SetAcceleration(value.linear, value.angular);
919 if (!body.IsAwake() && body.IsSpeedable())
931 if (body.IsAwake() && body.IsSleepingAllowed())
943 bool ShouldCollide(
const Body& lhs,
const Body& rhs) noexcept;
949 return body.GetSweep().pos1;
959 const auto invMass = body.GetInvMass();
967 body.SetAcceleration(value, body.GetAngularAcceleration());
974 body.SetAcceleration(body.GetLinearAcceleration(), value);
989 const auto invRotI = body.GetInvRotInertia();
990 const auto dp = point - body.GetWorldCenter();
993 body.SetAcceleration(linAccel, angAccel);
1008 const auto invRotI = body.GetInvRotInertia();
1009 const auto dp =
Length2{point - body.GetWorldCenter()};
1013 body.SetAcceleration(body.GetLinearAcceleration() + linAccel,
1014 body.GetAngularAcceleration() + angAccel);
1024 const auto linAccel = body.GetLinearAcceleration() + force * body.GetInvMass();
1025 const auto angAccel = body.GetAngularAcceleration();
1026 body.SetAcceleration(linAccel, angAccel);
1033 const auto linAccel = body.GetLinearAcceleration();
1034 const auto invRotI = body.GetInvRotInertia();
1035 const auto angAccel = torque * invRotI;
1036 body.SetAcceleration(linAccel, angAccel);
1048 const auto linAccel = body.GetLinearAcceleration();
1049 const auto invRotI = body.GetInvRotInertia();
1050 const auto angAccel = body.GetAngularAcceleration() + torque * invRotI;
1051 body.SetAcceleration(linAccel, angAccel);
1065 auto velocity = body.GetVelocity();
1066 velocity.linear += body.GetInvMass() * impulse;
1067 const auto invRotI = body.GetInvRotInertia();
1068 const auto dp = point - body.GetWorldCenter();
1070 body.SetVelocity(velocity);
1079 auto velocity = body.GetVelocity();
1080 const auto invRotI = body.GetInvRotInertia();
1082 body.SetVelocity(velocity);
1096 return Real{1} / body.GetInvRotInertia();
1114 return body.GetVelocity().linear;
1123 return body.GetVelocity().angular;
1151 return Transform(localPoint, body.GetTransformation());
1161 return Rotate(localVector, body.GetTransformation().q);
1168 return Rotate(localVector, body.GetTransformation().q);
1197 const Length2 worldPoint) noexcept
1199 const auto velocity = body.GetVelocity();
1200 const auto worldCtr = body.GetWorldCenter();
1201 const auto dp =
Length2{worldPoint - worldCtr};
1203 return velocity.linear + rlv;
1212 const Length2 localPoint) noexcept
1221 return body.GetLinearAcceleration() *
GetMass(body);
1289 return body.GetTransformation().p;
1297 return body.GetSweep().pos1.angular;
1303 return body.GetTransformation();
1311 body.SetTransform(xfm.p,
GetAngle(xfm.q));
1317 return Position{body.GetLocation(), body.GetAngle()};
1330 body.SetTransform(value,
GetAngle(body));
1349 #endif // PLAYRHO_DYNAMICS_BODY_HPP