ReactPhysics3D  v0.10.1
C++ Physics engine library
reactphysics3d::RigidBody Class Reference

This class represents a rigid body of the physics engine. More...

#include <include/reactphysics3d/body/RigidBody.h>

Inheritance diagram for reactphysics3d::RigidBody:
reactphysics3d::Body

Public Member Functions

 RigidBody (PhysicsWorld &world, Entity entity)
 Constructor. More...
 
virtual ~RigidBody () override=default
 Destructor.
 
 RigidBody (const RigidBody &body)=delete
 Deleted copy-constructor.
 
RigidBodyoperator= (const RigidBody &body)=delete
 Deleted assignment operator.
 
virtual void setTransform (const Transform &transform) override
 Set the current position and orientation. More...
 
decimal getMass () const
 Return the mass of the body. More...
 
void setMass (decimal mass)
 Set the mass of the rigid body. More...
 
Vector3 getLinearVelocity () const
 Return the linear velocity. More...
 
void setLinearVelocity (const Vector3 &linearVelocity)
 Set the linear velocity of the body. More...
 
Vector3 getAngularVelocity () const
 Return the angular velocity. More...
 
void setAngularVelocity (const Vector3 &angularVelocity)
 Set the angular velocity. More...
 
const Vector3getLocalInertiaTensor () const
 Return the local inertia tensor of the body (in body coordinates) More...
 
void setLocalInertiaTensor (const Vector3 &inertiaTensorLocal)
 Set the local inertia tensor of the body (in body coordinates) More...
 
const Vector3getLocalCenterOfMass () const
 Return the center of mass of the body (in local-space coordinates) More...
 
void setLocalCenterOfMass (const Vector3 &centerOfMass)
 Set the center of mass of the body (in local-space coordinates) More...
 
void updateLocalCenterOfMassFromColliders ()
 Compute and set the local-space center of mass of the body using its colliders. More...
 
void updateLocalInertiaTensorFromColliders ()
 Compute and set the local-space inertia tensor of the body using its colliders. More...
 
void updateMassFromColliders ()
 Compute and set the mass of the body using its colliders. More...
 
void updateMassPropertiesFromColliders ()
 Compute and set the center of mass, the mass and the local-space inertia tensor of the body using its colliders. More...
 
BodyType getType () const
 Return the type of the body. More...
 
void setType (BodyType type)
 Set the type of the body. More...
 
bool isGravityEnabled () const
 Return true if the gravity needs to be applied to this rigid body. More...
 
void enableGravity (bool isEnabled)
 Set the variable to know if the gravity is applied to this rigid body. More...
 
void setIsSleeping (bool isSleeping)
 Set the variable to know whether or not the body is sleeping.
 
decimal getLinearDamping () const
 Return the linear velocity damping factor. More...
 
void setLinearDamping (decimal linearDamping)
 Set the linear damping factor. More...
 
decimal getAngularDamping () const
 Return the angular velocity damping factor. More...
 
void setAngularDamping (decimal angularDamping)
 Set the angular damping factor. More...
 
const Vector3getLinearLockAxisFactor () const
 Return the lock translation factor. More...
 
void setLinearLockAxisFactor (const Vector3 &linearLockAxisFactor) const
 Set the linear lock factor. More...
 
const Vector3getAngularLockAxisFactor () const
 Return the lock rotation factor. More...
 
void setAngularLockAxisFactor (const Vector3 &angularLockAxisFactor) const
 Set the lock rotation factor. More...
 
void applyLocalForceAtCenterOfMass (const Vector3 &force)
 Manually apply an external force (in local-space) to the body at its center of mass. More...
 
void applyWorldForceAtCenterOfMass (const Vector3 &force)
 Manually apply an external force (in world-space) to the body at its center of mass. More...
 
void applyLocalForceAtLocalPosition (const Vector3 &force, const Vector3 &point)
 Manually apply an external force (in local-space) to the body at a given point (in local-space). More...
 
void applyWorldForceAtLocalPosition (const Vector3 &force, const Vector3 &point)
 Manually apply an external force (in world-space) to the body at a given point (in local-space). More...
 
void applyLocalForceAtWorldPosition (const Vector3 &force, const Vector3 &point)
 Manually apply an external force (in local-space) to the body at a given point (in world-space). More...
 
