Describes collision geometry used by one or more PhysicsBody objects. More...
#include <a3d/physics/shape/PhysicsShape.h>
Public Types | |
| enum class | Type : uint8_t { Primitive , BoundingBox , ConvexHull , ConcavePolyhedron } |
| Collision-geometry representation requested for a PhysicsShape. More... | |
| using | Source = std::variant< std::monostate, std::weak_ptr< Mesh >, std::weak_ptr< Node > > |
| Weak source object used to derive collision geometry, or no source for primitive shapes. More... | |
Public Member Functions | |
| PhysicsShape (Type type, const std::shared_ptr< Mesh > &mesh) | |
Creates a PhysicsShape of type derived from mesh. More... | |
| PhysicsShape (Type type, const std::shared_ptr< Node > &node) | |
Creates a PhysicsShape of type from mesh geometry in the node hierarchy. More... | |
| virtual Type | type () const |
| Returns the collision-geometry type. More... | |
| virtual void | type (Type type) |
| Validates the requested collision-geometry type. More... | |
| float | margin () const |
| Returns the collision margin used by this shape. More... | |
| void | margin (float margin) |
| Sets a uniform collision margin for this shape. More... | |
| Source | source () const |
| Returns the weak Mesh or Node source, or std::monostate for a source-less primitive shape. More... | |
Static Public Member Functions | |
| static std::shared_ptr< PhysicsShape > | BoundingBoxShape (const std::shared_ptr< Mesh > &mesh) |
Creates a bounding-box collision shape derived from mesh. More... | |
| static std::shared_ptr< PhysicsShape > | BoundingBoxShape (const std::shared_ptr< Node > &node) |
Creates a bounding-box collision shape from mesh geometry in the node hierarchy. More... | |
| static std::shared_ptr< PhysicsShape > | ConvexHullShape (const std::shared_ptr< Mesh > &mesh) |
Creates a convex-hull collision shape derived from mesh. More... | |
| static std::shared_ptr< PhysicsShape > | ConvexHullShape (const std::shared_ptr< Node > &node) |
Creates a convex-hull collision shape from mesh geometry in the node hierarchy. More... | |
| static std::shared_ptr< PhysicsShape > | ConcavePolyhedronShape (const std::shared_ptr< Mesh > &mesh) |
Creates a concave-polyhedron collision shape derived from mesh. More... | |
| static std::shared_ptr< PhysicsShape > | ConcavePolyhedronShape (const std::shared_ptr< Node > &node) |
Creates a concave-polyhedron collision shape from mesh geometry in the node hierarchy. More... | |
Describes collision geometry used by one or more PhysicsBody objects.
A PhysicsShape may derive its collision geometry from a Mesh, from the mesh hierarchy beneath a Node, or from a specialized primitive PhysicsShape subclass. Mesh and Node sources are retained weakly, so constructing a shape does not extend the lifetime of its source object. The source and any mesh geometry used to build the collision shape must remain alive for as long as the PhysicsShape is in use.
Supported collision shapes expose a configurable collision margin used for collision detection and contact generation. The effective default margin is shape-dependent. Changing the margin updates existing PhysicsBody objects without regenerating the source geometry.
Definition at line 43 of file PhysicsShape.h.
| using a3d::PhysicsShape::Source = std::variant<std::monostate, std::weak_ptr<Mesh>, std::weak_ptr<Node> > |
Weak source object used to derive collision geometry, or no source for primitive shapes.
Definition at line 58 of file PhysicsShape.h.
|
strong |
Collision-geometry representation requested for a PhysicsShape.
Definition at line 49 of file PhysicsShape.h.
Creates a PhysicsShape of type derived from mesh.
The source Mesh is retained weakly and must be non-null.
Creates a PhysicsShape of type from mesh geometry in the node hierarchy.
The source Node is retained weakly and must be non-null. Descendant mesh geometry is included using the descendants' local transforms.
|
static |
Creates a bounding-box collision shape derived from mesh.
|
static |
Creates a bounding-box collision shape from mesh geometry in the node hierarchy.
|
static |
Creates a concave-polyhedron collision shape derived from mesh.
|
static |
Creates a concave-polyhedron collision shape from mesh geometry in the node hierarchy.
|
static |
Creates a convex-hull collision shape derived from mesh.
|
static |
Creates a convex-hull collision shape from mesh geometry in the node hierarchy.
| float a3d::PhysicsShape::margin | ( | ) | const |
Returns the collision margin used by this shape.
If no explicit margin has been set, the effective margin is obtained from the existing collision geometry. Compound collision geometry must use a common margin for this function to return a value.
| std::logic_error | if this shape does not support a configurable collision margin, if collision geometry has not yet been created and no explicit margin has been set, or if the collision components do not use a common margin. |
| void a3d::PhysicsShape::margin | ( | float | margin | ) |
Sets a uniform collision margin for this shape.
The exact geometric effect of the margin depends on the collision-shape representation. Existing PhysicsBody objects sharing this shape are updated immediately without regenerating the source geometry.
InfinitePlanePhysicsShape, SpherePhysicsShape, and CapsulePhysicsShape do not support a configurable collision margin.
| std::logic_error | if this shape does not support a configurable collision margin. |
| std::invalid_argument | if margin is negative or non-finite. |
| Source a3d::PhysicsShape::source | ( | ) | const |
|
virtual |
Returns the collision-geometry type.
Reimplemented in a3d::BoxPhysicsShape, a3d::CapsulePhysicsShape, a3d::ConePhysicsShape, a3d::CylinderPhysicsShape, a3d::FinitePlanePhysicsShape, a3d::InfinitePlanePhysicsShape, and a3d::SpherePhysicsShape.
|
virtual |
Validates the requested collision-geometry type.
Changing a PhysicsShape type after construction is not currently supported.
| std::logic_error | if type differs from the current type. |
Reimplemented in a3d::BoxPhysicsShape, a3d::CapsulePhysicsShape, a3d::ConePhysicsShape, a3d::CylinderPhysicsShape, a3d::FinitePlanePhysicsShape, a3d::InfinitePlanePhysicsShape, and a3d::SpherePhysicsShape.