mitiru::physics3d

3D physics: rigid bodies, colliders, raycasts, constraint solver.

3D physics: rigid bodies, colliders, raycasts, constraint solver.

NameKindItems
BroadPhaseProxy3Dstruct2
BroadPhase3Dclass13
AABBCollider3Dstruct3
OBBCollider3Dstruct1
CapsuleColliderstruct16
ConvexShapestruct2
DistanceConstraintclass7
HingeConstraintclass5
ContactSolver3Dclass9
EpaFacestruct1
NarrowPhase3Dclass11
DebugDrawFlagsenum11
DebugColor3Dstruct8
PhysicsDebugRenderer3Dclass17
PhysicsSystem3Dclass20
ColliderType3Denum4
BroadphaseProxystruct1
PhysicsWorld3Dclass27
RigidBody3Dclass36
struct BroadPhaseProxy3D 2
[[nodiscard]] constexpr float minX() const noexcept
[[nodiscard]] constexpr float maxX() const noexcept
class BroadPhase3D 13
BroadPhase3D() = default
explicit BroadPhase3D(float margin) noexcept
void setMargin(float margin) noexcept
[[nodiscard]] constexpr float margin() const noexcept
void clear() noexcept
void addProxy(BodyId bodyId, std::size_t colliderIndex, const AABBCollider3D& aabb) noexcept
void sweep() noexcept
[[nodiscard]] const std::vector<BroadPhasePair3D>& candidatePairs() const noexcept
[[nodiscard]] std::size_t pairCount() const noexcept
[[nodiscard]] std::size_t proxyCount() const noexcept
[[nodiscard]] static AABBCollider3D computeAABB( const SphereCollider& sphere) noexcept
[[nodiscard]] static constexpr AABBCollider3D computeAABB( const AABBCollider3D& aabb) noexcept
[[nodiscard]] static AABBCollider3D computeAABB( const CapsuleCollider& capsule) noexcept
struct AABBCollider3D 3
[[nodiscard]] constexpr sgc::Vec3f center() const noexcept
[[nodiscard]] constexpr sgc::Vec3f halfExtents() const noexcept
[[nodiscard]] static constexpr AABBCollider3D fromCenterExtents( const sgc::Vec3f& center, const sgc::Vec3f& halfExtents) noexcept
struct OBBCollider3D 1
[[nodiscard]] sgc::Vec3f axis(int axisIndex) const noexcept
struct CapsuleCollider 16
[[nodiscard]] constexpr sgc::Vec3f center() const noexcept
[[nodiscard]] sgc::Vec3f axisDirection() const noexcept
[[nodiscard]] float axisLength() const noexcept
[[nodiscard]] inline ContactInfo3D testSphereSphere( const SphereCollider& a, const SphereCollider& b) noexcept
[[nodiscard]] inline constexpr sgc::Vec3f closestPointOnAABB( const sgc::Vec3f& point, const AABBCollider3D& aabb) noexcept
[[nodiscard]] inline ContactInfo3D testSphereAABB( const SphereCollider& sphere, const AABBCollider3D& aabb) noexcept
[[nodiscard]] inline ContactInfo3D testAABBAABB( const AABBCollider3D& a, const AABBCollider3D& b) noexcept
[[nodiscard]] inline std::optional<RayHit3D> raycastSphere( const Ray3D& ray, const SphereCollider& sphere, float maxDist = 1e6f) noexcept
[[nodiscard]] inline std::optional<RayHit3D> raycastAABB( const Ray3D& ray, const AABBCollider3D& aabb, float maxDist = 1e6f) noexcept
[[nodiscard]] inline sgc::Vec3f gjkSupport( const ConvexShape& a, const ConvexShape& b, const sgc::Vec3f& direction) noexcept
[[nodiscard]] inline constexpr sgc::Vec3f tripleProduct( const sgc::Vec3f& a, const sgc::Vec3f& b, const sgc::Vec3f& c) noexcept
[[nodiscard]] inline bool gjkIntersect(const ConvexShape& a, const ConvexShape& b) noexcept
[[nodiscard]] inline sgc::Vec3f closestPointOnSegment( const sgc::Vec3f& point, const sgc::Vec3f& segA, const sgc::Vec3f& segB) noexcept
inline void closestPointsSegmentSegment( const sgc::Vec3f& a0, const sgc::Vec3f& a1, const sgc::Vec3f& b0, const sgc::Vec3f& b1, sgc::Vec3f& outA, sgc::Vec3f& outB) noexcept
[[nodiscard]] inline ContactInfo3D testSphereCapsule( const SphereCollider& sphere, const CapsuleCollider& capsule) noexcept
[[nodiscard]] inline ContactInfo3D testCapsuleCapsule( const CapsuleCollider& a, const CapsuleCollider& b) noexcept
struct ConvexShape 2
std::vector<sgc::Vec3f> vertices
[[nodiscard]] sgc::Vec3f support(const sgc::Vec3f& direction) const noexcept
class DistanceConstraint 7
DistanceConstraint( RigidBody3D* bodyA, RigidBody3D* bodyB, float restLength, float stiffness = 1.0f) noexcept
void setAnchors(const sgc::Vec3f& anchorA, const sgc::Vec3f& anchorB) noexcept
void solve([[maybe_unused]] float dt) noexcept
void solveVelocity([[maybe_unused]] float dt) noexcept
[[nodiscard]] constexpr float restLength() const noexcept
void setRestLength(float len) noexcept
[[nodiscard]] constexpr float stiffness() const noexcept
class HingeConstraint 5
HingeConstraint( RigidBody3D* bodyA, RigidBody3D* bodyB, const sgc::Vec3f& worldPivot, const sgc::Vec3f& worldAxis) noexcept
void setLimits(float minAngle, float maxAngle) noexcept
[[nodiscard]] constexpr bool hasLimits() const noexcept
void solve([[maybe_unused]] float dt) noexcept
[[nodiscard]] const sgc::Vec3f& axis() const noexcept
class ContactSolver3D 9
ContactSolver3D() = default
explicit ContactSolver3D(const ContactSolverConfig3D& config) noexcept
void configure(const ContactSolverConfig3D& config) noexcept
[[nodiscard]] constexpr const ContactSolverConfig3D& config() const noexcept
void prepare( std::vector<ContactManifold3D>& manifolds, const std::unordered_map<BodyId, std::unique_ptr<RigidBody3D>>& bodies) noexcept
void warmStart( const std::vector<ContactManifold3D>& manifolds, std::unordered_map<BodyId, std::unique_ptr<RigidBody3D>>& bodies) noexcept
void solve( std::vector<ContactManifold3D>& manifolds, std::unordered_map<BodyId, std::unique_ptr<RigidBody3D>>& bodies) noexcept
void solvePositions( const std::vector<ContactManifold3D>& manifolds, std::unordered_map<BodyId, std::unique_ptr<RigidBody3D>>& bodies) noexcept
[[nodiscard]] static std::size_t manifoldCount( const std::vector<ContactManifold3D>& manifolds) noexcept
struct EpaFace 1
std::array<sgc::Vec3f, 3> vertices
class NarrowPhase3D 11
NarrowPhase3D() = default
void setMaxIterations(int iterations) noexcept
[[nodiscard]] constexpr int maxIterations() const noexcept
[[nodiscard]] static NarrowPhaseResult3D testSphereSphere( const SphereCollider& a, const SphereCollider& b) noexcept
[[nodiscard]] static NarrowPhaseResult3D testSphereBox( const SphereCollider& sphere, const AABBCollider3D& aabb) noexcept
[[nodiscard]] static NarrowPhaseResult3D testBoxBox( const AABBCollider3D& a, const AABBCollider3D& b) noexcept
[[nodiscard]] static NarrowPhaseResult3D testSphereCapsule( const SphereCollider& sphere, const CapsuleCollider& capsule) noexcept
[[nodiscard]] static NarrowPhaseResult3D testCapsuleCapsule( const CapsuleCollider& a, const CapsuleCollider& b) noexcept
[[nodiscard]] NarrowPhaseResult3D testConvexConvex( const ConvexShape& a, const ConvexShape& b) const noexcept
[[nodiscard]] static ConvexShape sphereToConvex( const SphereCollider& sphere, int subdivisions = 2) noexcept
[[nodiscard]] static ConvexShape aabbToConvex(const AABBCollider3D& aabb) noexcept
enum DebugDrawFlags : uint32_t 11
None = 0
Colliders = 1 << 0
Contacts = 1 << 1
Velocities = 1 << 2
Constraints = 1 << 3
AABBs = 1 << 4
CenterOfMass = 1 << 5
All = 0xFFFFFFFF
[[nodiscard]] inline constexpr DebugDrawFlags operator|( DebugDrawFlags a, DebugDrawFlags b) noexcept
[[nodiscard]] inline constexpr DebugDrawFlags operator&( DebugDrawFlags a, DebugDrawFlags b) noexcept
[[nodiscard]] inline constexpr bool hasFlag( DebugDrawFlags flags, DebugDrawFlags flag) noexcept
struct DebugColor3D 8
[[nodiscard]] static constexpr DebugColor3D green() noexcept
[[nodiscard]] static constexpr DebugColor3D red() noexcept
[[nodiscard]] static constexpr DebugColor3D blue() noexcept
[[nodiscard]] static constexpr DebugColor3D yellow() noexcept
[[nodiscard]] static constexpr DebugColor3D cyan() noexcept
[[nodiscard]] static constexpr DebugColor3D magenta() noexcept
[[nodiscard]] static constexpr DebugColor3D white() noexcept
[[nodiscard]] static constexpr DebugColor3D gray() noexcept
class PhysicsDebugRenderer3D 17
PhysicsDebugRenderer3D() = default
void setFlags(DebugDrawFlags flags) noexcept
[[nodiscard]] constexpr DebugDrawFlags flags() const noexcept
void setVelocityScale(float scale) noexcept
void setNormalLength(float length) noexcept
void setSphereSegments(int segments) noexcept
void clear() noexcept
void gather( const PhysicsWorld3D& world, const std::vector<ContactManifold3D>& manifolds = {}) noexcept
void addCollider(const BodyCollider& collider) noexcept
void addContact(const sgc::Vec3f& point, const sgc::Vec3f& normal, float depth) noexcept
void addVelocity(const sgc::Vec3f& position, const sgc::Vec3f& velocity) noexcept
[[nodiscard]] const std::vector<DebugLine3D>& lines() const noexcept
[[nodiscard]] const std::vector<DebugPoint3D>& points() const noexcept
[[nodiscard]] std::size_t lineCount() const noexcept
[[nodiscard]] std::size_t pointCount() const noexcept
void gatherBody(const RigidBody3D& body, const BodyCollider& collider) noexcept
using CollisionCallback3DEcs = std::function<void(const CollisionEvent3D&)>;
class PhysicsSystem3D : public scene::ISystem 20
explicit PhysicsSystem3D(const PhysicsSystem3DConfig& config = {})
[[nodiscard]] std::string name() const override
void update(scene::GameWorld& gameWorld, float dt) override
void setGravity(const sgc::Vec3f& gravity) noexcept
[[nodiscard]] const sgc::Vec3f& gravity() const noexcept
[[nodiscard]] const PhysicsSystem3DConfig& config() const noexcept
void registerCollisionCallback(CollisionCallback3DEcs callback)
void addDistanceConstraint(DistanceConstraint constraint) noexcept
void addHingeConstraint(HingeConstraint constraint) noexcept
void setDebugDrawEnabled(bool enabled) noexcept
void setDebugDrawFlags(DebugDrawFlags flags) noexcept
[[nodiscard]] const PhysicsDebugRenderer3D& debugRenderer() const noexcept
[[nodiscard]] std::size_t bodyCount() const noexcept
[[nodiscard]] std::size_t colliderCount() const noexcept
[[nodiscard]] std::size_t lastContactCount() const noexcept
[[nodiscard]] std::size_t lastBroadPhasePairCount() const noexcept
[[nodiscard]] std::optional<RayHit3D> raycast( const Ray3D& ray, float maxDist = 1e6f) const noexcept
[[nodiscard]] PhysicsWorld3D& physicsWorld() noexcept
[[nodiscard]] const PhysicsWorld3D& physicsWorld() const noexcept
[[nodiscard]] const std::vector<ContactManifold3D>& lastManifolds() const noexcept
enum ColliderType3D 4
Sphere
AABB
Capsule
using CollisionCallback3D = std::function<void(const WorldContact3D&)>;
struct BroadphaseProxy 1
[[nodiscard]] constexpr float minX() const noexcept
class PhysicsWorld3D 27
PhysicsWorld3D() = default
void setGravity(const sgc::Vec3f& gravity) noexcept
[[nodiscard]] constexpr const sgc::Vec3f& gravity() const noexcept
RigidBody3D& addBody() noexcept
void removeBody(BodyId id) noexcept
[[nodiscard]] RigidBody3D* getBody(BodyId id) noexcept
[[nodiscard]] const RigidBody3D* getBody(BodyId id) const noexcept
[[nodiscard]] std::size_t bodyCount() const noexcept
void addSphereCollider(BodyId bodyId, const SphereCollider& sphere) noexcept
void addAABBCollider(BodyId bodyId, const AABBCollider3D& aabb) noexcept
void addCapsuleCollider(BodyId bodyId, const CapsuleCollider& capsule) noexcept
[[nodiscard]] std::size_t colliderCount() const noexcept
void addDistanceConstraint(DistanceConstraint constraint) noexcept
void addHingeConstraint(HingeConstraint constraint) noexcept
[[nodiscard]] std::size_t constraintCount() const noexcept
void registerCollisionCallback(CollisionCallback3D callback) noexcept
void setSolverIterations(int iterations) noexcept
void step(float dt) noexcept
[[nodiscard]] std::size_t lastContactCount() const noexcept
[[nodiscard]] std::unordered_map<BodyId, std::unique_ptr<RigidBody3D>>& bodies() noexcept
[[nodiscard]] const std::unordered_map<BodyId, std::unique_ptr<RigidBody3D>>& bodies() const noexcept
[[nodiscard]] std::vector<BodyCollider>& colliders() noexcept
[[nodiscard]] const std::vector<BodyCollider>& colliders() const noexcept
[[nodiscard]] static AABBCollider3D computeAABB(const BodyCollider& collider) noexcept
[[nodiscard]] std::optional<RayHit3D> raycast( const Ray3D& ray, float maxDist = 1e6f) const noexcept
using BodyId = uint32_t;
inline constexpr BodyId INVALID_BODY_ID = 0
class RigidBody3D 36
RigidBody3D() noexcept
explicit RigidBody3D(float mass) noexcept
[[nodiscard]] constexpr const sgc::Vec3f& position() const noexcept
void setPosition(const sgc::Vec3f& pos) noexcept
[[nodiscard]] constexpr const sgc::Quaternionf& rotation() const noexcept
void setRotation(const sgc::Quaternionf& rot) noexcept
[[nodiscard]] constexpr float mass() const noexcept
[[nodiscard]] constexpr float inverseMass() const noexcept
void setMass(float mass) noexcept
[[nodiscard]] constexpr const sgc::Mat3f& inertiaTensor() const noexcept
[[nodiscard]] constexpr const sgc::Mat3f& inverseInertiaTensor() const noexcept
void setInertiaTensor(const sgc::Mat3f& tensor) noexcept
void setBoxInertiaTensor(const sgc::Vec3f& halfExtents) noexcept
void setSphereInertiaTensor(float radius) noexcept
[[nodiscard]] constexpr bool isStatic() const noexcept
[[nodiscard]] constexpr const sgc::Vec3f& linearVelocity() const noexcept
void setLinearVelocity(const sgc::Vec3f& vel) noexcept
[[nodiscard]] constexpr const sgc::Vec3f& angularVelocity() const noexcept
void setAngularVelocity(const sgc::Vec3f& vel) noexcept
[[nodiscard]] constexpr float linearDamping() const noexcept
void setLinearDamping(float damping) noexcept
[[nodiscard]] constexpr float angularDamping() const noexcept
void setAngularDamping(float damping) noexcept
[[nodiscard]] constexpr float restitution() const noexcept
void setRestitution(float e) noexcept
[[nodiscard]] constexpr float friction() const noexcept
void setFriction(float f) noexcept
void applyForce(const sgc::Vec3f& force) noexcept
void applyTorque(const sgc::Vec3f& torque) noexcept
void applyForceAtPoint(const sgc::Vec3f& force, const sgc::Vec3f& worldPoint) noexcept
void applyImpulse(const sgc::Vec3f& impulse) noexcept
void applyImpulseAtPoint(const sgc::Vec3f& impulse, const sgc::Vec3f& worldPoint) noexcept
void clearForces() noexcept
void integrate(float dt) noexcept
[[nodiscard]] constexpr BodyId id() const noexcept
void setId(BodyId id) noexcept

Sourced from docs/API_CATALOG.md, auto-generated by tools/generate_api_catalog.py.