MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / updateBodiesState

Method updateBodiesState

src/systems/DynamicsSystem.cpp:74–110  ·  view source on GitHub ↗

Update the postion/orientation of the bodies

Source from the content-addressed store, hash-verified

72
73// Update the postion/orientation of the bodies
74void DynamicsSystem::updateBodiesState() {
75
76 RP3D_PROFILE("DynamicsSystem::updateBodiesState()", mProfiler);
77
78 const uint32 nbRigidBodyComponents = mRigidBodyComponents.getNbEnabledComponents();
79 for (uint32 i=0; i < nbRigidBodyComponents; i++) {
80
81 // Update the linear and angular velocity of the body
82 mRigidBodyComponents.mLinearVelocities[i] = mRigidBodyComponents.mConstrainedLinearVelocities[i];
83 mRigidBodyComponents.mAngularVelocities[i] = mRigidBodyComponents.mConstrainedAngularVelocities[i];
84
85 // Update the position of the center of mass of the body
86 mRigidBodyComponents.mCentersOfMassWorld[i] = mRigidBodyComponents.mConstrainedPositions[i];
87
88 // Update the orientation of the body
89 const Quaternion& constrainedOrientation = mRigidBodyComponents.mConstrainedOrientations[i];
90 mTransformComponents.getTransform(mRigidBodyComponents.mBodiesEntities[i]).setOrientation(constrainedOrientation.getUnit());
91 }
92
93 // Update the position of the body (using the new center of mass and new orientation)
94 for (uint32 i=0; i < nbRigidBodyComponents; i++) {
95
96 Transform& transform = mTransformComponents.getTransform(mRigidBodyComponents.mBodiesEntities[i]);
97 const Vector3& centerOfMassWorld = mRigidBodyComponents.mCentersOfMassWorld[i];
98 const Vector3& centerOfMassLocal = mRigidBodyComponents.mCentersOfMassLocal[i];
99 transform.setPosition(centerOfMassWorld - transform.getOrientation() * centerOfMassLocal);
100 }
101
102 // Update the local-to-world transform of the colliders
103 const uint32 nbColliderComponents = mColliderComponents.getNbEnabledComponents();
104 for (uint32 i=0; i < nbColliderComponents; i++) {
105
106 // Update the local-to-world transform of the collider
107 mColliderComponents.mLocalToWorldTransforms[i] = mTransformComponents.getTransform(mColliderComponents.mBodiesEntities[i]) *
108 mColliderComponents.mLocalToBodyTransforms[i];
109 }
110}
111
112// Integrate the velocities of rigid bodies.
113/// This method only set the temporary velocities but does not update

Callers 1

updateMethod · 0.80

Calls 4

setOrientationMethod · 0.80
setPositionMethod · 0.80
getUnitMethod · 0.45

Tested by

no test coverage detected