ReactPhysics3D: reactphysics3d::RigidBody Class Reference

| ReactPhysics3D v0.10.2 C++ Physics engine library

Loading...
Searching...
No Matches
Public Member Functions | List of all members
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:

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

## 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

  world | The world where the body has been added
  entity | The 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

  collisionShape | A pointer to the collision shape of the new collider
  transform | The 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

  force | The 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

  force | The force (in local-space of the body) to apply on the body (in Newtons)
  point | The 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

  force | The force (in local-space of the body) to apply on the body (in Newtons)
  point | The 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

  torque | The 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

  force | The 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

  force | The force (in world-space) to apply on the body (in Newtons)
  point | The 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

  force | The force (in world-space) to apply on the body (in Newtons)
  point | The 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

  torque | The 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

  isEnabled | True 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

  collider | The pointer of the collider you want to remove

Reimplemented from reactphysics3d::Body.

## ◆ setAngularDamping()

void RigidBody::setAngularDamping | ( | decimal | angularDamping | ) |

Set the angular damping factor.

Parameters

  angularDamping | The 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

  angularLockAxisFactor | A 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

  angularVelocity | The angular velocity vector of the body

## ◆ setIsActive()

void RigidBody::setIsActive | ( | bool | isActive | ) |
| overridevirtual

Set whether or not the body is active.

Parameters

  isActive | True 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

  isAllowedToSleep | True if the body is allowed to sleep

## ◆ setLinearDamping()

void RigidBody::setLinearDamping | ( | decimal | linearDamping | ) |

Set the linear damping factor.

Parameters

  linearDamping | The 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

  linearLockAxisFactor | A 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

  linearVelocity | Linear 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

  centerOfMass | The 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

  inertiaTensorLocal | A 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

  mass | The mass (in kilograms) of the body

## ◆ setTransform()

void RigidBody::setTransform | ( | const Transform & | transform | ) |
| overridevirtual

Set the current position and orientation.

Parameters

  transform | The 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

  type | The 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:

- include/reactphysics3d/body/RigidBody.h
- src/body/RigidBody.cpp