NcEngine
CollisionQuery.h
Go to the documentation of this file.
1
5#pragma once
6
8
9#include <functional>
10#include <memory>
11#include <vector>
12
13namespace nc
14{
15class CookedShape;
16struct Shape;
17
19struct Ray
20{
21 Vector3 origin = Vector3::Zero();
22 Vector3 direction = Vector3::Front();
23};
24
27{
28 using EntityFilter_t = std::function<bool(Entity)>;
29 static constexpr auto EntityFilterAll = [](Entity) { return true; };
30
31 EntityFilter_t entityFilter = EntityFilterAll;
32 bool includeStatic = true;
33 bool includeDynamic = true;
34 bool includeTrigger = false;
35};
36
39{
41 Vector3 point = Vector3::Zero();
42 Vector3 surfaceNormal = Vector3::Zero();
43};
44
47{
51 float depth;
52};
53
56{
57 std::vector<TestShapeHit> hits;
58};
59
62{
63 public:
66
68 CollisionQuery& operator=(CollisionQuery&&) noexcept;
69 ~CollisionQuery() noexcept;
70
72 auto CastRay(const Ray& ray) const -> RayCastResult;
73
75 auto TestShape(const Shape& shape,
76 const Vector3& position = Vector3::Zero(),
77 const Quaternion& rotation = Quaternion::Identity()) const -> TestShapeResult;
78
83 auto TestShape(const CookedShape& shape,
84 const Vector3& position,
85 const Quaternion& rotation) const -> TestShapeResult;
86
88 auto TestShape(const CookedShape& shape) const -> TestShapeResult;
89
91 auto TestPoint(const Vector3& point) const -> std::vector<Entity>;
92
93 private:
94 std::unique_ptr<class CollisionQueryImpl> m_impl;
95};
96} // namespace nc
Interface for performing collision querries against rigid bodies.
Definition: CollisionQuery.h:62
auto TestPoint(const Vector3 &point) const -> std::vector< Entity >
Query for all bodies that contain a point.
auto CastRay(const Ray &ray) const -> RayCastResult
Query for the first body that a ray intersects.
CollisionQuery(const CollisionQueryFilter &filter=CollisionQueryFilter{})
Construct a CollisionQuery capable of testing against bodies which pass a filter.
auto TestShape(const Shape &shape, const Vector3 &position=Vector3::Zero(), const Quaternion &rotation=Quaternion::Identity()) const -> TestShapeResult
Query for all bodies that collide with a shape.
Handle to a processed Shape instance.
Definition: CookedShape.h:32
Identifies an object in the registry.
Definition: Entity.h:18
static constexpr auto Null() noexcept
Construct a null Entity.
Definition: Entity.h:61
Parameter controlling inclusion and exclusion of bodies from a CollisionQuery.
Definition: CollisionQuery.h:27
bool includeStatic
include static bodies in queries
Definition: CollisionQuery.h:32
EntityFilter_t entityFilter
include only bodies passing a custom filter (non-null)
Definition: CollisionQuery.h:31
bool includeTrigger
include triggers in queries
Definition: CollisionQuery.h:34
bool includeDynamic
include dynamic and kinematic bodies in queries
Definition: CollisionQuery.h:33
Quaternion type for representing 3D rotations.
Definition: Quaternion.h:13
Result of a raycast query.
Definition: CollisionQuery.h:39
Vector3 surfaceNormal
surface normal on the hit body
Definition: CollisionQuery.h:42
Vector3 point
worldspace point where the ray intersects the body
Definition: CollisionQuery.h:41
Entity hit
parent Entity of the first hit body or Entity::Null()
Definition: CollisionQuery.h:40
Ray used for performing raycast queries.
Definition: CollisionQuery.h:20
Vector3 origin
origin of the ray
Definition: CollisionQuery.h:21
Vector3 direction
combined direction and distance of the ray
Definition: CollisionQuery.h:22
Describes collision geometry for physics types.
Definition: Shape.h:31
Individual hit information from a shape test query.
Definition: CollisionQuery.h:47
Entity hit
the body that was collided with
Definition: CollisionQuery.h:48
float depth
penetration depth of the collision
Definition: CollisionQuery.h:51
Vector3 collisionNormal
collision resolution normal pointing from shape towards hit
Definition: CollisionQuery.h:50
Vector3 point
worldspace contact point on the surface of the hit body
Definition: CollisionQuery.h:49
Result of a shape collide query.
Definition: CollisionQuery.h:56
std::vector< TestShapeHit > hits
0 or more hit results
Definition: CollisionQuery.h:57
A three component vector.
Definition: Vector.h:29