GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::physics::Broadphase< N > Class Template Reference

Acceleration structure for spatial queries in a simulation. More...

#include <GREM/physics/Broadphase.hpp>

Classes

struct  CollisionResult
 Result of a collision check of a shape against the entities in a broadphase. More...
struct  RaycastResult
 Result of a raycast against the objects in a broadphase. More...
struct  ShapecastResult
 Result of a shapecast against the objects in a broadphase. More...

Public Types

using value_type = typename Tree::value_type
 Value type of the container.
using reference = typename Tree::reference
 Reference type of the container.
using const_reference = typename Tree::const_reference
 Const reference type of the container.
using pointer = typename Tree::pointer
 Pointer type of the container.
using const_pointer = typename Tree::const_pointer
 Const pointer type of the container.
using size_type = typename Tree::size_type
 Size type of the container.
using difference_type = typename Tree::difference_type
 Difference type of the container.
using iterator = typename Tree::iterator
 Iterator type of the container.
using const_iterator = typename Tree::const_iterator
 Const iterator type of the container.
using local_iterator = typename Tree::local_iterator
 Local iterator type for the nodes of the container.
using const_local_iterator = typename Tree::const_local_iterator
 Const local iterator type for the nodes of the container.
using ElementsView = Subrange<iterator, iterator, SubrangeKind::SIZED>
 Non-owning view over the elements in a broadphase.
using ConstElementsView = Subrange<const_iterator, const_iterator, SubrangeKind::SIZED>
 Non-owning read-only view over the elements in a broadphase.

Public Member Functions

ElementsView getElements () noexcept
 Get a view over the elements in the broadphase.
ConstElementsView getElements () const noexcept
 Get a read-only view over the elements in the broadphase.
void clear () noexcept
 Erase all elements from the broadphase and reset it to its empty state.
void reset (const Box< N > &worldBoundingBox, Distance minEntitySizeApproximation) noexcept
 Reset the broadphase to an empty state with new world parameters.
Distance getMinEntitySizeApproximation () const noexcept
 Get the current minimum entity size approximation of the broadphase.
Box< N > getRootBox () const noexcept
 Get the current root box of the broadphase.
iterator insert (const Box< N > &boundingBox, EntityID entityID)
 Insert an entity into the broadphase.
void erase (const_iterator pos)
 Remove an entity from the broadphase.
void erase (BroadphaseID id)
 Remove an entity from the broadphase.
EntityID operator[] (LooseOrthtreeID id) const
 Get the entity with a specific handle.
template<typename Callback, typename Predicate>
auto traverseNodes (Callback &&callback, Predicate &&predicate) const
 Execute a callback function for each active node of the broadphase, including empty internal nodes.
template<typename Callback>
auto traverseNodes (Callback &&callback) const
 Execute a callback function for each active node of the broadphase, including empty internal nodes.
template<typename Callback, typename Predicate>
auto traverseEntities (Callback &&callback, Predicate &&predicate) const
 Execute a callback function for each entity in the broadphase.
template<typename Callback>
auto traverseEntities (Callback &&callback) const
 Execute a callback function for each entity in the broadphase.