void applyWorldForceAtWorldPosition (const Vector3 &force, const Vector3 &point)
 Manually apply an external force (in world-space) to the body at a given point (in world-space). More...
 
void applyWorldTorque (const Vector3 &torque)
 Manually apply an external torque to the body (in world-space). More...
 
void applyLocalTorque (const Vector3 &torque)
 Manually apply an external torque to the body (in local-space). More...
 
void resetForce ()
 Reset the manually applied force to zero.
 
void resetTorque ()
 Reset the manually applied torque to zero.
 
const Vector3getForce () const
 Return the total manually applied force on the body (in world-space) More...
 
const Vector3getTorque () const
 Return the total manually applied torque on the body (in world-space) More...
 
bool isAllowedToSleep () const
 Return whether or not the body is allowed to sleep. More...
 
void setIsAllowedToSleep (bool isAllowedToSleep)
 Set whether or not the body is allowed to go to sleep. More...
 
bool isSleeping () const
 Return whether or not the body is sleeping. More...
 
virtual void setIsActive (bool isActive) override
 Set whether or not the body is active. More...
 
virtual CollideraddCollider (CollisionShape *collisionShape, const Transform &transform) override
 Create a new collider and add it to the body. More...
 
virtual void removeCollider (Collider *collider) override
 Remove a collider from the body. More...
 
- Public Member Functions inherited from reactphysics3d::Body
 Body (PhysicsWorld &world, Entity entity)
 Constructor. More...
 
virtual ~Body ()
 Destructor.
 
 Body (const Body &body)=delete
 Deleted copy-constructor.
 
Bodyoperator= (const Body &body)=delete
 Deleted assignment operator.
 
Entity getEntity () const
 Return the corresponding entity of the body. More...
 
bool isActive () const
 Return true if the body is active. More...
 
void * getUserData () const
 Return a pointer to the user data attached to this body. More...
 
void setUserData (void *userData)
 Attach user data to this body. More...
 
const TransformgetTransform () const
 Return the current position and orientation. More...
 
bool testPointInside (const Vector3 &worldPoint) const
 Return true if a point is inside the collision body. More...
 
bool raycast (const Ray &ray, RaycastInfo &raycastInfo)
 Raycast method with feedback information. More...
 
bool testAABBOverlap (const AABB &worldAABB) const
 Test if the collision body overlaps with a given AABB. More...
 
AABB getAABB () const
 Compute and return the AABB of the body by merging all colliders AABBs. More...
 
const CollidergetCollider (uint32 colliderIndex) const
 Return a const pointer to a given collider of the body. More...
 
CollidergetCollider (uint32 colliderIndex)
 Return a pointer to a given collider of the body. More...
 
uint32 getNbColliders () const
 Return the number of colliders associated with this body. More...
 
Vector3 getWorldPoint (const Vector3 &localPoint) const
 Return the world-space coordinates of a point given the local-space coordinates of the body. More...
 
Vector3 getWorldVector (const Vector3 &localVector) const
 Return the world-space vector of a vector given in local-space coordinates of the body. More...
 
Vector3 getLocalPoint (const Vector3 &worldPoint) const
 Return the body local-space coordinates of a point given in the world-space coordinates. More...
 
Vector3 getLocalVector (const Vector3 &worldVector) const
 Return the body local-space coordinates of a vector given in the world-space coordinates. More...
 
void setIsDebugEnabled (bool enabled)
 Set whether or not debug lines are computed for this body. More...
 
bool isDebugEnabled () const
 Return true if debug lines should be computed for this body. More...
 

Detailed Description

This class represents a rigid body of the physics engine.

A rigid body is a non-deformable body that has a constant mass. This class inherits from the Body class.

Constructor & Destructor Documentation

◆ RigidBody()

RigidBody::RigidBody ( PhysicsWorld world,
Entity  entity 
)

Constructor.

Parameters
worldThe world where the body has been added
entityThe entity of the rigidbody

Member Function Documentation

◆ addCollider()

Collider * RigidBody::addCollider ( CollisionShape collisionShape,
const Transform transform 
)
overridevirtual

Create a new collider and add it to the body.

This method will return a pointer to a new collider.

A collider is an object with a collision shape that is attached to a body. It is possible to attach multiple colliders to a given body. You can use the returned collider to get and set information about the corresponding collision shape for that body.

