|
Avara3D 0.2.0
C++ API reference
|
Rigid-body simulation state attached to a Node. More...
#include <a3d/physics/PhysicsBody.h>
Public Types | |
| enum class | Type : uint8_t { Static , Dynamic , Kinematic } |
| Determines how a rigid body participates in simulation. More... | |
| enum class | CenterOfMassCalculation : uint8_t { BoundsCenter } |
| Selects the method used to automatically determine a dynamic body's center of mass. More... | |
Public Member Functions | |
| PhysicsBody (Type type) | |
Creates a shape-less body of type. More... | |
| PhysicsBody (Type type, const std::shared_ptr< PhysicsShape > &shape) | |
Creates a body of type using shape. More... | |
| Type | type () const |
| Returns the body type. More... | |
| void | type (Type type) |
| Validates the requested body type. More... | |
| const std::shared_ptr< PhysicsShape > & | shape () const |
| Returns the collision shape retained by this body, or nullptr if no shape is assigned. More... | |
| void | shape (const std::shared_ptr< PhysicsShape > &shape) |
| Replaces the collision shape retained by this body; nullptr removes it. More... | |
| float | mass () const |
| Returns the body mass. More... | |
| void | mass (float mass) |
| Sets the mass of a dynamic body. More... | |
| math::vec3 | momentOfInertia () const |
| Returns the body's local principal-axis moment of inertia. More... | |
| void | momentOfInertia (const math::vec3 &moment) |
| Sets the local principal-axis moment of inertia when automatic calculation is disabled. More... | |
| math::vec3 | centerOfMass () const |
| Returns the center-of-mass offset from the owning node's origin in local coordinates. More... | |
| void | centerOfMass (const math::vec3 &offset) |
| Sets a dynamic body's local center-of-mass offset and disables automatic calculation. More... | |
| float | friction () const |
| Returns the sliding-friction coefficient. More... | |
| void | friction (float friction) |
| Sets the sliding-friction coefficient. More... | |
| float | rollingFriction () const |
| Returns the rolling-friction coefficient. More... | |
| void | rollingFriction (float friction) |
| Sets the rolling-friction coefficient. More... | |
| float | spinningFriction () const |
| Returns the spinning-friction coefficient. More... | |
| void | spinningFriction (float friction) |
| Sets the spinning-friction coefficient. More... | |
| float | restitution () const |
| Returns the collision restitution coefficient. More... | |
| void | restitution (float restitution) |
| Sets the collision restitution coefficient. More... | |
| math::vec3 | linearVelocity () const |
| Returns the body linear velocity in world coordinates. More... | |
| void | linearVelocity (const math::vec3 &velocity) |
| Sets the body linear velocity in world coordinates. More... | |
| math::vec3 | angularVelocity () const |
| Returns the body angular velocity in radians per second. More... | |
| void | angularVelocity (const math::vec3 &velocity) |
| Sets the body angular velocity in radians per second. More... | |
| math::vec3 | linearFactor () const |
| Returns the per-axis factor applied to linear motion. More... | |
| void | linearFactor (const math::vec3 &factor) |
| Sets the per-axis factor applied to linear motion. More... | |
| math::vec3 | angularFactor () const |
| Returns the per-axis factor applied to angular motion. More... | |
| void | angularFactor (const math::vec3 &factor) |
| Sets the per-axis factor applied to angular motion. More... | |
| float | linearDamping () const |
| Returns the linear damping coefficient. More... | |
| void | linearDamping (float damping) |
| Sets the linear damping coefficient. More... | |
| float | angularDamping () const |
| Returns the angular damping coefficient. More... | |
| void | angularDamping (float damping) |
| Sets the angular damping coefficient. More... | |
| float | linearSleepingThreshold () const |
| Returns the linear-speed threshold used when deciding whether the body may rest. More... | |
| void | linearSleepingThreshold (float threshold) |
| Sets the linear-speed threshold used when deciding whether the body may rest. More... | |
| float | angularSleepingThreshold () const |
| Returns the angular-speed threshold used when deciding whether the body may rest. More... | |
| void | angularSleepingThreshold (float threshold) |
| Sets the angular-speed threshold used when deciding whether the body may rest. More... | |
| void | applyForce (const math::vec3 &force, bool impulse) |
| Applies a central force or impulse to a dynamic body. More... | |
| 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. More... | |
| void | applyTorque (const math::vec3 &torque, bool impulse) |
| Applies torque or a torque impulse to a dynamic body. More... | |
| math::vec3 | totalForce () const |
| Returns the accumulated force for the current simulation step. More... | |
| math::vec3 | totalTorque () const |
| Returns the accumulated torque for the current simulation step. More... | |
| void | clearForces () |
| Clears accumulated forces and torques without changing the body's velocities. More... | |
| void | ccdEnabled (bool enabled) |
| Enables or disables continuous collision detection for this body. More... | |
| bool | ccdEnabled () const |
| Returns whether continuous collision detection is enabled. More... | |
| void | ccdMotionThreshold (float distance) |
| Sets the motion-distance threshold used by continuous collision detection; negative values become zero. More... | |
| float | ccdMotionThreshold () const |
| Returns the configured continuous-collision motion threshold. More... | |
| void | ccdSweptSphereRadius (float radius) |
| Sets the swept-sphere radius used by continuous collision detection; negative values become zero. More... | |
| float | ccdSweptSphereRadius () const |
| Returns the configured continuous-collision swept-sphere radius. More... | |
| bool | affectedByGravity () const |
| Returns whether this body is affected by its PhysicsWorld gravity. More... | |
| void | affectedByGravity (bool affectedByGravity) |
| Sets whether this body is affected by its PhysicsWorld gravity. More... | |
| bool | allowsResting () const |
| Returns whether the body is allowed to enter the resting state automatically. More... | |
| void | allowsResting (bool allowsResting) |
| Sets whether the body may enter the resting state automatically. More... | |
| bool | resting () const |
| Returns whether the body is currently resting. More... | |
| void | resting (bool resting) |
| Forces the body into or out of the resting state. More... | |
| bool | autocalculatesCenterOfMass () const |
| Returns whether the center of mass is calculated automatically. More... | |
| void | autocalculatesCenterOfMass (bool autocalculate) |
| Enables or disables automatic center-of-mass calculation. More... | |
| CenterOfMassCalculation | centerOfMassCalculation () const |
| Returns the method used for automatic center-of-mass calculation. More... | |
| void | centerOfMassCalculation (CenterOfMassCalculation calculation) |
| Sets the method used for automatic center-of-mass calculation. More... | |
| bool | autocalculatesMomentOfInertia () const |
| Returns whether the moment of inertia is calculated automatically from mass and collision shape. More... | |
| void | autocalculatesMomentOfInertia (bool autocalculate) |
| Enables or disables automatic moment-of-inertia calculation. More... | |
Static Public Member Functions | |
| static std::unique_ptr< PhysicsBody > | StaticBody () |
| Creates a shape-less static body. More... | |
| static std::unique_ptr< PhysicsBody > | StaticBody (const std::shared_ptr< PhysicsShape > &shape) |
Creates a static body using shape. More... | |
| static std::unique_ptr< PhysicsBody > | DynamicBody () |
| Creates a shape-less dynamic body. More... | |
| static std::unique_ptr< PhysicsBody > | DynamicBody (const std::shared_ptr< PhysicsShape > &shape) |
Creates a dynamic body using shape. More... | |
| static std::unique_ptr< PhysicsBody > | KinematicBody () |
| Creates a shape-less kinematic body. More... | |
| static std::unique_ptr< PhysicsBody > | KinematicBody (const std::shared_ptr< PhysicsShape > &shape) |
Creates a kinematic body using shape. More... | |
Rigid-body simulation state attached to a Node.
A Node owns its PhysicsBody, while the body retains its PhysicsShape with shared ownership so a shape may be reused by multiple bodies. Dynamic bodies are driven by simulation, kinematic bodies are moved explicitly through their Node transform, and static bodies represent fixed collision geometry.
When a body without an explicit shape is attached to a Node, A3D attempts to derive a suitable collision shape from the node's mesh or hierarchy. Automatically derived shapes are rebuilt when the owning Node's Mesh changes; explicitly assigned shapes are left unchanged.
Definition at line 39 of file PhysicsBody.h.
|
strong |
Selects the method used to automatically determine a dynamic body's center of mass.
| Enumerator | |
|---|---|
| BoundsCenter | Uses the center of the collision shape's local bounds. |
Definition at line 52 of file PhysicsBody.h.
|
strong |
Determines how a rigid body participates in simulation.
Definition at line 45 of file PhysicsBody.h.
|
explicit |
Creates a shape-less body of type.
| a3d::PhysicsBody::PhysicsBody | ( | Type | type, |
| const std::shared_ptr< PhysicsShape > & | shape | ||
| ) |
Creates a body of type using shape.
| std::logic_error | if shape is incompatible with type, or if collision geometry must be created and its source has expired or cannot produce a valid collision shape. |
| std::invalid_argument | if shape is derived from a Mesh with no elements. |
| bool a3d::PhysicsBody::affectedByGravity | ( | ) | const |
Returns whether this body is affected by its PhysicsWorld gravity.
| void a3d::PhysicsBody::affectedByGravity | ( | bool | affectedByGravity | ) |
Sets whether this body is affected by its PhysicsWorld gravity.
| bool a3d::PhysicsBody::allowsResting | ( | ) | const |
Returns whether the body is allowed to enter the resting state automatically.
| void a3d::PhysicsBody::allowsResting | ( | bool | allowsResting | ) |
Sets whether the body may enter the resting state automatically.
Kinematic bodies cannot enable resting.
| std::logic_error | if allowsResting is true for a kinematic body. |
| float a3d::PhysicsBody::angularDamping | ( | ) | const |
Returns the angular damping coefficient.
| void a3d::PhysicsBody::angularDamping | ( | float | damping | ) |
Sets the angular damping coefficient.
| math::vec3 a3d::PhysicsBody::angularFactor | ( | ) | const |
Returns the per-axis factor applied to angular motion.
| void a3d::PhysicsBody::angularFactor | ( | const math::vec3 & | factor | ) |
Sets the per-axis factor applied to angular motion.
| float a3d::PhysicsBody::angularSleepingThreshold | ( | ) | const |
Returns the angular-speed threshold used when deciding whether the body may rest.
| void a3d::PhysicsBody::angularSleepingThreshold | ( | float | threshold | ) |
Sets the angular-speed threshold used when deciding whether the body may rest.
| math::vec3 a3d::PhysicsBody::angularVelocity | ( | ) | const |
Returns the body angular velocity in radians per second.
| void a3d::PhysicsBody::angularVelocity | ( | const math::vec3 & | velocity | ) |
Sets the body angular velocity in radians per second.
| void a3d::PhysicsBody::applyForce | ( | const math::vec3 & | force, |
| bool | impulse | ||
| ) |
Applies a central force or impulse to a dynamic body.
| force | world-space force vector, or impulse vector when impulse is true. |
| impulse | when true, applies force as an instantaneous impulse instead of a continuous force. |
| std::logic_error | if the body is not dynamic. |
| void a3d::PhysicsBody::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.
| force | world-space force vector, or impulse vector when impulse is true. |
| location | world-space application position. |
| impulse | when true, applies force as an instantaneous impulse instead of a continuous force. |
| std::logic_error | if the body is not dynamic. |
| void a3d::PhysicsBody::applyTorque | ( | const math::vec3 & | torque, |
| bool | impulse | ||
| ) |
Applies torque or a torque impulse to a dynamic body.
| torque | torque vector, or angular impulse when impulse is true. |
| impulse | when true, applies torque as an instantaneous angular impulse. |
| std::logic_error | if the body is not dynamic. |
| bool a3d::PhysicsBody::autocalculatesCenterOfMass | ( | ) | const |
Returns whether the center of mass is calculated automatically.
| void a3d::PhysicsBody::autocalculatesCenterOfMass | ( | bool | autocalculate | ) |
Enables or disables automatic center-of-mass calculation.
Enabling recomputes the center of mass. Disabling preserves the current offset for subsequent manual adjustment.
| std::logic_error | if automatic calculation is enabled for a non-dynamic body. |
| bool a3d::PhysicsBody::autocalculatesMomentOfInertia | ( | ) | const |
Returns whether the moment of inertia is calculated automatically from mass and collision shape.
| void a3d::PhysicsBody::autocalculatesMomentOfInertia | ( | bool | autocalculate | ) |
Enables or disables automatic moment-of-inertia calculation.
| bool a3d::PhysicsBody::ccdEnabled | ( | ) | const |
Returns whether continuous collision detection is enabled.
| void a3d::PhysicsBody::ccdEnabled | ( | bool | enabled | ) |
Enables or disables continuous collision detection for this body.
| float a3d::PhysicsBody::ccdMotionThreshold | ( | ) | const |
Returns the configured continuous-collision motion threshold.
| void a3d::PhysicsBody::ccdMotionThreshold | ( | float | distance | ) |
Sets the motion-distance threshold used by continuous collision detection; negative values become zero.
| float a3d::PhysicsBody::ccdSweptSphereRadius | ( | ) | const |
Returns the configured continuous-collision swept-sphere radius.
| void a3d::PhysicsBody::ccdSweptSphereRadius | ( | float | radius | ) |
Sets the swept-sphere radius used by continuous collision detection; negative values become zero.
| math::vec3 a3d::PhysicsBody::centerOfMass | ( | ) | const |
Returns the center-of-mass offset from the owning node's origin in local coordinates.
| void a3d::PhysicsBody::centerOfMass | ( | const math::vec3 & | offset | ) |
Sets a dynamic body's local center-of-mass offset and disables automatic calculation.
| std::logic_error | if the body is not dynamic. |
| CenterOfMassCalculation a3d::PhysicsBody::centerOfMassCalculation | ( | ) | const |
Returns the method used for automatic center-of-mass calculation.
| void a3d::PhysicsBody::centerOfMassCalculation | ( | CenterOfMassCalculation | calculation | ) |
Sets the method used for automatic center-of-mass calculation.
If automatic calculation is enabled, the center of mass is recomputed.
| std::logic_error | if the body is not dynamic. |
| void a3d::PhysicsBody::clearForces | ( | ) |
Clears accumulated forces and torques without changing the body's velocities.
|
static |
Creates a shape-less dynamic body.
|
static |
Creates a dynamic body using shape.
| std::logic_error | if shape is incompatible with a dynamic body, or if collision geometry must be created and its source has expired or cannot produce a valid collision shape. |
| std::invalid_argument | if shape is derived from a Mesh with no elements. |
| float a3d::PhysicsBody::friction | ( | ) | const |
Returns the sliding-friction coefficient.
| void a3d::PhysicsBody::friction | ( | float | friction | ) |
Sets the sliding-friction coefficient.
|
static |
Creates a shape-less kinematic body.
|
static |
Creates a kinematic body using shape.
| std::logic_error | if shape is incompatible with a kinematic body, or if collision geometry must be created and its source has expired or cannot produce a valid collision shape. |
| std::invalid_argument | if shape is derived from a Mesh with no elements. |
| float a3d::PhysicsBody::linearDamping | ( | ) | const |
Returns the linear damping coefficient.
| void a3d::PhysicsBody::linearDamping | ( | float | damping | ) |
Sets the linear damping coefficient.
| math::vec3 a3d::PhysicsBody::linearFactor | ( | ) | const |
Returns the per-axis factor applied to linear motion.
| void a3d::PhysicsBody::linearFactor | ( | const math::vec3 & | factor | ) |
Sets the per-axis factor applied to linear motion.
| float a3d::PhysicsBody::linearSleepingThreshold | ( | ) | const |
Returns the linear-speed threshold used when deciding whether the body may rest.
| void a3d::PhysicsBody::linearSleepingThreshold | ( | float | threshold | ) |
Sets the linear-speed threshold used when deciding whether the body may rest.
| math::vec3 a3d::PhysicsBody::linearVelocity | ( | ) | const |
Returns the body linear velocity in world coordinates.
| void a3d::PhysicsBody::linearVelocity | ( | const math::vec3 & | velocity | ) |
Sets the body linear velocity in world coordinates.
| float a3d::PhysicsBody::mass | ( | ) | const |
Returns the body mass.
| void a3d::PhysicsBody::mass | ( | float | mass | ) |
Sets the mass of a dynamic body.
| std::logic_error | if the body is not dynamic. |
| std::invalid_argument | if mass is less than or equal to zero. |
| math::vec3 a3d::PhysicsBody::momentOfInertia | ( | ) | const |
Returns the body's local principal-axis moment of inertia.
| void a3d::PhysicsBody::momentOfInertia | ( | const math::vec3 & | moment | ) |
Sets the local principal-axis moment of inertia when automatic calculation is disabled.
| bool a3d::PhysicsBody::resting | ( | ) | const |
Returns whether the body is currently resting.
| void a3d::PhysicsBody::resting | ( | bool | resting | ) |
Forces the body into or out of the resting state.
| float a3d::PhysicsBody::restitution | ( | ) | const |
Returns the collision restitution coefficient.
| void a3d::PhysicsBody::restitution | ( | float | restitution | ) |
Sets the collision restitution coefficient.
| float a3d::PhysicsBody::rollingFriction | ( | ) | const |
Returns the rolling-friction coefficient.
| void a3d::PhysicsBody::rollingFriction | ( | float | friction | ) |
Sets the rolling-friction coefficient.
| const std::shared_ptr< PhysicsShape > & a3d::PhysicsBody::shape | ( | ) | const |
Returns the collision shape retained by this body, or nullptr if no shape is assigned.
| void a3d::PhysicsBody::shape | ( | const std::shared_ptr< PhysicsShape > & | shape | ) |
Replaces the collision shape retained by this body; nullptr removes it.
A non-null shape assigned through this function is treated as explicit and is not automatically replaced when the owning Node's Mesh changes.
| std::logic_error | if shape does not support this body's type, or if collision geometry must be created and its source has expired or cannot produce a valid collision shape. |
| std::invalid_argument | if shape is derived from a Mesh with no elements. |
| float a3d::PhysicsBody::spinningFriction | ( | ) | const |
Returns the spinning-friction coefficient.
| void a3d::PhysicsBody::spinningFriction | ( | float | friction | ) |
Sets the spinning-friction coefficient.
|
static |
Creates a shape-less static body.
|
static |
Creates a static body using shape.
| std::logic_error | if shape is incompatible with a static body, or if collision geometry must be created and its source has expired or cannot produce a valid collision shape. |
| std::invalid_argument | if shape is derived from a Mesh with no elements. |
| math::vec3 a3d::PhysicsBody::totalForce | ( | ) | const |
Returns the accumulated force for the current simulation step.
| math::vec3 a3d::PhysicsBody::totalTorque | ( | ) | const |
Returns the accumulated torque for the current simulation step.
| Type a3d::PhysicsBody::type | ( | ) | const |
Returns the body type.
| void a3d::PhysicsBody::type | ( | Type | type | ) |
Validates the requested body type.
Changing a body's type after construction is not currently supported.
| std::logic_error | if type differs from the current type. |