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

This class represents a physics world. More...

#include <include/reactphysics3d/engine/PhysicsWorld.h>

Classes

struct  WorldSettings
 Structure WorldSettings. More...
 

Public Member Functions

CollisionDispatchgetCollisionDispatch ()
 Get the collision dispatch configuration. More...
 
void raycast (const Ray &ray, RaycastCallback *raycastCallback, unsigned short raycastWithCategoryMaskBits=0xFFFF) const
 Ray cast method. More...
 
bool testOverlap (Body *body1, Body *body2)
 Return true if two bodies overlap (collide) More...
 
void testOverlap (Body *body, OverlapCallback &overlapCallback)
 Report all the bodies that overlap (collide) with the body in parameter. More...
 
void testOverlap (OverlapCallback &overlapCallback)
 Report all the bodies that overlap (collide) in the world. More...
 
void testCollision (Body *body1, Body *body2, CollisionCallback &callback)
 Test collision and report contacts between two bodies. More...
 
void testCollision (Body *body, CollisionCallback &callback)
 Test collision and report all the contacts involving the body in parameter. More...
 
void testCollision (CollisionCallback &callback)
 Test collision and report contacts between each colliding bodies in the world. More...
 
MemoryManagergetMemoryManager ()
 Return a reference to the memory manager of the world.
 
AABB getWorldAABB (const Collider *collider) const
 Return the current world-space AABB of given collider. More...
 
const std::string & getName () const
 Return the name of the world. More...
 
 PhysicsWorld (const PhysicsWorld &world)=delete
 Deleted copy-constructor.
 
PhysicsWorldoperator= (const PhysicsWorld &world)=delete
 Deleted assignment operator.
 
void update (decimal timeStep)
 Update the physics simulation. More...
 
uint16 getNbIterationsVelocitySolver () const
 Get the number of iterations for the velocity constraint solver. More...
 
void setNbIterationsVelocitySolver (uint16 nbIterations)
 Set the number of iterations for the velocity constraint solver. More...
 
uint16 getNbIterationsPositionSolver () const
 Get the number of iterations for the position constraint solver. More...
 
void setNbIterationsPositionSolver (uint32 nbIterations)
 Set the number of iterations for the position constraint solver. More...
 
void setContactsPositionCorrectionTechnique (ContactsPositionCorrectionTechnique technique)
 Set the position correction technique used for contacts. More...
 
RigidBodycreateRigidBody (const Transform &transform)
 Create a rigid body into the physics world. More...
 
void enableDisableJoints ()
 Disable the joints for pair of sleeping bodies.
 
void destroyRigidBody (RigidBody *rigidBody)
 Destroy a rigid body and all the joints which it belongs. More...
 
JointcreateJoint (const JointInfo &jointInfo)
 Create a joint between two bodies in the world and return a pointer to the new joint. More...
 
void destroyJoint (Joint *joint)
 Destroy a joint. More...
 
Vector3 getGravity () const
 Return the gravity vector of the world. More...
 
void setGravity (const Vector3 &gravity)
 Set the gravity vector of the world. More...
 
bool isGravityEnabled () const
 Return if the gravity is on. More...
 
void setIsGravityEnabled (bool isGravityEnabled)
 Enable/Disable the gravity. More...
 
bool isSleepingEnabled () const
 Return true if the sleeping technique is enabled. More...
 
void enableSleeping (bool isSleepingEnabled)
 Enable/Disable the sleeping technique. More...
 
decimal getSleepLinearVelocity () const
 Return the current sleep linear velocity. More...
 
void setSleepLinearVelocity (decimal sleepLinearVelocity)
 Set the sleep linear velocity. More...
 
decimal getSleepAngularVelocity () const
 Return the current sleep angular velocity. More...
 
void setSleepAngularVelocity (decimal sleepAngularVelocity)
 Set the sleep angular velocity. More...
 
decimal getTimeBeforeSleep () const
 Return the time a body is required to stay still before sleeping. More...
 
void setTimeBeforeSleep (decimal timeBeforeSleep)
 Set the time a body is required to stay still before sleeping. More...
 
