9#ifndef AVARA3D_PHYSICS_PHYSICSBODY_H
10#define AVARA3D_PHYSICS_PHYSICSBODY_H
21 class PhysicsBodyProxy;
22 class PhysicsShapeProxy;
45 enum class Type : uint8_t {
70 static std::unique_ptr<PhysicsBody>
StaticBody(
const std::shared_ptr<PhysicsShape>&
shape);
83 static std::unique_ptr<PhysicsBody>
DynamicBody(
const std::shared_ptr<PhysicsShape>&
shape);
136 const std::shared_ptr<PhysicsShape>&
shape()
const;
362 void attachedToNode(
const std::shared_ptr<Node>& node);
363 void detachedFromNode(
const std::shared_ptr<Node>& node);
365 void meshDetachedFromNode(
const std::shared_ptr<Node>& node,
const std::shared_ptr<Mesh>& mesh);
366 void meshAttachedToNode(
const std::shared_ptr<Node>& node,
const std::shared_ptr<Mesh>& mesh);
368 void meshWillChangeOnNode(
const std::shared_ptr<Node>& node,
const std::shared_ptr<Mesh>& oldMesh);
369 void meshDidChangeOnNode(
const std::shared_ptr<Node>& node,
const std::shared_ptr<Mesh>& newMesh);
377 void shapeWillUpdate();
378 void shapeDidUpdate();
380 void syncTransformFromNode();
382 std::weak_ptr<Node> node()
const;
387 PhysicsBodyProxy* proxy()
const;
392 void checkAutocreateShape(
const std::shared_ptr<Node>& node);
393 void checkAutocreateShape(
const std::shared_ptr<Mesh>& mesh);
395 void checkAddToWorld();
399 std::shared_ptr<PhysicsShape> _shape;
400 bool _shapeAutocreated;
401 std::unique_ptr<PhysicsBodyProxy> _proxy;
402 std::weak_ptr<Node> _node;
Rigid-body simulation state attached to a Node.
void autocalculatesMomentOfInertia(bool autocalculate)
Enables or disables automatic moment-of-inertia calculation.
static std::unique_ptr< PhysicsBody > KinematicBody(const std::shared_ptr< PhysicsShape > &shape)
Creates a kinematic body using shape.
void linearDamping(float damping)
Sets the linear damping coefficient.
bool allowsResting() const
Returns whether the body is allowed to enter the resting state automatically.
PhysicsBody(Type type, const std::shared_ptr< PhysicsShape > &shape)
Creates a body of type using shape.
float linearDamping() const
Returns the linear damping coefficient.
void ccdMotionThreshold(float distance)
Sets the motion-distance threshold used by continuous collision detection; negative values become zer...
bool resting() const
Returns whether the body is currently resting.
void applyTorque(const math::vec3 &torque, bool impulse)
Applies torque or a torque impulse to a dynamic body.
void centerOfMassCalculation(CenterOfMassCalculation calculation)
Sets the method used for automatic center-of-mass calculation.
void resting(bool resting)
Forces the body into or out of the resting state.
void allowsResting(bool allowsResting)
Sets whether the body may enter the resting state automatically.
Type type() const
Returns the body type.
float spinningFriction() const
Returns the spinning-friction coefficient.
bool autocalculatesMomentOfInertia() const
Returns whether the moment of inertia is calculated automatically from mass and collision shape.
void linearSleepingThreshold(float threshold)
Sets the linear-speed threshold used when deciding whether the body may rest.
void restitution(float restitution)
Sets the collision restitution coefficient.
math::vec3 angularVelocity() const
Returns the body angular velocity in radians per second.
void autocalculatesCenterOfMass(bool autocalculate)
Enables or disables automatic center-of-mass calculation.
void ccdEnabled(bool enabled)
Enables or disables continuous collision detection for this body.
void mass(float mass)
Sets the mass of a dynamic body.
bool ccdEnabled() const
Returns whether continuous collision detection is enabled.
CenterOfMassCalculation centerOfMassCalculation() const
Returns the method used for automatic center-of-mass calculation.
math::vec3 angularFactor() const
Returns the per-axis factor applied to angular motion.
math::vec3 momentOfInertia() const
Returns the body's local principal-axis moment of inertia.
static std::unique_ptr< PhysicsBody > KinematicBody()
Creates a shape-less kinematic body.
float linearSleepingThreshold() const
Returns the linear-speed threshold used when deciding whether the body may rest.
math::vec3 totalForce() const
Returns the accumulated force for the current simulation step.
void clearForces()
Clears accumulated forces and torques without changing the body's velocities.
void friction(float friction)
Sets the sliding-friction coefficient.
PhysicsBody(Type type)
Creates a shape-less body of type.
math::vec3 centerOfMass() const
Returns the center-of-mass offset from the owning node's origin in local coordinates.
bool affectedByGravity() const
Returns whether this body is affected by its PhysicsWorld gravity.
void angularVelocity(const math::vec3 &velocity)
Sets the body angular velocity in radians per second.
void linearFactor(const math::vec3 &factor)
Sets the per-axis factor applied to linear motion.
float restitution() const
Returns the collision restitution coefficient.
Type
Determines how a rigid body participates in simulation.
float ccdMotionThreshold() const
Returns the configured continuous-collision motion threshold.
math::vec3 totalTorque() const
Returns the accumulated torque for the current simulation step.
static std::unique_ptr< PhysicsBody > StaticBody()
Creates a shape-less static body.
void momentOfInertia(const math::vec3 &moment)
Sets the local principal-axis moment of inertia when automatic calculation is disabled.
float ccdSweptSphereRadius() const
Returns the configured continuous-collision swept-sphere radius.
void linearVelocity(const math::vec3 &velocity)
Sets the body linear velocity in world coordinates.
void spinningFriction(float friction)
Sets the spinning-friction coefficient.
void shape(const std::shared_ptr< PhysicsShape > &shape)
Replaces the collision shape retained by this body; nullptr removes it.
void rollingFriction(float friction)
Sets the rolling-friction coefficient.
void centerOfMass(const math::vec3 &offset)
Sets a dynamic body's local center-of-mass offset and disables automatic calculation.
CenterOfMassCalculation
Selects the method used to automatically determine a dynamic body's center of mass.
void applyForce(const math::vec3 &force, const math::vec3 &location, bool impulse)
Applies a force or impulse at a world-space position on a dynamic body.
void ccdSweptSphereRadius(float radius)
Sets the swept-sphere radius used by continuous collision detection; negative values become zero.
void applyForce(const math::vec3 &force, bool impulse)
Applies a central force or impulse to a dynamic body.
void angularSleepingThreshold(float threshold)
Sets the angular-speed threshold used when deciding whether the body may rest.
static std::unique_ptr< PhysicsBody > DynamicBody(const std::shared_ptr< PhysicsShape > &shape)
Creates a dynamic body using shape.
float friction() const
Returns the sliding-friction coefficient.
const std::shared_ptr< PhysicsShape > & shape() const
Returns the collision shape retained by this body, or nullptr if no shape is assigned.
static std::unique_ptr< PhysicsBody > DynamicBody()
Creates a shape-less dynamic body.
bool autocalculatesCenterOfMass() const
Returns whether the center of mass is calculated automatically.
float mass() const
Returns the body mass.
void angularDamping(float damping)
Sets the angular damping coefficient.
float rollingFriction() const
Returns the rolling-friction coefficient.
float angularSleepingThreshold() const
Returns the angular-speed threshold used when deciding whether the body may rest.
void type(Type type)
Validates the requested body type.
void affectedByGravity(bool affectedByGravity)
Sets whether this body is affected by its PhysicsWorld gravity.
void angularFactor(const math::vec3 &factor)
Sets the per-axis factor applied to angular motion.
math::vec3 linearVelocity() const
Returns the body linear velocity in world coordinates.
float angularDamping() const
Returns the angular damping coefficient.
static std::unique_ptr< PhysicsBody > StaticBody(const std::shared_ptr< PhysicsShape > &shape)
Creates a static body using shape.
math::vec3 linearFactor() const
Returns the per-axis factor applied to linear motion.
Simulates rigid bodies and performs physics collision queries for a Scene.