Update the postion/orientation of the bodies
| 72 | |
| 73 | // Update the postion/orientation of the bodies |
| 74 | void 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 |
no test coverage detected