void setEventListener (EventListener *eventListener)
 Set an event listener object to receive events callbacks. More...
 
uint32 getNbRigidBodies () const
 Return the number of RigidBody in the physics world. More...
 
const RigidBodygetRigidBody (uint32 index) const
 Return a constant pointer to a given RigidBody of the world. More...
 
RigidBodygetRigidBody (uint32 index)
 Return a pointer to a given RigidBody of the world. More...
 
bool getIsDebugRenderingEnabled () const
 Return true if the debug rendering is enabled. More...
 
void setIsDebugRenderingEnabled (bool isEnabled)
 Set to true if debug rendering is enabled. More...
 
DebugRenderergetDebugRenderer ()
 Return a reference to the Debug Renderer of the world. More...
 

Detailed Description

This class represents a physics world.

Member Function Documentation

◆ createJoint()

Joint * PhysicsWorld::createJoint ( const JointInfo jointInfo)

Create a joint between two bodies in the world and return a pointer to the new joint.

Parameters
jointInfoThe information that is necessary to create the joint
Returns
A pointer to the joint that has been created in the world

◆ createRigidBody()

RigidBody * PhysicsWorld::createRigidBody ( const Transform transform)

Create a rigid body into the physics world.

Parameters
transformTransformation from body local-space to world-space
Returns
A pointer to the body that has been created in the world

◆ destroyJoint()

void PhysicsWorld::destroyJoint ( Joint joint)

Destroy a joint.

Parameters
jointPointer to the joint you want to destroy

◆ destroyRigidBody()

void PhysicsWorld::destroyRigidBody ( RigidBody rigidBody)

Destroy a rigid body and all the joints which it belongs.

Parameters
rigidBodyPointer to the body you want to destroy

◆ enableSleeping()

void PhysicsWorld::enableSleeping ( bool  isSleepingEnabled)

Enable/Disable the sleeping technique.

The sleeping technique is used to put bodies that are not moving into sleep to speed up the simulation.

Parameters
isSleepingEnabledTrue if you want to enable the sleeping technique and false otherwise

◆ getCollisionDispatch()

RP3D_FORCE_INLINE CollisionDispatch & reactphysics3d::PhysicsWorld::getCollisionDispatch ( )

Get the collision dispatch configuration.

This can be used to replace default collision detection algorithms by your custom algorithm for instance.

Parameters
CollisionDispatchPointer to a collision dispatch object describing which collision detection algorithm to use for two given collision shapes

◆ getDebugRenderer()

RP3D_FORCE_INLINE DebugRenderer & reactphysics3d::PhysicsWorld::getDebugRenderer ( )

Return a reference to the Debug Renderer of the world.

Returns
A reference to the DebugRenderer object of the world

◆ getGravity()

RP3D_FORCE_INLINE Vector3 reactphysics3d::PhysicsWorld::getGravity ( ) const

Return the gravity vector of the world.

Returns
The current gravity vector (in meter per seconds squared)

◆ getIsDebugRenderingEnabled()

RP3D_FORCE_INLINE bool reactphysics3d::PhysicsWorld::getIsDebugRenderingEnabled ( ) const

Return true if the debug rendering is enabled.

Returns
True if the debug rendering is enabled and false otherwise

◆ getName()

RP3D_FORCE_INLINE const std::string & reactphysics3d::PhysicsWorld::getName ( ) const

Return the name of the world.

Returns
Name of the world

◆ getNbIterationsPositionSolver()

RP3D_FORCE_INLINE uint16 reactphysics3d::PhysicsWorld::getNbIterationsPositionSolver ( ) const

Get the number of iterations for the position constraint solver.

Returns
The number of iterations of the position constraint solver

◆ getNbIterationsVelocitySolver()

RP3D_FORCE_INLINE uint16 reactphysics3d::PhysicsWorld::getNbIterationsVelocitySolver ( ) const

Get the number of iterations for the velocity constraint solver.

Returns
The number of iterations of the velocity constraint solver

◆ getNbRigidBodies()

RP3D_FORCE_INLINE uint32 reactphysics3d::PhysicsWorld::getNbRigidBodies ( ) const