Parameters
collisionShapeA pointer to the collision shape of the new collider
transformThe transformation of the collider that transforms the local-space of the collider into the local-space of the body
Returns
A pointer to the collider that has been created

Reimplemented from reactphysics3d::Body.

◆ applyLocalForceAtCenterOfMass()

void RigidBody::applyLocalForceAtCenterOfMass ( const Vector3 force)

Manually apply an external force (in local-space) to the body at its center of mass.

If the body is sleeping, calling this method will wake it up.

Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
forceThe external force (in local-space of the body) to apply on the center of mass of the body (in Newtons)

◆ applyLocalForceAtLocalPosition()

void RigidBody::applyLocalForceAtLocalPosition ( const Vector3 force,
const Vector3 point 
)

Manually apply an external force (in local-space) to the body at a given point (in local-space).

If the point is not at the center of mass of the body, it will also generate some torque and therefore, change the angular velocity of the body.

If the body is sleeping, calling this method will wake it up. Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
forceThe force (in local-space of the body) to apply on the body (in Newtons)
pointThe point where the force is applied (in local-space of the body)

◆ applyLocalForceAtWorldPosition()

void RigidBody::applyLocalForceAtWorldPosition ( const Vector3 force,
const Vector3 point 
)

Manually apply an external force (in local-space) to the body at a given point (in world-space).

If the point is not at the center of mass of the body, it will also generate some torque and therefore, change the angular velocity of the body.

If the body is sleeping, calling this method will wake it up. Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
forceThe force (in local-space of the body) to apply on the body (in Newtons)
pointThe point where the force is applied (in world-space)

◆ applyLocalTorque()

void RigidBody::applyLocalTorque ( const Vector3 torque)

Manually apply an external torque to the body (in local-space).

If the body is sleeping, calling this method will wake it up.

Note that the force will we added to the sum of the applied torques and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
torqueThe external torque to apply on the body (in local-space)

◆ applyWorldForceAtCenterOfMass()

void RigidBody::applyWorldForceAtCenterOfMass ( const Vector3 force)

Manually apply an external force (in world-space) to the body at its center of mass.

If the body is sleeping, calling this method will wake it up.

Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
forceThe external force (in world-space) to apply on the center of mass of the body (in Newtons)

◆ applyWorldForceAtLocalPosition()

void RigidBody::applyWorldForceAtLocalPosition ( const Vector3 force,
const Vector3 point 
)

Manually apply an external force (in world-space) to the body at a given point (in local-space).

If the point is not at the center of mass of the body, it will also generate some torque and therefore, change the angular velocity of the body.

If the body is sleeping, calling this method will wake it up. Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
forceThe force (in world-space) to apply on the body (in Newtons)
pointThe point where the force is applied (in local-space)

◆ applyWorldForceAtWorldPosition()

void RigidBody::applyWorldForceAtWorldPosition ( const Vector3 force,
const Vector3 point 
)

Manually apply an external force (in world-space) to the body at a given point (in world-space).

If the point is not at the center of mass of the body, it will also generate some torque and therefore, change the angular velocity of the body.

If the body is sleeping, calling this method will wake it up. Note that the force will we added to the sum of the applied forces and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
forceThe force (in world-space) to apply on the body (in Newtons)
pointThe point where the force is applied (in world-space)

◆ applyWorldTorque()

void RigidBody::applyWorldTorque ( const Vector3 torque)

Manually apply an external torque to the body (in world-space).

If the body is sleeping, calling this method will wake it up.

Note that the force will we added to the sum of the applied torques and that this sum will be reset to zero at the end of each call of the PhyscisWorld::update() method. You can only apply a force to a dynamic body otherwise, this method will do nothing.

Parameters
torqueThe external torque to apply on the body (in world-space)

◆ enableGravity()

void RigidBody::enableGravity ( bool  isEnabled)

Set the variable to know if the gravity is applied to this rigid body.

Parameters
isEnabledTrue if you want the gravity to be applied to this body

◆ getAngularDamping()

decimal RigidBody::getAngularDamping ( ) const

Return the angular velocity damping factor.

Returns
The angular damping factor of this body (in range [0; +inf]). Zero means no damping.

◆ getAngularLockAxisFactor()

const Vector3 & RigidBody::getAngularLockAxisFactor ( ) const

