4#ifndef GREM_PHYSICS_BROADPHASE_HPP
5#define GREM_PHYSICS_BROADPHASE_HPP
47 using LooseOrthtreeID::operator==;
48 using LooseOrthtreeID::operator bool;
122 tree.reset(worldBoundingBox.in(
Box<N>::UNIT), minEntitySizeApproximation.in(Distance::UNIT));
131 return tree.getMinOrthantSize() * Distance::UNIT;
238 template <
typename Callback,
typename Predicate>
282 template <
typename Callback>
284 return traverseNodes(std::forward<Callback>(callback), [](
const Box<N>&) ->
bool {
return true; });
327 template <
typename Callback,
typename Predicate>
329 return tree.traverseElements(std::forward<Callback>(callback),
364 template <
typename Callback>
526 FunctionView<bool(
const CollisionResult& collision)> callback = [](
const CollisionResult&) ->
bool {
return true; },
645 ray, filter, entities, filterTest,
646 [&](
const RaycastResult& hit) ->
bool {
647 if (hit.distance == 0) {
651 if (!result || hit.distance < result->distance) {
698 ray, filter, entities, filterTest,
699 [&](
const RaycastResult& hit) ->
bool {
839 convexShape, filter, transformation, direction, maxDistance, entities, options, filterTest,
840 [&](
const ShapecastResult& hit) ->
bool {
841 if (hit.distance == 0) {
845 if (!result || hit.distance < result->distance) {
900 convexShape, filter, transformation, direction, maxDistance, entities, options, filterTest,
901 [&](
const ShapecastResult& hit) ->
bool {
920 template <
typename Predicate>
922 return erase_if(c.tree, std::forward<Predicate>(predicate));
Definition FunctionView.hpp:29
Opaque handle to an element in a LooseOrthtree.
Definition LooseOrthtree.hpp:32
constexpr LooseOrthtreeID() noexcept=default
Orthtree-based space subdivision structure, optimized for intersection queries between axis-aligned b...
Definition LooseOrthtree.hpp:65
const EntityID & const_reference
Definition LooseOrthtree.hpp:71
size_t size_type
Definition LooseOrthtree.hpp:74
EntityID & reference
Definition LooseOrthtree.hpp:70
LocalIterator< true > const_local_iterator
Definition LooseOrthtree.hpp:215
EntityID value_type
Definition LooseOrthtree.hpp:69
Iterator< false > iterator
Iterator type of the container.
Definition LooseOrthtree.hpp:212
const EntityID * const_pointer
Definition LooseOrthtree.hpp:73
LocalIterator< false > local_iterator
Definition LooseOrthtree.hpp:214
EntityID * pointer
Definition LooseOrthtree.hpp:72
Iterator< true > const_iterator
Const iterator type of the container.
Definition LooseOrthtree.hpp:213
ptrdiff_t difference_type
Definition LooseOrthtree.hpp:75
Optional value type that holds either a value or no value.
Definition Optional.hpp:58
Definition Subrange.hpp:88
View of entities in an EntityRegistry that have all of the required components and none of the exclud...
Definition EntityRegistry.hpp:815
Acceleration structure for spatial queries in a simulation.
Definition Broadphase.hpp:57
typename Tree::local_iterator local_iterator
Local iterator type for the nodes of the container.
Definition Broadphase.hpp:71
typename Tree::size_type size_type
Size type of the container.
Definition Broadphase.hpp:67
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
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
auto traverseNodes(Callback &&callback, Predicate &&predicate) const
Execute a callback function for each active node of the broadphase, including empty internal nodes.
Definition Broadphase.hpp:239
Subrange< iterator, iterator, SubrangeKind::SIZED > ElementsView
Non-owning view over the elements in a broadphase.
Definition Broadphase.hpp:77
Distance getMinEntitySizeApproximation() const noexcept
Get the current minimum entity size approximation of the broadphase.
Definition Broadphase.hpp:130
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 l...
Definition Broadphase.hpp:640
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 ra...
Definition Broadphase.hpp:693
auto traverseEntities(Callback &&callback) const
Execute a callback function for each entity in the broadphase.
Definition Broadphase.hpp:365
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
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
typename Tree::iterator iterator
Iterator type of the container.
Definition Broadphase.hpp:69
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 obj...
Definition Broadphase.hpp:893
Subrange< const_iterator, const_iterator, SubrangeKind::SIZED > ConstElementsView
Non-owning read-only view over the elements in a broadphase.
Definition Broadphase.hpp:82
iterator insert(const Box< N > &boundingBox, EntityID entityID)
Insert an entity into the broadphase.
Definition Broadphase.hpp:155
auto traverseEntities(Callback &&callback, Predicate &&predicate) const
Execute a callback function for each entity in the broadphase.
Definition Broadphase.hpp:328
typename Tree::const_reference const_reference
Const reference type of the container.
Definition Broadphase.hpp:64
typename Tree::difference_type difference_type
Difference type of the container.
Definition Broadphase.hpp:68
ElementsView getElements() noexcept
Get a view over the elements in the broadphase.
Definition Broadphase.hpp:91
void clear() noexcept
Erase all elements from the broadphase and reset it to its empty state.
Definition Broadphase.hpp:109
Box< N > getRootBox() const noexcept
Get the current root box of the broadphase.
Definition Broadphase.hpp:139
typename Tree::const_pointer const_pointer
Const pointer type of the container.
Definition Broadphase.hpp:66
void reset(const Box< N > &worldBoundingBox, Distance minEntitySizeApproximation) noexcept
Reset the broadphase to an empty state with new world parameters.
Definition Broadphase.hpp:121
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...
Definition Broadphase.hpp:832
ConstElementsView getElements() const noexcept
Get a read-only view over the elements in the broadphase.
Definition Broadphase.hpp:102
typename Tree::reference reference
Reference type of the container.
Definition Broadphase.hpp:63
auto traverseNodes(Callback &&callback) const
Execute a callback function for each active node of the broadphase, including empty internal nodes.
Definition Broadphase.hpp:283
typename Tree::const_local_iterator const_local_iterator
Const local iterator type for the nodes of the container.
Definition Broadphase.hpp:72
typename Tree::value_type value_type
Value type of the container.
Definition Broadphase.hpp:62
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
EntityID operator[](LooseOrthtreeID id) const
Get the entity with a specific handle.
Definition Broadphase.hpp:188
friend size_type erase_if(Broadphase &c, Predicate &&predicate)
Erase all entities that match a predicate from the broadphase.
Definition Broadphase.hpp:921
void erase(BroadphaseID id)
Remove an entity from the broadphase.
Definition Broadphase.hpp:177
typename Tree::const_iterator const_iterator
Const iterator type of the container.
Definition Broadphase.hpp:70
void erase(const_iterator pos)
Remove an entity from the broadphase.
Definition Broadphase.hpp:166
View of a generic convex shape.
Definition Shape.hpp:3147
View of a generic shape.
Definition Shape.hpp:2833
Concept that checks if a type is a valid shape type.
Definition Shape.hpp:1227
Definition concepts.hpp:106
Definition Broadphase.hpp:24
Length1D Distance
Scalar length quantity.
Definition quantities.hpp:4962
Length< 1 > Length1D
Relative distance/length offset in 1-dimensional space. Unit: Meters.
Definition quantities.hpp:4925
execution::EntityID EntityID
Opaque handle to a specific entity in a Simulation's EntityRegistry.
Definition EntityID.hpp:16
Broadphase< 2 > Broadphase2D
Acceleration structure for spatial queries in a 2-dimensional simulation.
Definition Broadphase.hpp:929
Quantity< N, Meters > Length
Relative distance/length offset quantity.
Definition quantities.hpp:4924
Quantity< N, Absolute< Meters > > Position
Absolute position in world space.
Definition quantities.hpp:4949
Quantity< N, Unitless > Scale
Dimensionless scale.
Definition quantities.hpp:3984
Broadphase< 3 > Broadphase3D
Acceleration structure for spatial queries in a 3-dimensional simulation.
Definition Broadphase.hpp:930
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
Description of an axis-aligned box in world space.
Definition Shape.hpp:813
static constexpr Unit UNIT
Unit.
Definition Shape.hpp:817
GREM_ALWAYS_INLINE constexpr grem::Box< N, Scalar > in(OtherUnitT unit) const noexcept
Convert this physical box to a unitless box given a desired unit.
Definition Shape.hpp:844
Opaque handle to an entity in a Broadphase.
Definition Broadphase.hpp:29
constexpr BroadphaseID(LooseOrthtree< 3, Scalar, EntityID >::const_iterator pos) noexcept
Definition Broadphase.hpp:44
constexpr BroadphaseID() noexcept=default
constexpr BroadphaseID(LooseOrthtree< 2, Scalar, EntityID >::iterator pos) noexcept
Definition Broadphase.hpp:35
constexpr BroadphaseID(LooseOrthtree< 3, Scalar, EntityID >::iterator pos) noexcept
Definition Broadphase.hpp:41
constexpr BroadphaseID(LooseOrthtree< 2, Scalar, EntityID >::const_iterator pos) noexcept
Definition Broadphase.hpp:38
Result of a collision check of a shape against the entities in a broadphase.
Definition Broadphase.hpp:467
EntityID objectID
Handle to the object that the shape collided with.
Definition Broadphase.hpp:471
ContactManifold< N > manifold
Contact manifold of the collision, where the first object is the given shape and the second object is...
Definition Broadphase.hpp:477
Result of a raycast against the objects in a broadphase.
Definition Broadphase.hpp:532
CollisionFilterTestResult filterTestResult
Result of the collision filter test.
Definition Broadphase.hpp:559
Length< N > localOffset
Offset from the object's center of mass in shape-local space at which the collision occured.
Definition Broadphase.hpp:542
Direction< N > normal
Unit vector perpendicular to the separating plane of the collision, pointing away from the object's s...
Definition Broadphase.hpp:548
EntityID objectID
Handle to the object that the ray collided with.
Definition Broadphase.hpp:536
Distance distance
Distance from the raycast origin along the raycast direction at which which the ray collided.
Definition Broadphase.hpp:554
Result of a shapecast against the objects in a broadphase.
Definition Broadphase.hpp:710
Distance distance
Distance along the shapecast direction at which the collision occured.
Definition Broadphase.hpp:732
EntityID objectID
Handle to the object that the shape collided with.
Definition Broadphase.hpp:714
CollisionFilterTestResult filterTestResult
Result of the collision filter test.
Definition Broadphase.hpp:737
Pair< Length< N > > localOffsets
Offsets from the objects' centers of mass in shape-local space at which the collision occured.
Definition Broadphase.hpp:720
Direction< N > normal
Unit vector perpendicular to the separating plane of the collision, pointing away from the second obj...
Definition Broadphase.hpp:726
Generic collider.
Definition Shape.hpp:2812
Configuration options for a collision algorithm.
Definition collision.hpp:373
Result of a CollisionFilterTest.
Definition Shape.hpp:283
Test that checks if a pair of colliders should collide.
Definition Shape.hpp:337
Collision filtering options for a collider.
Definition Shape.hpp:272
Normalized unit vector.
Definition quantities.hpp:4105
Bounds of an object.
Definition objects.hpp:232
Absolute orientation in world space.
Definition quantities.hpp:4431
Description of a ray.
Definition Shape.hpp:392
Result of a raycast.
Definition Shape.hpp:654
Result of a shapecast.
Definition collision.hpp:1057