Return the number of RigidBody in the physics world.

Returns
The number of rigid bodies in the physics world

◆ getRigidBody() [1/2]

RigidBody * PhysicsWorld::getRigidBody ( uint32  index)

Return a pointer to a given RigidBody of the world.

Parameters
indexIndex of a RigidBody in the world
Returns
Pointer to a given RigidBody

◆ getRigidBody() [2/2]

const RigidBody * PhysicsWorld::getRigidBody ( uint32  index) const

Return a constant pointer to a given RigidBody of the world.

Parameters
indexIndex of a RigidBody in the world
Returns
Constant pointer to a given RigidBody

◆ getSleepAngularVelocity()

RP3D_FORCE_INLINE decimal reactphysics3d::PhysicsWorld::getSleepAngularVelocity ( ) const

Return the current sleep angular velocity.

Returns
The sleep angular velocity (in radian per second)

◆ getSleepLinearVelocity()

RP3D_FORCE_INLINE decimal reactphysics3d::PhysicsWorld::getSleepLinearVelocity ( ) const

Return the current sleep linear velocity.

Returns
The sleep linear velocity (in meters per second)

◆ getTimeBeforeSleep()

RP3D_FORCE_INLINE decimal reactphysics3d::PhysicsWorld::getTimeBeforeSleep ( ) const

Return the time a body is required to stay still before sleeping.

Returns
Time a body is required to stay still before sleeping (in seconds)

◆ getWorldAABB()

AABB PhysicsWorld::getWorldAABB ( const Collider collider) const

Return the current world-space AABB of given collider.

Parameters
colliderPointer to a collider
Returns
The AAABB of the collider in world-space

◆ isGravityEnabled()

RP3D_FORCE_INLINE bool reactphysics3d::PhysicsWorld::isGravityEnabled ( ) const

Return if the gravity is on.

Returns
True if the gravity is enabled in the world

◆ isSleepingEnabled()

RP3D_FORCE_INLINE bool reactphysics3d::PhysicsWorld::isSleepingEnabled ( ) const

Return true if the sleeping technique is enabled.

Returns
True if the sleeping technique is enabled and false otherwise

◆ raycast()

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::raycast ( const Ray ray,
RaycastCallback raycastCallback,
unsigned short  raycastWithCategoryMaskBits = 0xFFFF 
) const

Ray cast method.

Parameters
rayRay to use for raycasting
raycastCallbackPointer to the class with the callback method
raycastWithCategoryMaskBitsBits mask corresponding to the category of bodies to be raycasted

◆ setContactsPositionCorrectionTechnique()

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::setContactsPositionCorrectionTechnique ( ContactsPositionCorrectionTechnique  technique)

Set the position correction technique used for contacts.

Parameters
techniqueTechnique used for the position correction (Baumgarte or Split Impulses)

◆ setEventListener()

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::setEventListener ( EventListener eventListener)

Set an event listener object to receive events callbacks.

If you use "nullptr" as an argument, the events callbacks will be disabled.

Parameters
eventListenerPointer to the event listener object that will receive event callbacks during the simulation

◆ setGravity()

void PhysicsWorld::setGravity ( const Vector3 gravity)

Set the gravity vector of the world.

Parameters
gravityThe gravity vector (in meter per seconds squared)

◆ setIsDebugRenderingEnabled()

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::setIsDebugRenderingEnabled ( bool  isEnabled)

Set to true if debug rendering is enabled.

Parameters
isEnabledTrue if you want to enable the debug rendering and false otherwise

◆ setIsGravityEnabled()

void PhysicsWorld::setIsGravityEnabled ( bool  isGravityEnabled)

Enable/Disable the gravity.

Parameters
isGravityEnabledTrue if you want to enable the gravity in the world and false otherwise

◆ setNbIterationsPositionSolver()

void PhysicsWorld::setNbIterationsPositionSolver ( uint32  nbIterations)

Set the number of iterations for the position constraint solver.

Parameters
nbIterationsNumber of iterations for the position solver

◆ setNbIterationsVelocitySolver()

