vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
query.h
1#pragma once
2
3#include <vector>
4
5#include <glm/glm.hpp>
6
7#include "core/math/bounds.h"
8#include "ecs/entity.h"
9
10namespace Vkm::Engine {
11
12class Scene;
13struct Collider;
14struct ColliderPart;
15
22struct RayHit {
24 float distance = 0.0f;
25 glm::vec3 point = {0.0f, 0.0f, 0.0f};
26 glm::vec3 normal = {0.0f, 1.0f, 0.0f};
27};
28
37 bool hitTriggers = false;
38 bool hitStatic = true;
39 bool hitDynamic = true;
40
44 int layerMask = ~0;
45};
46
63bool raycast(
64 Scene& scene,
65 const glm::vec3& origin,
66 const glm::vec3& direction,
67 float maxDistance,
68 RayHit& out,
69 const QueryFilter& filter = {}
70);
71
87bool spherecast(
88 Scene& scene,
89 const glm::vec3& origin,
90 float radius,
91 const glm::vec3& direction,
92 float maxDistance,
93 RayHit& out,
94 const QueryFilter& filter = {}
95);
96
105class QueryParts {
106 public:
107 QueryParts() = default;
108 ~QueryParts() = default;
109
110 QueryParts(const QueryParts& other) = default;
111 QueryParts& operator=(const QueryParts& other) = default;
112
113 QueryParts(QueryParts && other) noexcept = default;
114 QueryParts& operator=(QueryParts && other) noexcept = default;
115
123 void gather(Scene& scene, const QueryFilter& filter, const Math::AABB& around);
124
135 const glm::vec3& origin,
136 const glm::vec3& direction,
137 float maxDistance,
138 RayHit& out
139 ) const;
140
141 bool empty() const { return m_parts.empty(); }
142
143 private:
144 struct Placed {
145 EntityId entity;
146 const Collider* collider = nullptr;
147 const ColliderPart* part = nullptr;
148 glm::vec3 center{0.0f};
149 glm::mat3 basis{1.0f};
150 glm::vec3 mid{0.0f};
151 glm::vec3 half{0.0f};
152 };
153
154 private:
155 std::vector<Placed> m_parts;
156};
157
158} // namespace Vkm::Engine
void gather(Scene &scene, const QueryFilter &filter, const Math::AABB &around)
Place every part filter lets through whose world bound meets around.
bool raycast(const glm::vec3 &origin, const glm::vec3 &direction, float maxDistance, RayHit &out) const
Cast a ray against the gathered parts, as raycast casts it against the scene.
Central registry managing entities and an open set of component types.
Definition scene.h:29
One primitive of a collider, in the entity's local frame.
Definition collider.h:44
Collision geometry attached to an entity, evaluated in its Transform frame.
Definition collider.h:84
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
An axis-aligned box.
Definition bounds.h:17
Which bodies a query is allowed to see.
Definition query.h:35
int layerMask
Which layers may be hit, as a mask of the bits collision uses; everything by default.
Definition query.h:44
EntityId ignore
Never hit, nor its Ragdoll's bones; the caster, usually.
Definition query.h:36
bool hitTriggers
Include colliders marked isTrigger.
Definition query.h:37
bool hitStatic
Include Static and Kinematic bodies, by their authored motion.
Definition query.h:38
bool hitDynamic
Include Dynamic bodies, a ragdoll's posed bones among them.
Definition query.h:39
What a query struck: which entity, where, and the surface it hit.
Definition query.h:22
EntityId entity
The body that was struck.
Definition query.h:23
glm::vec3 normal
Outward surface normal.
Definition query.h:26
glm::vec3 point
World-space contact point.
Definition query.h:25
float distance
Along the ray, in metres.
Definition query.h:24