Avara3D 0.2.0
C++ API reference
a3d::PhysicsShape Class Reference

Describes collision geometry used by one or more PhysicsBody objects. More...

#include <a3d/physics/shape/PhysicsShape.h>

Inheritance diagram for a3d::PhysicsShape:
[legend]

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...
 
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< PhysicsShapeBoundingBoxShape (const std::shared_ptr< Mesh > &mesh)
 Creates a bounding-box collision shape derived from mesh. More...
 
static std::shared_ptr< PhysicsShapeBoundingBoxShape (const std::shared_ptr< Node > &node)
 Creates a bounding-box collision shape from mesh geometry in the node hierarchy. More...
 
static std::shared_ptr< PhysicsShapeConvexHullShape (const std::shared_ptr< Mesh > &mesh)
 Creates a convex-hull collision shape derived from mesh. More...
 
static std::shared_ptr< PhysicsShapeConvexHullShape (const std::shared_ptr< Node > &node)
 Creates a convex-hull collision shape from mesh geometry in the node hierarchy. More...
 
static std::shared_ptr< PhysicsShapeConcavePolyhedronShape (const std::shared_ptr< Mesh > &mesh)
 Creates a concave-polyhedron collision shape derived from mesh. More...
 
static std::shared_ptr< PhysicsShapeConcavePolyhedronShape (const std::shared_ptr< Node > &node)
 Creates a concave-polyhedron collision shape from mesh geometry in the node hierarchy. More...
 

Detailed Description

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.

Definition at line 37 of file PhysicsShape.h.

Member Typedef Documentation

◆ Source

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 52 of file PhysicsShape.h.

Member Enumeration Documentation

◆ Type

enum class a3d::PhysicsShape::Type : uint8_t
strong

Collision-geometry representation requested for a PhysicsShape.

Enumerator
Primitive 

Reserved for internal use; public callers should not supply this value. This API is expected to change.

BoundingBox 

Bounding-box collision geometry derived from the source geometry.

ConvexHull 

Convex-hull collision geometry derived from the source geometry.

ConcavePolyhedron 

Potentially concave polygonal collision geometry derived from the source geometry.

Definition at line 43 of file PhysicsShape.h.

Constructor & Destructor Documentation

◆ PhysicsShape() [1/2]

a3d::PhysicsShape::PhysicsShape ( Type  type,
const std::shared_ptr< Mesh > &  mesh 
)

Creates a PhysicsShape of type derived from mesh.

The source Mesh is retained weakly and must be non-null.

◆ PhysicsShape() [2/2]

a3d::PhysicsShape::PhysicsShape ( Type  type,
const std::shared_ptr< Node > &  node 
)

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.

Member Function Documentation

◆ BoundingBoxShape() [1/2]

static std::shared_ptr< PhysicsShape > a3d::PhysicsShape::BoundingBoxShape ( const std::shared_ptr< Mesh > &  mesh)
static

Creates a bounding-box collision shape derived from mesh.

◆ BoundingBoxShape() [2/2]

static std::shared_ptr< PhysicsShape > a3d::PhysicsShape::BoundingBoxShape ( const std::shared_ptr< Node > &  node)
static

Creates a bounding-box collision shape from mesh geometry in the node hierarchy.

◆ ConcavePolyhedronShape() [1/2]

static std::shared_ptr< PhysicsShape > a3d::PhysicsShape::ConcavePolyhedronShape ( const std::shared_ptr< Mesh > &  mesh)
static

Creates a concave-polyhedron collision shape derived from mesh.

◆ ConcavePolyhedronShape() [2/2]

static std::shared_ptr< PhysicsShape > a3d::PhysicsShape::ConcavePolyhedronShape ( const std::shared_ptr< Node > &  node)
static

Creates a concave-polyhedron collision shape from mesh geometry in the node hierarchy.

◆ ConvexHullShape() [1/2]

static std::shared_ptr< PhysicsShape > a3d::PhysicsShape::ConvexHullShape ( const std::shared_ptr< Mesh > &  mesh)
static

Creates a convex-hull collision shape derived from mesh.

◆ ConvexHullShape() [2/2]

static std::shared_ptr< PhysicsShape > a3d::PhysicsShape::ConvexHullShape ( const std::shared_ptr< Node > &  node)
static

Creates a convex-hull collision shape from mesh geometry in the node hierarchy.

◆ source()

Source a3d::PhysicsShape::source ( ) const

Returns the weak Mesh or Node source, or std::monostate for a source-less primitive shape.

◆ type() [1/2]

virtual Type a3d::PhysicsShape::type ( ) const
virtual

◆ type() [2/2]

virtual void a3d::PhysicsShape::type ( Type  type)
virtual

Validates the requested collision-geometry type.

Changing a PhysicsShape type after construction is not currently supported.

Exceptions
std::logic_errorif type differs from the current type.

Reimplemented in a3d::BoxPhysicsShape, a3d::CapsulePhysicsShape, a3d::ConePhysicsShape, a3d::CylinderPhysicsShape, a3d::FinitePlanePhysicsShape, a3d::InfinitePlanePhysicsShape, and a3d::SpherePhysicsShape.


The documentation for this class was generated from the following file: