Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::CollisionMesh2D Class Reference

Convex collision mesh built from 2D points. More...

#include <spk_collision_mesh_2d.hpp>

Inheritance diagram for spk::CollisionMesh2D:
Inheritance graph
Collaboration diagram for spk::CollisionMesh2D:
Collaboration graph

Public Types

using Polygon = spk::IMesh<spk::Vector2>::Polygon
 Polygon type used for collision triangles.
using EditionContract = spk::IMesh<spk::Vector2>::EditionContract
 Contract type for mesh edition notifications.
Public Types inherited from spk::IMesh< spk::Vector2 >
using Polygon
 Polygon type stored by the mesh.
using EditionContract
 Contract type returned by edition subscriptions.
using EditionJob
 Job type invoked on mesh edits.

Public Member Functions

 CollisionMesh2D ()
 Creates an empty collision mesh.
 CollisionMesh2D (const CollisionMesh2D &p_other)
 Copies another collision mesh.
CollisionMesh2Doperator= (const CollisionMesh2D &p_other)
 Copy-assigns another collision mesh.
 CollisionMesh2D (CollisionMesh2D &&p_other) noexcept
 Move-constructs a collision mesh.
CollisionMesh2Doperator= (CollisionMesh2D &&p_other) noexcept
 Move-assigns a collision mesh.
template<typename TMesh>
 CollisionMesh2D (const TMesh &p_mesh, const std::function< spk::Vector2(const typename TMesh::Vertex &)> &p_positionExtractor)
 Builds a convex collision mesh from another mesh type.
bool collideWith (const CollisionMesh2D &p_other, const Transform2D &p_selfTransform, const Transform2D &p_otherTransform) const
 Tests collision against another mesh using transform components.
bool collideWith (const spk::Vector2 &p_worldPoint, const Transform2D &p_selfTransform) const
 Tests collision with a world-space point using a transform component.
bool collideWith (const CollisionMesh2D &p_other, const spk::Matrix4x4 &p_selfTransform, const spk::Matrix4x4 &p_otherTransform) const
 Tests collision against another mesh using explicit matrices.
bool collideWith (const spk::Vector2 &p_worldPoint, const spk::Matrix4x4 &p_selfTransform) const
 Tests collision with a world-space point using a matrix.
const spk::BoundingBox2DboundingBox () const
 Returns the axis-aligned bounding box in local space.
Public Member Functions inherited from spk::IMesh< spk::Vector2 >
 IMesh ()
 Builds an empty mesh with a dynamic buffer set.
IMeshoperator= (const IMesh &p_other)
 Assigns polygon data from another mesh.
void clear ()
 Clears all polygons and notifies subscribers.
void append (const Polygon &p_shape)
 Appends a polygon and notifies subscribers.
EditionContract subscribeToEdition (const EditionJob &p_job) const
 Subscribes to mesh edition notifications.
const std::vector< spk::Vector2 > & vertices () const
 Returns the cached vertex list for all polygons.
const std::vector< Polygon > & polygons () const
 Returns the stored polygons.
const std::vector< uint32_t > & indexes () const
 Returns the cached triangle indices for the mesh.
IMeshoperator+= (const IMesh &p_other)
 Appends polygons from another mesh and notifies subscribers.
const std::shared_ptr< spk::OpenGL::BufferSetObject > & bufferSet () const
 Returns the underlying buffer set.
void synchronize () const
 Updates GPU buffers when mesh data has changed.
IMesh fuze (const IMesh &p_other) const
 Returns a new mesh by concatenating another mesh.

Protected Member Functions

void _configureBufferSet () const override
 Configures the vertex buffer layout for this mesh.

Detailed Description

Convex collision mesh built from 2D points.

Constructor & Destructor Documentation

◆ CollisionMesh2D() [1/3]

spk::CollisionMesh2D::CollisionMesh2D ( const CollisionMesh2D & p_other)

Copies another collision mesh.

Parameters
p_otherMesh to copy from.
Here is the call graph for this function:

◆ CollisionMesh2D() [2/3]

spk::CollisionMesh2D::CollisionMesh2D ( CollisionMesh2D && p_other)
noexcept

Move-constructs a collision mesh.

Parameters
p_otherMesh to move from.
Here is the call graph for this function:

◆ CollisionMesh2D() [3/3]

template<typename TMesh>
spk::CollisionMesh2D::CollisionMesh2D ( const TMesh & p_mesh,
const std::function< spk::Vector2(const typename TMesh::Vertex &)> & p_positionExtractor )
inlineexplicit

Builds a convex collision mesh from another mesh type.

Template Parameters
TMeshMesh type providing polygons() and Vertex.
Parameters
p_meshSource mesh to sample.
p_positionExtractorFunction returning the world position of a vertex.
Here is the call graph for this function:

Member Function Documentation

◆ _configureBufferSet()

void spk::CollisionMesh2D::_configureBufferSet ( ) const
inlineoverrideprotectedvirtual

Configures the vertex buffer layout for this mesh.

Implements spk::IMesh< spk::Vector2 >.

Here is the call graph for this function:

◆ boundingBox()

const spk::BoundingBox2D & spk::CollisionMesh2D::boundingBox ( ) const

Returns the axis-aligned bounding box in local space.

Returns
Cached bounding box.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ collideWith() [1/4]

bool spk::CollisionMesh2D::collideWith ( const CollisionMesh2D & p_other,
const spk::Matrix4x4 & p_selfTransform,
const spk::Matrix4x4 & p_otherTransform ) const

Tests collision against another mesh using explicit matrices.

Parameters
p_otherOther mesh to collide with.
p_selfTransformMatrix for this mesh.
p_otherTransformMatrix for the other mesh.
Returns
True if the meshes overlap.
Here is the call graph for this function:

◆ collideWith() [2/4]

bool spk::CollisionMesh2D::collideWith ( const CollisionMesh2D & p_other,
const Transform2D & p_selfTransform,
const Transform2D & p_otherTransform ) const

Tests collision against another mesh using transform components.

Parameters
p_otherOther mesh to collide with.
p_selfTransformTransform applied to this mesh.
p_otherTransformTransform applied to the other mesh.
Returns
True if the meshes overlap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ collideWith() [3/4]

bool spk::CollisionMesh2D::collideWith ( const spk::Vector2 & p_worldPoint,
const spk::Matrix4x4 & p_selfTransform ) const

Tests collision with a world-space point using a matrix.

Parameters
p_worldPointPoint in world space.
p_selfTransformMatrix for this mesh.
Returns
True if the point is inside the mesh.
Here is the call graph for this function:

◆ collideWith() [4/4]

bool spk::CollisionMesh2D::collideWith ( const spk::Vector2 & p_worldPoint,
const Transform2D & p_selfTransform ) const

Tests collision with a world-space point using a transform component.

Parameters
p_worldPointPoint in world space.
p_selfTransformTransform applied to this mesh.
Returns
True if the point is inside the mesh.
Here is the call graph for this function:

◆ operator=() [1/2]

CollisionMesh2D & spk::CollisionMesh2D::operator= ( CollisionMesh2D && p_other)
noexcept

Move-assigns a collision mesh.

Parameters
p_otherMesh to move from.
Returns
Reference to this mesh.
Here is the call graph for this function:

◆ operator=() [2/2]

CollisionMesh2D & spk::CollisionMesh2D::operator= ( const CollisionMesh2D & p_other)

Copy-assigns another collision mesh.

Parameters
p_otherMesh to copy from.
Returns
Reference to this mesh.
Here is the call graph for this function:

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