void PhysicsWorld::setNbIterationsVelocitySolver ( uint16  nbIterations)

Set the number of iterations for the velocity constraint solver.

Parameters
nbIterationsNumber of iterations for the velocity solver

◆ setSleepAngularVelocity()

void PhysicsWorld::setSleepAngularVelocity ( decimal  sleepAngularVelocity)

Set the sleep angular velocity.

When the velocity of a body becomes smaller than the sleep linear/angular velocity for a given amount of time, the body starts sleeping and does not need to be simulated anymore.

Parameters
sleepAngularVelocityThe sleep angular velocity (in radian per second)

◆ setSleepLinearVelocity()

void PhysicsWorld::setSleepLinearVelocity ( decimal  sleepLinearVelocity)

Set the sleep linear velocity.

When the velocity of a body becomes smaller than the sleep linear/angular velocity for a given amount of time, the body starts sleeping and does not need to be simulated anymore.

Parameters
sleepLinearVelocityThe sleep linear velocity (in meters per second)

◆ setTimeBeforeSleep()

void PhysicsWorld::setTimeBeforeSleep ( decimal  timeBeforeSleep)

Set the time a body is required to stay still before sleeping.

Parameters
timeBeforeSleepTime a body is required to stay still before sleeping (in seconds)

◆ testCollision() [1/3]

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::testCollision ( Body body,
CollisionCallback callback 
)

Test collision and report all the contacts involving the body in parameter.

Use this method if you only want to get all the contacts involving a given body.

All the contacts will be reported using the callback object in paramater. If you are not interested in the contacts but you only want to know if the bodies collide, you can use the testOverlap() method instead.

Parameters
bodyPointer to the body against which we need to test collision
callbackPointer to the object with the callback method to report contacts

◆ testCollision() [2/3]

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::testCollision ( Body body1,
Body body2,
CollisionCallback callback 
)

Test collision and report contacts between two bodies.

Use this method if you only want to get all the contacts between two bodies.

All the contacts will be reported using the callback object in paramater. If you are not interested in the contacts but you only want to know if the bodies collide, you can use the testOverlap() method instead.

Parameters
body1Pointer to the first body to test
body2Pointer to the second body to test
callbackPointer to the object with the callback method

◆ testCollision() [3/3]

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::testCollision ( CollisionCallback callback)

Test collision and report contacts between each colliding bodies in the world.

Use this method if you want to get all the contacts between colliding bodies in the world.

All the contacts will be reported using the callback object in paramater. If you are not interested in the contacts but you only want to know if the bodies collide, you can use the testOverlap() method instead.

Parameters
callbackPointer to the object with the callback method to report contacts

◆ testOverlap() [1/3]

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::testOverlap ( Body body,
OverlapCallback overlapCallback 
)

Report all the bodies that overlap (collide) with the body in parameter.

Use this method if you are not interested in contacts but if you simply want to know which bodies overlap with the body in parameter.

If you want to get the contacts, you need to use the testCollision() method instead.

Parameters
bodyPointer to the collision body to test overlap with
overlapCallbackPointer to the callback class to report overlap

◆ testOverlap() [2/3]

bool PhysicsWorld::testOverlap ( Body body1,
Body body2 
)

Return true if two bodies overlap (collide)

Use this method if you are not interested in contacts but if you simply want to know if the two bodies overlap.

If you want to get the contacts, you need to use the testCollision() method instead.

Parameters
body1Pointer to the first body
body2Pointer to a second body
Returns
True if the two bodies overlap

◆ testOverlap() [3/3]

RP3D_FORCE_INLINE void reactphysics3d::PhysicsWorld::testOverlap ( OverlapCallback overlapCallback)

Report all the bodies that overlap (collide) in the world.

Use this method if you are not interested in contacts but if you simply want to know which bodies overlap.

If you want to get the contacts, you need to use the testCollision() method instead.

Parameters
overlapCallbackPointer to the callback class to report overlap

◆ update()

void PhysicsWorld::update ( decimal  timeStep)

Update the physics simulation.

Parameters
timeStepThe amount of time to step the simulation by (in seconds)

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