src/body/RigidBody.cpp
void RigidBody::setLocalCenterOfMass(const Vector3& centerOfMass) {

    const Vector3 oldCenterOfMass = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity);
    mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMass);

    // Compute the center of mass in world-space coordinates
    mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * centerOfMass);

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

    RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
             "Body " + std::to_string(mEntity.id) + ": Set centerOfMassLocal=" + centerOfMass.to_string(),  __FILE__, __LINE__);
}
// Set the center of mass of the body (in local-space coordinates)
/// This method does not move the rigid body in the world.
/**
 * @param centerOfMass The center of mass of the body in local-space coordinates
 */
Set the center of mass of the body (in local-space coordinates)
This method does not move the rigid body in the world.

@param centerOfMass The center of mass of the body in local-space coordinates
Set the center of mass of the body ( in local - space coordinates ) This method does not move the rigid body in the world . @param centerOfMass The center of mass of the body in local - space coordinates
void RigidBody::setLocalCenterOfMass(const Vector3& centerOfMass) {
    const Vector3 oldCenterOfMass = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity);
    mWorld.mRigidBodyComponents.setCenterOfMassLocal(mEntity, centerOfMass);
    mWorld.mRigidBodyComponents.setCenterOfMassWorld(mEntity, mWorld.mTransformComponents.getTransform(mEntity) * centerOfMass);
    Vector3 linearVelocity = mWorld.mRigidBodyComponents.getLinearVelocity(mEntity);
    const Vector3& angularVelocity = mWorld.mRigidBodyComponents.getAngularVelocity(mEntity);
    const Vector3& centerOfMassWorld = mWorld.mRigidBodyComponents.getCenterOfMassWorld(mEntity);
    linearVelocity += angularVelocity.cross(centerOfMassWorld - oldCenterOfMass);
    mWorld.mRigidBodyComponents.setLinearVelocity(mEntity, linearVelocity);
    RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
             "Body " + std::to_string(mEntity.id) + ": Set centerOfMassLocal=" + centerOfMass.to_string(),  __FILE__, __LINE__);
}
void RigidBody :: setLocalCenterOfMass ( const Vector3 & centerOfMass ) { const Vector3 oldCenterOfMass = mWorld . mRigidBodyComponents . getCenterOfMassWorld ( mEntity ) ; mWorld . mRigidBodyComponents . setCenterOfMassLocal ( mEntity , centerOfMass ) ; mWorld . mRigidBodyComponents . setCenterOfMassWorld ( mEntity , mWorld . mTransformComponents . getTransform ( mEntity ) * centerOfMass ) ; Vector3 linearVelocity = mWorld . mRigidBodyComponents . getLinearVelocity ( mEntity ) ; const Vector3 & angularVelocity = mWorld . mRigidBodyComponents . getAngularVelocity ( mEntity ) ; const Vector3 & centerOfMassWorld = mWorld . mRigidBodyComponents . getCenterOfMassWorld ( mEntity ) ; linearVelocity += angularVelocity . cross ( centerOfMassWorld - oldCenterOfMass ) ; mWorld . mRigidBodyComponents . setLinearVelocity ( mEntity , linearVelocity ) ; RP3D_LOG ( mWorld . mConfig . worldName , Logger :: Level :: Information , Logger :: Category :: Body , " " + std :: to_string ( mEntity . id ) + " " + centerOfMass . to_string ( ) , __FILE__ , __LINE__ ) ; }
Set the center of mass of the body (in local-space coordinates)
This method does not move the rigid body in the world.
Set the center of mass of the body ( in local - space coordinates ) This method does not move the rigid body in the world .
// Compute the center of mass in world-space coordinates // Update the linear velocity of the center of mass