bool testPoint (Position< N > point, CollisionFilter filter, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, CollisionFilterTest filterTest={}, FunctionView< bool(EntityID objectID, CollisionFilterTestResult filterTestResult)> callback=[](EntityID) -> bool { return true;}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find all objects in the broadphase that contain a given point.
bool testShape (Length1D minPenetrationDepth, ShapeView< N > shape, CollisionFilter filter, const Transformation< N > &transformation, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, const CollisionAlgorithmOptions< N > &options, CollisionFilterTest filterTest={}, FunctionView< bool(EntityID objectID, CollisionFilterTestResult filterTestResult)> callback=[](EntityID) -> bool { return true;}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find all objects in the broadphase that collide with a given shape.
bool collide (ShapeView< N > shape, CollisionFilter filter, const Transformation< N > &transformation, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, const CollisionAlgorithmOptions< N > &options, CollisionFilterTest filterTest={}, FunctionView< bool(const CollisionResult &collision)> callback=[](const CollisionResult &) -> bool { return true;}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find collisions between a shape and the objects in the broadphase.
bool raycast (const Ray< N > &ray, CollisionFilter filter, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, CollisionFilterTest filterTest={}, FunctionView< bool(const RaycastResult &hit)> callback=[](const RaycastResult &) -> bool { return true;}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find collisions between a point and the objects in the broadphase when the point is cast like a ray from a given start position towards a given direction.
Optional< RaycastResult > raycastClosestHit (const Ray< N > &ray, CollisionFilter filter, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, CollisionFilterTest filterTest={}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find the closest collision between a point and the objects in the broadphase when the point is cast like a ray from a given start position towards a given direction.
Optional< RaycastResult > raycastAnyHit (const Ray< N > &ray, CollisionFilter filter, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, CollisionFilterTest filterTest={}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find any collision between a point and the objects in the broadphase when the point is cast like a ray from a given start position towards a given direction.
bool shapecast (ConvexShapeView< N > convexShape, CollisionFilter filter, const Transformation< N > &transformation, Direction< N > direction, Distance maxDistance, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, const CollisionAlgorithmOptions< N > &options, CollisionFilterTest filterTest={}, FunctionView< bool(const ShapecastResult &hit)> callback=[](const ShapecastResult &) -> bool { return true;}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find collisions between an object of a convex shape and the objects in the broadphase when the object is cast from a given start position towards a given direction.
Optional< ShapecastResult > shapecastClosestHit (ConvexShapeView< N > convexShape, CollisionFilter filter, const Transformation< N > &transformation, Direction< N > direction, Distance maxDistance, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, const CollisionAlgorithmOptions< N > &options, CollisionFilterTest filterTest={}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find the closest collision between an object of a convex shape and the objects in the broadphase when the object is cast from a given start position towards a given direction.
Optional< ShapecastResult > shapecastAnyHit (ConvexShapeView< N > convexShape, CollisionFilter filter, const Transformation< N > &transformation, Direction< N > direction, Distance maxDistance, execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities, const CollisionAlgorithmOptions< N > &options, CollisionFilterTest filterTest={}, FunctionView< bool(EntityID objectID)> predicate=[](EntityID) -> bool { return true;}) const
 Find any collision between an object of a convex shape and the objects in the broadphase when the object is cast from a given start position towards a given direction.

Friends

template<typename Predicate>
size_type erase_if (Broadphase &c, Predicate &&predicate)
 Erase all entities that match a predicate from the broadphase.

Detailed Description

template<size_t N>
class grem::physics::Broadphase< N >

Acceleration structure for spatial queries in a simulation.

Template Parameters
Nnumber of dimensions of the world space (must be 2 or 3).

Member Typedef Documentation

◆ value_type

template<size_t N>
using grem::physics::Broadphase< N >::value_type = typename Tree::value_type

Value type of the container.

◆ reference

template<size_t N>
using grem::physics::Broadphase< N >::reference = typename Tree::reference

Reference type of the container.

◆ const_reference

template<size_t N>
using grem::physics::Broadphase< N >::const_reference = typename Tree::const_reference

Const reference type of the container.

◆ pointer

template<size_t N>
using grem::physics::Broadphase< N >::pointer = typename Tree::pointer

Pointer type of the container.

◆ const_pointer

template<size_t N>
using grem::physics::Broadphase< N >::const_pointer = typename Tree::const_pointer

Const pointer type of the container.

◆ size_type

template<size_t N>
using grem::physics::Broadphase< N >::size_type = typename Tree::size_type

Size type of the container.

◆ difference_type

template<size_t N>
using grem::physics::Broadphase< N >::difference_type = typename Tree::difference_type

Difference type of the container.

◆ iterator

template<size_t N>
using grem::physics::Broadphase< N >::iterator = typename Tree::iterator

Iterator type of the container.

◆ const_iterator

template<size_t N>
using grem::physics::Broadphase< N >::const_iterator = typename Tree::const_iterator

Const iterator type of the container.

◆ local_iterator

template<size_t N>
using grem::physics::Broadphase< N >::local_iterator = typename Tree::local_iterator

Local iterator type for the nodes of the container.

◆ const_local_iterator

template<size_t N>
using grem::physics::Broadphase< N >::const_local_iterator = typename Tree::const_local_iterator

Const local iterator type for the nodes of the container.

◆ ElementsView

template<size_t N>
using grem::physics::Broadphase< N >::ElementsView = Subrange<iterator, iterator, SubrangeKind::SIZED>

Non-owning view over the elements in a broadphase.

◆ ConstElementsView

template<size_t N>
using grem::physics::Broadphase< N >::ConstElementsView = Subrange<const_iterator, const_iterator, SubrangeKind::SIZED>

Non-owning read-only view over the elements in a broadphase.

Member Function Documentation

◆ getElements() [1/2]

template<size_t N>
ElementsView grem::physics::Broadphase< N >::getElements ( )
inlinenodiscardnoexcept

Get a view over the elements in the broadphase.

Returns
a view over the elements.
Note
The element order is unspecified.

◆ getElements() [2/2]

template<size_t N>
ConstElementsView grem::physics::Broadphase< N >::getElements ( ) const
inlinenodiscardnoexcept

Get a read-only view over the elements in the broadphase.

Returns
a read-only view over the elements.
Note
The element order is unspecified.

◆ clear()

template<size_t N>
void grem::physics::Broadphase< N >::clear ( )
inlinenoexcept

Erase all elements from the broadphase and reset it to its empty state.

◆ reset()

template<size_t N>
void grem::physics::Broadphase< N >::reset ( const Box< N > & worldBoundingBox,
Distance minEntitySizeApproximation )
inlinenoexcept

Reset the broadphase to an empty state with new world parameters.

Parameters
worldBoundingBoxtotal bounding box of the entities that will be inserted.
minEntitySizeApproximationapproximation of the minimum width of the entities that will be inserted.

◆ getMinEntitySizeApproximation()

template<size_t N>
Distance grem::physics::Broadphase< N >::getMinEntitySizeApproximation ( ) const
inlinenodiscardnoexcept

Get the current minimum entity size approximation of the broadphase.

Returns
the minimum entity size approximation.

◆ getRootBox()

template<size_t N>
Box< N > grem::physics::Broadphase< N >::getRootBox ( ) const
inlinenodiscardnoexcept

Get the current root box of the broadphase.

Returns
the root box of the broadphase.

◆ insert()

template<size_t N>
iterator grem::physics::Broadphase< N >::insert ( const Box< N > & boundingBox,
EntityID entityID )
inline

Insert an entity into the broadphase.

Parameters
boundingBoxaxis-aligned bounding box of the entity.
entityIDhandle to the entity.
Returns
an iterator to the newly inserted entity.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ erase() [1/2]

template<size_t N>
void grem::physics::Broadphase< N >::erase ( const_iterator pos)
inline

Remove an entity from the broadphase.

Parameters
positerator to the entity to remove. Must be valid.
See also
clear()

◆ erase() [2/2]

template<size_t N>
void grem::physics::Broadphase< N >::erase ( BroadphaseID id)
inline

Remove an entity from the broadphase.

Parameters
idhandle to the entity to remove. Must be valid.
See also
clear()

◆ operator[]()

template<size_t N>
EntityID grem::physics::Broadphase< N >::operator[] ( LooseOrthtreeID id) const
inlinenodiscard

Get the entity with a specific handle.

Parameters
idhandle to the entity to get. Must be valid.
Returns
the handle of the entity with the given broadphase handle.

◆ traverseNodes() [1/2]

template<size_t N>
template<typename Callback, typename Predicate>
auto grem::physics::Broadphase< N >::traverseNodes ( Callback && callback,
Predicate && predicate ) const
inline

Execute a callback function for each active node of the broadphase, including empty internal nodes.

Parameters
callbackfunction to execute, which should accept the following parameters (though they don't need to be used):
  • const Box<N>& boundingBox: an axis-aligned box spanning all entities in the node.
  • const_local_iterator first: a read-only iterator to the beginning of the range of entities in the node.
  • const_local_iterator last: a read-only iterator to one past the end of the range of entities in the node.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
predicatecondition that must be met in order to traverse deeper into the hierarchy. Must return bool and accept the following parameter:
  • const Box<N>& boundingBox: an axis-aligned box spanning all entities in the branch.
The predicate function should return a bool that is true if the next node should be traversed, or false if the branch should be ignored.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseEntities()

◆ traverseNodes() [2/2]

template<size_t N>
template<typename Callback>
auto grem::physics::Broadphase< N >::traverseNodes ( Callback && callback) const
inline

Execute a callback function for each active node of the broadphase, including empty internal nodes.

Parameters
callbackfunction to execute, which should accept the following parameters (though they don't need to be used):
  • const Box<N>& boundingBox: an axis-aligned box spanning all entities in the node.
  • const_local_iterator first: a read-only iterator to the beginning of the range of entities in the node.
  • const_local_iterator last: a read-only iterator to one past the end of the range of entities in the node.
The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseEntities()

◆ traverseEntities() [1/2]

template<size_t N>
template<typename Callback, typename Predicate>
auto grem::physics::Broadphase< N >::traverseEntities ( Callback && callback,
Predicate && predicate ) const
inline

Execute a callback function for each entity in the broadphase.

Parameters
callbackfunction to execute, which should accept the following parameter: The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
predicatecondition that must be met in order to traverse deeper into the hierarchy. Must return bool and accept the following parameter:
  • const Box<N>& boundingBox: an axis-aligned box spanning all entities in the branch.
The predicate function should return a bool that is true if the next node should be traversed, or false if the branch should be ignored.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()

◆ traverseEntities() [2/2]

template<size_t N>
template<typename Callback>
auto grem::physics::Broadphase< N >::traverseEntities ( Callback && callback) const
inline

Execute a callback function for each entity in the broadphase.

Parameters
callbackfunction to execute, which should accept the following parameter: The callback function should return either void or a bool that specifies whether to stop the traversal or not. A value of true means to stop and return early, while a value of false means to continue traversing.
Returns
void if the callback function returns void, true if the callback returns bool and exited early, false if the callback function returns bool but didn't exit early.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Warning
Although it is sematically const, this function is not thread-safe since it mutates an internal memory cache. Exclusive access is therefore required for safety.
See also
traverseNodes()

◆ testPoint()

template<size_t N>
bool grem::physics::Broadphase< N >::testPoint ( Position< N > point,
CollisionFilter filter,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
CollisionFilterTest filterTest = {},
FunctionView< bool(EntityID objectID, CollisionFilterTestResult filterTestResult)> callback = [](EntityID) -> bool { return true;},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true;} ) const

Find all objects in the broadphase that contain a given point.

Parameters
pointworld-space point to check.
filtercollision filter of the point.
entitiesobjects to collide against.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
callbackfunction to execute for each colliding object that passed the filter test. Returns a bool that specifies whether to stop searching or not. A value of true means to stop and return early, while a value of false means to continue processing the rest of the collisions. Note that at the end of the search, testPoint() will return true if at least one collision was found, regardless of what the callback returned.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
true if at least one collision was found, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ testShape()

template<size_t N>
bool grem::physics::Broadphase< N >::testShape ( Length1D minPenetrationDepth,
ShapeView< N > shape,
CollisionFilter filter,
const Transformation< N > & transformation,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
const CollisionAlgorithmOptions< N > & options,
CollisionFilterTest filterTest = {},
FunctionView< bool(EntityID objectID, CollisionFilterTestResult filterTestResult)> callback = [](EntityID) -> bool { return true;},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true;} ) const

Find all objects in the broadphase that collide with a given shape.

Parameters
minPenetrationDepthminimum penetration depth for a contact to be considered to be colliding.
shapeshape to collide.
filtercollision filter of the shape.
transformationworld-space transformation of the shape.
entitiesobjects to collide against.
optionscollision algorithm options, see CollisionAlgorithmOptions. Should usually be simulation.resources.getResource<SimulationOptions<N>>().collisionAlgorithmOptions.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
callbackfunction to execute for each colliding object that passed the filter test. Returns a bool that specifies whether to stop searching or not. A value of true means to stop and return early, while a value of false means to continue processing the rest of the collisions. Note that at the end of the search, testShape() will return true if at least one collision was found, regardless of what the callback returned.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
true if at least one collision was found, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ collide()

template<size_t N>
bool grem::physics::Broadphase< N >::collide ( ShapeView< N > shape,
CollisionFilter filter,
const Transformation< N > & transformation,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
const CollisionAlgorithmOptions< N > & options,
CollisionFilterTest filterTest = {},
FunctionView< bool(const CollisionResult &collision)> callback = [](const CollisionResult &) -> bool { return true;},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true;} ) const

Find collisions between a shape and the objects in the broadphase.

Parameters
shapeshape to collide.
filtercollision filter of the shape.
transformationworld-space transformation of the shape.
entitiesobjects to collide against.
optionscollision algorithm options, see CollisionAlgorithmOptions. Should usually be simulation.resources.getResource<SimulationOptions<N>>().collisionAlgorithmOptions.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
callbackfunction to execute for each colliding object that passed the filter test. Returns a bool that specifies whether to stop searching or not. A value of true means to stop and return early, while a value of false means to continue processing the rest of the collisions. Note that at the end of the search, collide() will return true if at least one collision was found, regardless of what the callback returned.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
true if at least one collision was found, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ raycast()

template<size_t N>
bool grem::physics::Broadphase< N >::raycast ( const Ray< N > & ray,
CollisionFilter filter,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
CollisionFilterTest filterTest = {},
FunctionView< bool(const RaycastResult &hit)> callback = [](const RaycastResult &) -> bool { return true;},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true;} ) const

Find collisions between a point and the objects in the broadphase when the point is cast like a ray from a given start position towards a given direction.

Parameters
rayray to cast.
filtercollision filter of the ray.
entitiesobjects to collide against.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
callbackfunction to execute for each colliding object that passed the filter test. Returns a bool that specifies whether to stop searching or not. A value of true means to stop and return early, while a value of false means to continue processing the rest of the collisions. Note that at the end of the search, raycast() will return true if at least one collision was found, regardless of what the callback returned.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
true if at least one collision was found, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ raycastClosestHit()

template<size_t N>
Optional< RaycastResult > grem::physics::Broadphase< N >::raycastClosestHit ( const Ray< N > & ray,
CollisionFilter filter,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
CollisionFilterTest filterTest = {},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true; } ) const
inlinenodiscard

Find the closest collision between a point and the objects in the broadphase when the point is cast like a ray from a given start position towards a given direction.

Parameters
rayray to cast.
filtercollision filter of the ray.
entitiesobjects to collide against.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
the closest found collision that passed the filter test, or an empty optional if no collisions were found that passed the test.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the predicate function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ raycastAnyHit()

template<size_t N>
Optional< RaycastResult > grem::physics::Broadphase< N >::raycastAnyHit ( const Ray< N > & ray,
CollisionFilter filter,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
CollisionFilterTest filterTest = {},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true; } ) const
inlinenodiscard

Find any collision between a point and the objects in the broadphase when the point is cast like a ray from a given start position towards a given direction.

Parameters
rayray to cast.
filtercollision filter of the ray.
entitiesobjects to collide against.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
the first found collision that passed the filter test, or an empty optional if no collisions were found that passed the test.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the predicate function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ shapecast()

template<size_t N>
bool grem::physics::Broadphase< N >::shapecast ( ConvexShapeView< N > convexShape,
CollisionFilter filter,
const Transformation< N > & transformation,
Direction< N > direction,
Distance maxDistance,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
const CollisionAlgorithmOptions< N > & options,
CollisionFilterTest filterTest = {},
FunctionView< bool(const ShapecastResult &hit)> callback = [](const ShapecastResult &) -> bool { return true;},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true;} ) const

Find collisions between an object of a convex shape and the objects in the broadphase when the object is cast from a given start position towards a given direction.

Parameters
convexShapeconvex shape to cast.
filtercollision filter of the shape.
transformationworld-space transformation of the shape.
directiondirection to cast in.
maxDistancemaximum hit distance. Must be non-negative.
entitiesobjects to collide against.
optionscollision algorithm options, see CollisionAlgorithmOptions. Should usually be simulation.resources.getResource<SimulationOptions<N>>().collisionAlgorithmOptions.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
callbackfunction to execute for each colliding object that passed the filter test. Returns a bool that specifies whether to stop searching or not. A value of true means to stop and return early, while a value of false means to continue processing the rest of the collisions. Note that at the end of the search, shapecast() will return true if at least one collision was found, regardless of what the callback returned.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
true if at least one collision was found, false otherwise.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the callback or predicate functions.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ shapecastClosestHit()

template<size_t N>
Optional< ShapecastResult > grem::physics::Broadphase< N >::shapecastClosestHit ( ConvexShapeView< N > convexShape,
CollisionFilter filter,
const Transformation< N > & transformation,
Direction< N > direction,
Distance maxDistance,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
const CollisionAlgorithmOptions< N > & options,
CollisionFilterTest filterTest = {},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true; } ) const
inlinenodiscard

Find the closest collision between an object of a convex shape and the objects in the broadphase when the object is cast from a given start position towards a given direction.

Parameters
convexShapeconvex shape to cast.
filtercollision filter of the shape.
transformationworld-space transformation of the shape.
directiondirection to cast in.
maxDistancemaximum hit distance. Must be non-negative.
entitiesobjects to collide against.
optionscollision algorithm options, see CollisionAlgorithmOptions. Should usually be simulation.resources.getResource<SimulationOptions<N>>().collisionAlgorithmOptions.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
the closest found collision that passed the filter test, or an empty optional if no collisions were found that passed the test.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the predicate function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ shapecastAnyHit()

template<size_t N>
Optional< ShapecastResult > grem::physics::Broadphase< N >::shapecastAnyHit ( ConvexShapeView< N > convexShape,
CollisionFilter filter,
const Transformation< N > & transformation,
Direction< N > direction,
Distance maxDistance,
execution::Entities< const Position< N >, const Orientation< N >, const Scale< N >, const Collider< N >, const ObjectBounds< N > > entities,
const CollisionAlgorithmOptions< N > & options,
CollisionFilterTest filterTest = {},
FunctionView< bool(EntityID objectID)> predicate = [](EntityID) -> bool { return true; } ) const
inlinenodiscard

Find any collision between an object of a convex shape and the objects in the broadphase when the object is cast from a given start position towards a given direction.

Parameters
convexShapeconvex shape to cast.
filtercollision filter of the shape.
transformationworld-space transformation of the shape.
directiondirection to cast in.
maxDistancemaximum hit distance. Must be non-negative.
entitiesobjects to collide against.
optionscollision algorithm options, see CollisionAlgorithmOptions. Should usually be simulation.resources.getResource<SimulationOptions<N>>().collisionAlgorithmOptions.
filterTesttest that potential colliders must pass in order to be considered for collision. The default test passes if the filters of both colliders want either collision or response (or both) on any layer(s). To limit to only colliders that want response (and skip trigger volumes, etc.), use CollisionFilterTest::RESPONSE.
predicatecondition that must be met in order to consider an entity for collision. Must return bool and accept the following parameter:
  • EntityID objectID: an entity handle to the candidate object.
Returns
the first found collision that passed the filter test, or an empty optional if no collisions were found that passed the test.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the predicate function.
Note
The order of traversal is unspecified, though it is guaranteed that outer nodes will be visited before their own inner nodes that they contain.
Only entities that are both in the broadphase and in the given set will be considered for collision.

◆ erase_if

template<size_t N>
template<typename Predicate>
size_type erase_if ( Broadphase< N > & c,
Predicate && predicate )
friend

Erase all entities that match a predicate from the broadphase.

Parameters
cbroadphase to erase from.
predicatecondition to check.
Returns
the number of entities that matched the predicate and were subsequently erased.
Exceptions
anyexception thrown by the predicate function.

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