|
Avara3D 0.2.0
C++ API reference
|
Simulates rigid bodies and performs physics collision queries for a Scene. More...
#include <a3d/physics/PhysicsWorld.h>
Classes | |
| struct | ConvexSweepTestOptions |
| Options controlling a convex sweep collision query. More... | |
| struct | RayTestOptions |
| Options controlling a ray collision query. More... | |
Public Types | |
| using | DidBeginContactCallback = std::function< void(PhysicsWorld &physicsWorld, const PhysicsContact &contact)> |
| Callback invoked when a pair of physics bodies begins a logical contact. More... | |
| using | DidContinueContactCallback = std::function< void(PhysicsWorld &physicsWorld, const PhysicsContact &contact)> |
| Callback invoked once per simulation step while a body pair remains in contact. More... | |
| using | DidEndContactCallback = std::function< void(PhysicsWorld &physicsWorld, const PhysicsContact &contact)> |
| Callback invoked when a tracked body pair ceases to be in contact. More... | |
Public Member Functions | |
| PhysicsWorld () | |
| Creates a PhysicsWorld with Earth-like gravity of (0, -9.807, 0). More... | |
| const math::vec3 & | gravity () const |
| Returns the world gravity acceleration vector. More... | |
| void | gravity (const math::vec3 &gravity) |
| Sets the world gravity and immediately applies it to affected dynamic bodies. More... | |
| std::optional< PhysicsContact > | contactTest (const PhysicsBody &bodyA, const PhysicsBody &bodyB) const |
Tests for contact between bodyA and bodyB. More... | |
| std::vector< PhysicsContact > | contactTest (const PhysicsBody &body) const |
Returns current contacts between body and other physics bodies. More... | |
| std::vector< HitTestResult > | rayTest (const math::vec3 &from, const math::vec3 &to, const RayTestOptions &options) const |
Tests the world-space segment from from to to against physics bodies. More... | |
| std::vector< HitTestResult > | rayTest (const math::vec3 &from, const math::vec3 &to) const |
Tests the world-space segment from from to to and returns the closest physics hit. More... | |
| std::vector< PhysicsContact > | convexSweepTest (const PhysicsShape &shape, const math::mat4 &fromMat, const math::mat4 &toMat, const ConvexSweepTestOptions &options) const |
Sweeps shape between two transforms. More... | |
| std::vector< PhysicsContact > | convexSweepTest (const PhysicsShape &shape, const math::mat4 &fromMat, const math::mat4 &toMat) const |
Sweeps shape between two transforms. More... | |
| Scene * | scene () const |
| Returns the Scene containing this PhysicsWorld, or nullptr when it is not installed in a Scene. More... | |
| DidBeginContactCallback | didBeginContactCallback () const |
| Returns the callback invoked when a body pair begins contact. More... | |
| void | didBeginContactCallback (DidBeginContactCallback function) |
| Replaces the begin-contact callback; an empty callback disables it. More... | |
| DidContinueContactCallback | didContinueContactCallback () const |
| Returns the callback invoked while a body pair remains in contact. More... | |
| void | didContinueContactCallback (DidContinueContactCallback function) |
| Replaces the continuing-contact callback; an empty callback disables it. More... | |
| DidEndContactCallback | didEndContactCallback () const |
| Returns the callback invoked when a tracked body pair ends contact. More... | |
| void | didEndContactCallback (DidEndContactCallback function) |
| Replaces the end-contact callback; an empty callback disables it. More... | |
Simulates rigid bodies and performs physics collision queries for a Scene.
Physics bodies attached to nodes in a Scene become members of its PhysicsWorld when they have a usable collision shape. The world applies its gravity to participating dynamic bodies and reports logical contact lifecycles through optional callbacks.
Definition at line 39 of file PhysicsWorld.h.
| using a3d::PhysicsWorld::DidBeginContactCallback = std::function<void(PhysicsWorld& physicsWorld, const PhysicsContact& contact)> |
Callback invoked when a pair of physics bodies begins a logical contact.
A body pair produces one logical contact lifecycle even when multiple underlying contact points exist.
Definition at line 62 of file PhysicsWorld.h.
| using a3d::PhysicsWorld::DidContinueContactCallback = std::function<void(PhysicsWorld& physicsWorld, const PhysicsContact& contact)> |
Callback invoked once per simulation step while a body pair remains in contact.
Ordering relative to callbacks for unrelated body pairs is unspecified.
Definition at line 70 of file PhysicsWorld.h.
| using a3d::PhysicsWorld::DidEndContactCallback = std::function<void(PhysicsWorld& physicsWorld, const PhysicsContact& contact)> |
Callback invoked when a tracked body pair ceases to be in contact.
Removing a physics body silently terminates its tracked contacts and does not generate end-contact callbacks. Ordering relative to callbacks for unrelated body pairs is unspecified.
Definition at line 80 of file PhysicsWorld.h.
| a3d::PhysicsWorld::PhysicsWorld | ( | ) |
Creates a PhysicsWorld with Earth-like gravity of (0, -9.807, 0).
| std::vector< PhysicsContact > a3d::PhysicsWorld::contactTest | ( | const PhysicsBody & | body | ) | const |
Returns current contacts between body and other physics bodies.
At most one representative PhysicsContact is returned for each body pair.
| std::optional< PhysicsContact > a3d::PhysicsWorld::contactTest | ( | const PhysicsBody & | bodyA, |
| const PhysicsBody & | bodyB | ||
| ) | const |
Tests for contact between bodyA and bodyB.
If the bodies have multiple contact points, the returned PhysicsContact represents the point with greatest collision impulse, using penetration depth as a tie-breaker.
| std::vector< PhysicsContact > a3d::PhysicsWorld::convexSweepTest | ( | const PhysicsShape & | shape, |
| const math::mat4 & | fromMat, | ||
| const math::mat4 & | toMat | ||
| ) | const |
Sweeps shape between two transforms.
Not currently implemented.
| std::runtime_error | always; convex sweep tests are not currently implemented. |
| std::vector< PhysicsContact > a3d::PhysicsWorld::convexSweepTest | ( | const PhysicsShape & | shape, |
| const math::mat4 & | fromMat, | ||
| const math::mat4 & | toMat, | ||
| const ConvexSweepTestOptions & | options | ||
| ) | const |
Sweeps shape between two transforms.
Not currently implemented.
| std::runtime_error | always; convex sweep tests are not currently implemented. |
| DidBeginContactCallback a3d::PhysicsWorld::didBeginContactCallback | ( | ) | const |
Returns the callback invoked when a body pair begins contact.
| void a3d::PhysicsWorld::didBeginContactCallback | ( | DidBeginContactCallback | function | ) |
Replaces the begin-contact callback; an empty callback disables it.
| DidContinueContactCallback a3d::PhysicsWorld::didContinueContactCallback | ( | ) | const |
Returns the callback invoked while a body pair remains in contact.
| void a3d::PhysicsWorld::didContinueContactCallback | ( | DidContinueContactCallback | function | ) |
Replaces the continuing-contact callback; an empty callback disables it.
| DidEndContactCallback a3d::PhysicsWorld::didEndContactCallback | ( | ) | const |
Returns the callback invoked when a tracked body pair ends contact.
| void a3d::PhysicsWorld::didEndContactCallback | ( | DidEndContactCallback | function | ) |
Replaces the end-contact callback; an empty callback disables it.
| const math::vec3 & a3d::PhysicsWorld::gravity | ( | ) | const |
Returns the world gravity acceleration vector.
| void a3d::PhysicsWorld::gravity | ( | const math::vec3 & | gravity | ) |
Sets the world gravity and immediately applies it to affected dynamic bodies.
| std::vector< HitTestResult > a3d::PhysicsWorld::rayTest | ( | const math::vec3 & | from, |
| const math::vec3 & | to | ||
| ) | const |
Tests the world-space segment from from to to and returns the closest physics hit.
| std::vector< HitTestResult > a3d::PhysicsWorld::rayTest | ( | const math::vec3 & | from, |
| const math::vec3 & | to, | ||
| const RayTestOptions & | options | ||
| ) | const |
Tests the world-space segment from from to to against physics bodies.
| options | controls whether any, the closest, or all hits are returned. |
options. | Scene * a3d::PhysicsWorld::scene | ( | ) | const |
Returns the Scene containing this PhysicsWorld, or nullptr when it is not installed in a Scene.