Return the lock rotation factor.

The angular lock axis factor specify whether angular motion around world-space axes X,Y,Z is restricted or not.

Returns
A Vector3 with the angular lock axis factor for each X,Y,Z world-space axis

◆ getAngularVelocity()

Vector3 RigidBody::getAngularVelocity ( ) const

Return the angular velocity.

Returns
The angular velocity vector of the body

◆ getForce()

const Vector3 & RigidBody::getForce ( ) const

Return the total manually applied force on the body (in world-space)

Returns
The total manually applied force on the body (in world-space)

◆ getLinearDamping()

decimal RigidBody::getLinearDamping ( ) const

Return the linear velocity damping factor.

Returns
The linear damping factor of this body (in range [0; +inf]). Zero means no damping.

◆ getLinearLockAxisFactor()

const Vector3 & RigidBody::getLinearLockAxisFactor ( ) const

Return the lock translation factor.

The linear lock axis factor specify whether linear motion along world-space axes X,Y,Z is restricted or not.

Returns
A Vector3 with the linear lock axis factor for each X,Y,Z world-space axis

◆ getLinearVelocity()

Vector3 RigidBody::getLinearVelocity ( ) const

Return the linear velocity.

Returns
The linear velocity vector of the body

◆ getLocalCenterOfMass()

const Vector3 & RigidBody::getLocalCenterOfMass ( ) const

Return the center of mass of the body (in local-space coordinates)

Returns
The local-space position of the center of mass of the body

◆ getLocalInertiaTensor()

const Vector3 & RigidBody::getLocalInertiaTensor ( ) const

Return the local inertia tensor of the body (in body coordinates)

Returns
A vector with the three values of the diagonal 3x3 matrix of the local-space inertia tensor

◆ getMass()

decimal RigidBody::getMass ( ) const

Return the mass of the body.

Returns
The mass (in kilograms) of the body

◆ getTorque()

const Vector3 & RigidBody::getTorque ( ) const

Return the total manually applied torque on the body (in world-space)

Returns
The total manually applied torque on the body (in world-space)

◆ getType()

BodyType RigidBody::getType ( ) const

Return the type of the body.

Returns
The type of rigid body (static, kinematic or dynamic)

◆ isAllowedToSleep()

bool RigidBody::isAllowedToSleep ( ) const

Return whether or not the body is allowed to sleep.

Returns
True if the body is allowed to sleep and false otherwise

◆ isGravityEnabled()

bool RigidBody::isGravityEnabled ( ) const

Return true if the gravity needs to be applied to this rigid body.

Returns
True if the gravity is applied to the body

◆ isSleeping()

bool RigidBody::isSleeping ( ) const

Return whether or not the body is sleeping.

Returns
True if the body is currently sleeping and false otherwise

◆ removeCollider()

void RigidBody::removeCollider ( Collider collider)
overridevirtual

Remove a collider from the body.

To remove a collider, you need to specify its pointer.

Parameters
colliderThe pointer of the collider you want to remove

Reimplemented from reactphysics3d::Body.

◆ setAngularDamping()

void RigidBody::setAngularDamping ( decimal  angularDamping)

Set the angular damping factor.

Parameters
angularDampingThe angular damping factor of this body (in range [0; +inf]). Zero means no damping.

◆ setAngularLockAxisFactor()

void RigidBody::setAngularLockAxisFactor ( const Vector3 angularLockAxisFactor) const

Set the lock rotation factor.

This method allows to restrict the angular motion of a rigid body around the world-space axes X,Y and Z.

For instance, it's possible to disable the angular motion of a body around a given axis by setting a lock axis factor of zero.

Parameters
angularLockAxisFactorA Vector3 with the lock factor for each world-space axis X,Y,Z

◆ setAngularVelocity()

void RigidBody::setAngularVelocity ( const Vector3 angularVelocity)

Set the angular velocity.

Parameters
angularVelocityThe angular velocity vector of the body

◆ setIsActive()

void RigidBody::setIsActive ( bool  isActive)
overridevirtual

Set whether or not the body is active.

Parameters
isActiveTrue if you want to activate the body

Reimplemented from reactphysics3d::Body.

◆ setIsAllowedToSleep()

void RigidBody::setIsAllowedToSleep ( bool  isAllowedToSleep)

Set whether or not the body is allowed to go to sleep.

