9#ifndef AVARA3D_PHYSICS_PHYSICSWORLD_H
10#define AVARA3D_PHYSICS_PHYSICSWORLD_H
18#include "a3d/scene/HitTestResult.h"
27 class PhysicsWorldProxy;
47 HitTestSearchMode
searchMode {HitTestSearchMode::Closest};
53 HitTestSearchMode
searchMode {HitTestSearchMode::Closest};
184 unsigned staticBodies {0};
185 unsigned dynamicBodies {0};
186 unsigned kinematicBodies {0};
187 unsigned primitiveShapes {0};
188 unsigned boundingBoxShapes {0};
189 unsigned convexHullShapes {0};
190 unsigned concavePolyhedronShapes {0};
191 unsigned activeContacts {0};
196 void attachedToScene(Scene&
scene);
197 void detachedFromScene(Scene&
scene);
199 void add(PhysicsBody& body);
200 void remove(PhysicsBody& body);
202 void step(
double deltaTime, Profiler& profiler);
204 Inventory inventory()
const;
206 void appendDebugLines(std::vector<Line>& out)
const;
208 PhysicsWorldProxy* proxy()
const;
214 std::unique_ptr<PhysicsWorldProxy> _proxy;
Rigid-body simulation state attached to a Node.
Describes collision geometry used by one or more PhysicsBody objects.
Simulates rigid bodies and performs physics collision queries for a Scene.
std::optional< PhysicsContact > contactTest(const PhysicsBody &bodyA, const PhysicsBody &bodyB) const
Tests for contact between bodyA and bodyB.
Scene * scene() const
Returns the Scene containing this PhysicsWorld, or nullptr when it is not installed in a Scene.
DidBeginContactCallback didBeginContactCallback() const
Returns the callback invoked when a body pair begins contact.
void didEndContactCallback(DidEndContactCallback function)
Replaces the end-contact callback; an empty callback disables it.
void didContinueContactCallback(DidContinueContactCallback function)
Replaces the continuing-contact callback; an empty callback disables it.
void didBeginContactCallback(DidBeginContactCallback function)
Replaces the begin-contact callback; an empty callback disables it.
const math::vec3 & gravity() const
Returns the world gravity acceleration vector.
DidContinueContactCallback didContinueContactCallback() const
Returns the callback invoked while a body pair remains in contact.
std::function< void(PhysicsWorld &physicsWorld, const PhysicsContact &contact)> DidBeginContactCallback
Callback invoked when a pair of physics bodies begins a logical contact.
std::vector< PhysicsContact > convexSweepTest(const PhysicsShape &shape, const math::mat4 &fromMat, const math::mat4 &toMat) const
Sweeps shape between two transforms.
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.
PhysicsWorld()
Creates a PhysicsWorld with Earth-like gravity of (0, -9.807, 0).
std::vector< PhysicsContact > convexSweepTest(const PhysicsShape &shape, const math::mat4 &fromMat, const math::mat4 &toMat, const ConvexSweepTestOptions &options) const
Sweeps shape between two transforms.
std::vector< PhysicsContact > contactTest(const PhysicsBody &body) const
Returns current contacts between body and other physics bodies.
std::function< void(PhysicsWorld &physicsWorld, const PhysicsContact &contact)> DidEndContactCallback
Callback invoked when a tracked body pair ceases to be in contact.
DidEndContactCallback didEndContactCallback() const
Returns the callback invoked when a tracked body pair ends contact.
std::function< void(PhysicsWorld &physicsWorld, const PhysicsContact &contact)> DidContinueContactCallback
Callback invoked once per simulation step while a body pair remains in contact.
void gravity(const math::vec3 &gravity)
Sets the world gravity and immediately applies it to affected dynamic bodies.
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.
Owns a scene graph and the worlds used to simulate and render it.
Options controlling a convex sweep collision query.
HitTestSearchMode searchMode
How matching sweep hits are selected.
Options controlling a ray collision query.
HitTestSearchMode searchMode
How matching ray hits are selected.