src/body/RigidBody.cpp
void RigidBody::updateLocalCenterOfMassFromColliders() {

    const Vector3 oldCenterOfMassWorld = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity);

    Vector3 centerOfMassLocal = computeCenterOfMass();

    const Vector3 centerOfMassWorld = mWorld.mTransformComponents.getTransform(mEntity) * centerOfMassLocal;

    // Set the center of mass
    mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMassLocal);
    mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, centerOfMassWorld);

    // Update the linear velocity of the center of mass
    Vector3 linearVelocity = mWorld.mRigidBodyComponents.getLinearVelocity(mEntity);
    const Vector3& angularVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
    linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMassWorld);
    mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);

    RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
             "Body " + std::to_string(mEntity.id) + ": Set centerOfMassLocal=" + centerOfMassLocal.to_string(),  __FILE__, __LINE__);
}
// Compute and set the local-space center of mass of the body using its colliders
/// This method uses the shape, mass density and transforms of the colliders to set
/// the center of mass of the body. Note that calling this method will overwrite the
/// mass that has been previously set with the RigidBody::setCenterOfMass() method. Moreover, this method
/// does not use the mass set by the user with the RigidBody::setMass() method to compute the center
/// of mass but only the mass density and volume of the colliders.
Compute and set the local-space center of mass of the body using its colliders
This method uses the shape, mass density and transforms of the colliders to set
the center of mass of the body. Note that calling this method will overwrite the
mass that has been previously set with the RigidBody::setCenterOfMass() method. Moreover, this method
does not use the mass set by the user with the RigidBody::setMass() method to compute the center
of mass but only the mass density and volume of the colliders.
Compute and set the local - space center of mass of the body using its colliders This method uses the shape mass density and transforms of the colliders to set the center of mass of the body . Note that calling this method will overwrite the mass that has been previously set with the RigidBody :: setCenterOfMass () method . Moreover this method does not use the mass set by the user with the RigidBody :: setMass () method to compute the center of mass but only the mass density and volume of the colliders .
void RigidBody::updateLocalCenterOfMassFromColliders() {
    const Vector3 oldCenterOfMassWorld = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity);
    Vector3 centerOfMassLocal = computeCenterOfMass();
    const Vector3 centerOfMassWorld = mWorld.mTransformComponents.getTransform(mEntity) * centerOfMassLocal;
    mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMassLocal);
    mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, centerOfMassWorld);
    Vector3 linearVelocity = mWorld.mRigidBodyComponents.getLinearVelocity(mEntity);
    const Vector3& angularVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
    linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMassWorld);
    mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);
    RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
             "Body " + std::to_string(mEntity.id) + ": Set centerOfMassLocal=" + centerOfMassLocal.to_string(),  __FILE__, __LINE__);
}
void RigidBody :: updateLocalCenterOfMassFromColliders ( ) { const Vector3 oldCenterOfMassWorld = mWorld . mRigidBodyComponents . getCenterOfMassWorld ( mEntity ) ; Vector3 centerOfMassLocal = computeCenterOfMass ( ) ; const Vector3 centerOfMassWorld = mWorld . mTransformComponents . getTransform ( mEntity ) * centerOfMassLocal ; mWorld . mRigidBodyComponents . setCenterOfMassLocal ( mEntity , centerOfMassLocal ) ; mWorld . mRigidBodyComponents . setCenterOfMassWorld ( mEntity , centerOfMassWorld ) ; Vector3 linearVelocity = mWorld . mRigidBodyComponents . getLinearVelocity ( mEntity ) ; const Vector3 & angularVelocity = mWorld . mRigidBodyComponents . getAngularVelocity ( mEntity ) ; linearVelocity += angularVelocity . cross ( centerOfMassWorld - oldCenterOfMassWorld ) ; mWorld . mRigidBodyComponents . setLinearVelocity ( mEntity , linearVelocity ) ; RP3D_LOG ( mWorld . mConfig . worldName , Logger :: Level :: Information , Logger :: Category :: Body , " " + std :: to_string ( mEntity . id ) + " " + centerOfMassLocal . to_string ( ) , __FILE__ , __LINE__ ) ; }
Compute and set the local-space center of mass of the body using its colliders
This method uses the shape, mass density and transforms of the colliders to set
the center of mass of the body.
Compute and set the local - space center of mass of the body using its colliders This method uses the shape mass density and transforms of the colliders to set the center of mass of the body .
// Set the center of mass // Update the linear velocity of the center of mass