ReactPhysics3D  v0.10.2
C++ Physics engine library
Loading...
Searching...
No Matches
reactphysics3d::Body Class Reference

This class represents a body. More...

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

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

Public Member Functions

 Body (PhysicsWorld &world, Entity entity)
 Constructor.
 
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.
 
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.
 
virtual void setIsActive (bool isActive)
 Set whether or not the body is active.
 
const TransformgetTransform () const
 Return the current position and orientation.
 
virtual void setTransform (const Transform &transform)
 Set the current position and orientation.
 
virtual CollideraddCollider (CollisionShape *collisionShape, const Transform &transform)
 Create a new collider and add it to the body.
 
virtual void removeCollider (Collider *collider)
 Remove a collider from the body.
 
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 CollidergetCollider (uint32 colliderIndex) const
 Return a const pointer to a given collider of the body.
 
CollidergetCollider (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 body.

Constructor & Destructor Documentation

◆ Body()

Body::Body ( PhysicsWorld world,
Entity  entity 
)

Constructor.

Parameters
worldThe reference to the physics world where the body is created
entityEntity of the body

Member Function Documentation

◆ addCollider()

Collider * Body::addCollider ( CollisionShape collisionShape,
const Transform transform 
)
virtual

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 in reactphysics3d::RigidBody.

◆ getAABB()

AABB Body::getAABB ( ) const

Compute and return the AABB of the body by merging all colliders AABBs.

Returns
The axis-aligned bounding box (AABB) of the body in world-space coordinates

◆ getCollider() [1/2]

Collider * Body::getCollider ( uint32  colliderIndex)

Return a pointer to a given collider of the body.

Parameters
colliderIndexIndex of a Collider of the body
Returns
The pointer to the requested collider

◆ getCollider() [2/2]

const Collider * Body::getCollider ( uint32  colliderIndex) const

Return a const pointer to a given collider of the body.

Parameters
colliderIndexIndex of a Collider of the body
Returns
The const pointer to the requested collider

◆ getEntity()

RP3D_FORCE_INLINE Entity reactphysics3d::Body::getEntity ( ) const

Return the corresponding entity of the body.

Returns
The entity of the body

◆ getLocalPoint()

Vector3 Body::getLocalPoint ( const Vector3 worldPoint) const

Return the body local-space coordinates of a point given in the world-space coordinates.

Parameters
worldPointA point in world-space coordinates
Returns
The point in the local-space coordinates of the body

◆ getLocalVector()

Vector3 Body::getLocalVector ( const Vector3 worldVector) const

Return the body local-space coordinates of a vector given in the world-space coordinates.

Parameters
worldVectorA vector in world-space coordinates
Returns
The vector in the local-space coordinates of the body

◆ getNbColliders()

uint32 Body::getNbColliders ( ) const

Return the number of colliders associated with this body.

Returns
The number of colliders associated with this body

◆ getTransform()

const Transform & Body::getTransform ( ) const

Return the current position and orientation.

Returns
The current transformation of the body that transforms the local-space of the body into world-space

◆ getUserData()

void * Body::getUserData ( ) const

Return a pointer to the user data attached to this body.

Returns
A pointer to the user data you have attached to the body

◆ getWorldPoint()

Vector3 Body::getWorldPoint ( const Vector3 localPoint) const

Return the world-space coordinates of a point given the local-space coordinates of the body.

Parameters
localPointA point in the local-space coordinates of the body
Returns
The point in world-space coordinates

◆ getWorldVector()

Vector3 Body::getWorldVector ( const Vector3 localVector) const

Return the world-space vector of a vector given in local-space coordinates of the body.

Parameters
localVectorA vector in the local-space coordinates of the body
Returns
The vector in world-space coordinates

◆ isActive()

bool Body::isActive ( ) const

Return true if the body is active.

Returns
True if the body currently active and false otherwise

◆ isDebugEnabled()

bool Body::isDebugEnabled ( ) const

Return true if debug lines should be computed for this body.

Returns
Returns true if this body is computing debug information

◆ raycast()

bool Body::raycast ( const Ray ray,
RaycastInfo raycastInfo 
)

Raycast method with feedback information.

The method returns the closest hit among all the collision shapes of the body.

Parameters
rayThe ray used to raycast agains the body
[out]raycastInfoStructure that contains the result of the raycasting (valid only if the method returned true)
Returns
True if the ray hit the body and false otherwise

◆ removeCollider()

void Body::removeCollider ( Collider collider)
virtual

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 in reactphysics3d::RigidBody.

◆ setIsActive()

void Body::setIsActive ( bool  isActive)
virtual

Set whether or not the body is active.

Parameters
isActiveTrue if you want to activate the body

Reimplemented in reactphysics3d::RigidBody.

◆ setIsDebugEnabled()

void Body::setIsDebugEnabled ( bool  enabled)

Set whether or not debug lines are computed for this body.

Parameters
enabledSet to true if this body should have it's debug information computed

◆ setTransform()

void Body::setTransform ( const Transform transform)
virtual

Set the current position and orientation.

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

Reimplemented in reactphysics3d::RigidBody.

◆ setUserData()

void Body::setUserData ( void *  userData)

Attach user data to this body.

Parameters
userDataA pointer to the user data you want to attach to the body

◆ testAABBOverlap()

RP3D_FORCE_INLINE bool reactphysics3d::Body::testAABBOverlap ( const AABB worldAABB) const

Test if the collision body overlaps with a given AABB.

Parameters
worldAABBThe AABB (in world-space coordinates) that will be used to test overlap
Returns
True if the given AABB overlaps with the AABB of the collision body

◆ testPointInside()

bool Body::testPointInside ( const Vector3 worldPoint) const

Return true if a point is inside the collision body.

This method returns true if a point is inside any collision shape of the body.

Parameters
worldPointThe point to test (in world-space coordinates)
Returns
True if the point is inside the body

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