ReactPhysics3D
v0.10.2
C++ Physics engine library
|
This class represents a rigid body of the physics engine. More...
#include <include/reactphysics3d/body/RigidBody.h>
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 ¢erOfMass) |
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. | |
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.
RigidBody::RigidBody | ( | PhysicsWorld & | world, |
Entity | entity | ||
) |
Constructor.
world | The world where the body has been added |
entity | The entity of the rigidbody |
|
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.
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 |
Reimplemented from reactphysics3d::Body.
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.
force | The external force (in local-space of the body) to apply on the center of mass of the body (in Newtons) |
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.
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) |
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.
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) |
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.
torque | The external torque to apply on the body (in local-space) |
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.
force | The external force (in world-space) to apply on the center of mass of the body (in Newtons) |
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.
force | The force (in world-space) to apply on the body (in Newtons) |
point | The point where the force is applied (in local-space) |
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.
force | The force (in world-space) to apply on the body (in Newtons) |
point | The point where the force is applied (in world-space) |
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.
torque | The external torque to apply on the body (in world-space) |
void RigidBody::enableGravity | ( | bool | isEnabled | ) |
Set the variable to know if the gravity is applied to this rigid body.
isEnabled | True if you want the gravity to be applied to this body |
decimal RigidBody::getAngularDamping | ( | ) | const |
Return the angular velocity damping factor.
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.
Vector3 RigidBody::getAngularVelocity | ( | ) | const |
Return the angular velocity.
const Vector3 & RigidBody::getForce | ( | ) | const |
Return the total manually applied force on the body (in world-space)
decimal RigidBody::getLinearDamping | ( | ) | const |
Return the linear velocity damping factor.
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.
Vector3 RigidBody::getLinearVelocity | ( | ) | const |
Return the linear velocity.
const Vector3 & RigidBody::getLocalCenterOfMass | ( | ) | const |
Return the center of mass of the body (in local-space coordinates)
const Vector3 & RigidBody::getLocalInertiaTensor | ( | ) | const |
Return the local inertia tensor of the body (in body coordinates)
decimal RigidBody::getMass | ( | ) | const |
Return the mass of the body.
const Vector3 & RigidBody::getTorque | ( | ) | const |
Return the total manually applied torque on the body (in world-space)
BodyType RigidBody::getType | ( | ) | const |
Return the type of the body.
bool RigidBody::isAllowedToSleep | ( | ) | const |
Return whether or not the body is allowed to sleep.
bool RigidBody::isGravityEnabled | ( | ) | const |
Return true if the gravity needs to be applied to this rigid body.
bool RigidBody::isSleeping | ( | ) | const |
Return whether or not the body is sleeping.
|
overridevirtual |
Remove a collider from the body.
To remove a collider, you need to specify its pointer.
collider | The pointer of the collider you want to remove |
Reimplemented from reactphysics3d::Body.
void RigidBody::setAngularDamping | ( | decimal | angularDamping | ) |
Set the angular damping factor.
angularDamping | The angular damping factor of this body (in range [0; +inf]). Zero means no damping. |
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.
angularLockAxisFactor | A Vector3 with the lock factor for each world-space axis X,Y,Z |
void RigidBody::setAngularVelocity | ( | const Vector3 & | angularVelocity | ) |
Set the angular velocity.
angularVelocity | The angular velocity vector of the body |
|
overridevirtual |
Set whether or not the body is active.
isActive | True if you want to activate the body |
Reimplemented from reactphysics3d::Body.
void RigidBody::setIsAllowedToSleep | ( | bool | isAllowedToSleep | ) |
Set whether or not the body is allowed to go to sleep.
isAllowedToSleep | True if the body is allowed to sleep |
void RigidBody::setLinearDamping | ( | decimal | linearDamping | ) |
Set the linear damping factor.
linearDamping | The linear damping factor of this body (in range [0; +inf]). Zero means no damping. |
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.
linearLockAxisFactor | A Vector3 with the lock factor for each world-space axis X,Y,Z |
void RigidBody::setLinearVelocity | ( | const Vector3 & | linearVelocity | ) |
Set the linear velocity of the body.
linearVelocity | Linear velocity vector of the body |
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.
centerOfMass | The center of mass of the body in local-space coordinates |
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.
inertiaTensorLocal | A vector with the three values of the diagonal 3x3 matrix of the local-space inertia tensor |
void RigidBody::setMass | ( | decimal | mass | ) |
Set the mass of the rigid body.
Note that a mass of zero is interpreted as infinite mass.
mass | The mass (in kilograms) of the body |
|
overridevirtual |
Set the current position and orientation.
transform | The transformation of the body that transforms the local-space of the body into world-space |
Reimplemented from reactphysics3d::Body.
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.
type | The type of the body (STATIC, KINEMATIC, DYNAMIC) |
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.
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.
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
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().