ReactPhysics3D: reactphysics3d::PhysicsWorld Class Reference

| ReactPhysics3D v0.10.2 C++ Physics engine library

Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
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
CollisionDispatch & | getCollisionDispatch ()
| Get the collision dispatch configuration.
void | raycast (const Ray &ray, RaycastCallback *raycastCallback, unsigned short raycastWithCategoryMaskBits=0xFFFF) const
| Ray cast method.
bool | testOverlap (Body *body1, Body *body2)
| Return true if two bodies overlap (collide)
void | testOverlap (Body *body, OverlapCallback &overlapCallback)
| Report all the bodies that overlap (collide) with the body in parameter.
void | testOverlap (OverlapCallback &overlapCallback)
| Report all the bodies that overlap (collide) in the world.
void | testCollision (Body *body1, Body *body2, CollisionCallback &callback)
| Test collision and report contacts between two bodies.
void | testCollision (Body *body, CollisionCallback &callback)
| Test collision and report all the contacts involving the body in parameter.
void | testCollision (CollisionCallback &callback)
| Test collision and report contacts between each colliding bodies in the world.
MemoryManager & | getMemoryManager ()
| 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.
const std::string & | getName () const
| Return the name of the world.
| PhysicsWorld (const PhysicsWorld &world)=delete
| Deleted copy-constructor.
PhysicsWorld & | operator= (const PhysicsWorld &world)=delete
| Deleted assignment operator.
void | update (decimal timeStep)
| Update the physics simulation.
uint16 | getNbIterationsVelocitySolver () const
| Get the number of iterations for the velocity constraint solver.
void | setNbIterationsVelocitySolver (uint16 nbIterations)
| Set the number of iterations for the velocity constraint solver.
uint16 | getNbIterationsPositionSolver () const
| Get the number of iterations for the position constraint solver.
void | setNbIterationsPositionSolver (uint32 nbIterations)
| Set the number of iterations for the position constraint solver.
void | setContactsPositionCorrectionTechnique (ContactsPositionCorrectionTechnique technique)
| Set the position correction technique used for contacts.
RigidBody * | createRigidBody (const Transform &transform)
| Create a rigid body into the physics world.
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.
Joint * | createJoint (const JointInfo &jointInfo)
| Create a joint between two bodies in the world and return a pointer to the new joint.
void | destroyJoint (Joint *joint)
| Destroy a joint.
Vector3 | getGravity () const
| Return the gravity vector of the world.
void | setGravity (const Vector3 &gravity)
| Set the gravity vector of the world.
bool | isGravityEnabled () const
| Return if the gravity is on.
void | setIsGravityEnabled (bool isGravityEnabled)
| Enable/Disable the gravity.
bool | isSleepingEnabled () const
| Return true if the sleeping technique is enabled.
void | enableSleeping (bool isSleepingEnabled)
| Enable/Disable the sleeping technique.
decimal | getSleepLinearVelocity () const
| Return the current sleep linear velocity.
void | setSleepLinearVelocity (decimal sleepLinearVelocity)
| Set the sleep linear velocity.
decimal | getSleepAngularVelocity () const
| Return the current sleep angular velocity.
void | setSleepAngularVelocity (decimal sleepAngularVelocity)
| Set the sleep angular velocity.
decimal | getTimeBeforeSleep () const
| Return the time a body is required to stay still before sleeping.
void | setTimeBeforeSleep (decimal timeBeforeSleep)
| Set the time a body is required to stay still before sleeping.
void | setEventListener (EventListener *eventListener)
| Set an event listener object to receive events callbacks.
uint32 | getNbRigidBodies () const
| Return the number of RigidBody in the physics world.
const RigidBody * | getRigidBody (uint32 index) const
| Return a constant pointer to a given RigidBody of the world.
RigidBody * | getRigidBody (uint32 index)
| Return a pointer to a given RigidBody of the world.
bool | getIsDebugRenderingEnabled () const
| Return true if the debug rendering is enabled.
void | setIsDebugRenderingEnabled (bool isEnabled)
| Set to true if debug rendering is enabled.
DebugRenderer & | getDebugRenderer ()
| Return a reference to the Debug Renderer of the world.

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

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

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

  joint | Pointer 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

  rigidBody | Pointer 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

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

  CollisionDispatch | Pointer 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

  index | Index 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

  index | Index 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

  collider | Pointer 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

  ray | Ray to use for raycasting
  raycastCallback | Pointer to the class with the callback method
  raycastWithCategoryMaskBits | Bits 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

  technique | Technique 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

  eventListener | Pointer 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

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

  isEnabled | True if you want to enable the debug rendering and false otherwise

## ◆ setIsGravityEnabled()

void PhysicsWorld::setIsGravityEnabled | ( | bool | isGravityEnabled | ) |

Enable/Disable the gravity.

Parameters

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

  nbIterations | Number of iterations for the position solver

## ◆ setNbIterationsVelocitySolver()

void PhysicsWorld::setNbIterationsVelocitySolver | ( | uint16 | nbIterations | ) |

Set the number of iterations for the velocity constraint solver.

Parameters

  nbIterations | Number 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

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

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

  timeBeforeSleep | Time 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

  body | Pointer to the body against which we need to test collision
  callback | Pointer 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

  body1 | Pointer to the first body to test
  body2 | Pointer to the second body to test
  callback | Pointer 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

  callback | Pointer 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

  body | Pointer to the collision body to test overlap with
  overlapCallback | Pointer 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

  body1 | Pointer to the first body
  body2 | Pointer 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

  overlapCallback | Pointer to the callback class to report overlap

## ◆ update()

void PhysicsWorld::update | ( | decimal | timeStep | ) |

Update the physics simulation.

Parameters

  timeStep | The amount of time to step the simulation by (in seconds)

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

- include/reactphysics3d/engine/PhysicsWorld.h
- src/engine/PhysicsWorld.cpp