Parameters
isAllowedToSleepTrue if the body is allowed to sleep

◆ setLinearDamping()

void RigidBody::setLinearDamping ( decimal  linearDamping)

Set the linear damping factor.

Parameters
linearDampingThe linear damping factor of this body (in range [0; +inf]). Zero means no damping.

◆ setLinearLockAxisFactor()

void RigidBody::setLinearLockAxisFactor ( const Vector3 linearLockAxisFactor) const

Set the linear lock factor.

This method allows to restrict the linear motion of a rigid body along the world-space axes X,Y and Z.

For instance, it's possible to disable the linear motion of a body along a given axis by setting a lock axis factor of zero.

Parameters
linearLockAxisFactorA Vector3 with the lock factor for each world-space axis X,Y,Z

◆ setLinearVelocity()

void RigidBody::setLinearVelocity ( const Vector3 linearVelocity)

Set the linear velocity of the body.

Parameters
linearVelocityLinear velocity vector of the body

◆ setLocalCenterOfMass()

void RigidBody::setLocalCenterOfMass ( const Vector3 centerOfMass)

Set the center of mass of the body (in local-space coordinates)

This method does not move the rigid body in the world.

Parameters
centerOfMassThe center of mass of the body in local-space coordinates

◆ setLocalInertiaTensor()

void RigidBody::setLocalInertiaTensor ( const Vector3 inertiaTensorLocal)

Set the local inertia tensor of the body (in body coordinates)

Note that an inertia tensor with a zero value on its diagonal is interpreted as infinite inertia.

Parameters
inertiaTensorLocalA vector with the three values of the diagonal 3x3 matrix of the local-space inertia tensor

◆ setMass()

void RigidBody::setMass ( decimal  mass)

Set the mass of the rigid body.

Note that a mass of zero is interpreted as infinite mass.

Parameters
massThe mass (in kilograms) of the body

◆ setTransform()

void RigidBody::setTransform ( const Transform transform)
overridevirtual

Set the current position and orientation.

Parameters
transformThe transformation of the body that transforms the local-space of the body into world-space

Reimplemented from reactphysics3d::Body.

◆ setType()

void RigidBody::setType ( BodyType  type)

Set the type of the body.

The type of the body can either STATIC, KINEMATIC or DYNAMIC as described bellow: STATIC : A static body is simulated as if it has infinite mass, zero velocity but its position can be changed manually.

A static body does not collide with other static or kinematic bodies. KINEMATIC : A kinematic body is simulated as if it has infinite mass, its velocity can be changed manually and its position is computed by the physics engine. A kinematic body does not collide with other static or kinematic bodies. DYNAMIC : A dynamic body has non-zero mass, its velocity is determined by forces and its position is determined by the physics engine. A dynamic body can collide with other dynamic, static or kinematic bodies.

Parameters
typeThe type of the body (STATIC, KINEMATIC, DYNAMIC)

◆ updateLocalCenterOfMassFromColliders()

void RigidBody::updateLocalCenterOfMassFromColliders ( )

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.

◆ updateLocalInertiaTensorFromColliders()

void RigidBody::updateLocalInertiaTensorFromColliders ( )

Compute and set the local-space inertia tensor of the body using its colliders.

This method uses the shape, mass density and transforms of the colliders to set the local-space inertia tensor of the body.

Note that calling this method will overwrite the mass that has been set with the RigidBody::setInertiaTensorLocal() method.

◆ updateMassFromColliders()

void RigidBody::updateMassFromColliders ( )

Compute and set the mass of the body using its colliders.

This method uses the shape, mass density and transforms of the colliders to set the total mass of the body.

Note that calling this method will overwrite the mass that has been set with the RigidBody::setMass() method

◆ updateMassPropertiesFromColliders()

void RigidBody::updateMassPropertiesFromColliders ( )

Compute and set the center of mass, the mass and the local-space inertia tensor of the body using its colliders.

This method uses the shape, mass density and transform of the colliders of the body to set the total mass, the center of mass and the local inertia tensor of the body.

Note that calling this method will overwrite the mass that has been set with the RigidBody::setMass(), the center of mass that has been set with RigidBody::setCenterOfMass() and the local inertia tensor that has been set with RigidBody::setInertiaTensorLocal().


The documentation for this class was generated from the following files: