vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
collider.h
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6#include <glm/glm.hpp>
7
8#include "core/reflect.h"
9#include "resource/asset/mesh_asset.h"
10
11namespace Vkm::Engine {
12
18enum class ColliderShape : uint8_t {
19 Box = 0,
20 Capsule = 1,
21 Mesh = 2,
22 Count
23};
24
33 ColliderShape shape = ColliderShape::Box;
34 glm::vec3 center = {0.0f, 0.0f, 0.0f};
35 glm::vec3 halfExtents = {0.5f, 0.5f, 0.5f};
36 float radius = 0.5f;
37 float halfHeight = 0.5f;
38 MeshHandle mesh = {};
40 glm::vec3 meshScale = {1.0f, 1.0f, 1.0f};
41};
42
48struct MeshNode {
49 glm::vec3 min = {0.0f, 0.0f, 0.0f};
50 glm::vec3 max = {0.0f, 0.0f, 0.0f};
51
52 uint32_t firstTriangle = 0;
53 uint32_t triangleCount = 0;
54 uint32_t rightChild = 0;
55};
56
61 uint64_t uid = 0;
62 uint64_t version = 0;
63 glm::vec3 scale = {0.0f, 0.0f, 0.0f};
64};
65
72struct Collider {
74 std::vector<ColliderPart> parts = { ColliderPart{} };
75
83 std::vector<glm::vec3> meshPoints;
84
85 std::vector<MeshNode> meshNodes;
87
88 bool isTrigger = false;
90 bool enabled = true;
91};
92
93} // namespace Vkm::Engine
94
95VKM_ENUM_NAMES(::Vkm::Engine::ColliderShape, "Box", "Capsule", "Mesh")
96
97// Every shape's fields are reflected whatever the tag, so switching a part's shape and back keeps
98// what it was authored with.
99VKM_REFLECT_BEGIN(::Vkm::Engine::ColliderPart)
100 VKM_F(shape)
101 VKM_F(center)
102 VKM_F(halfExtents)
103 VKM_F(radius)
104 VKM_F(halfHeight)
105 VKM_F(mesh)
106 VKM_F(meshScale)
107VKM_REFLECT_END()
108
109VKM_REFLECT_BEGIN(::Vkm::Engine::Collider)
110 VKM_F(isTrigger)
111 VKM_F(enabled)
112 VKM_F(parts)
113VKM_REFLECT_END()
One primitive of a collider, in the entity's local frame.
Definition collider.h:32
ColliderShape shape
Which fields below are live.
Definition collider.h:33
float halfHeight
Capsule: half the segment, caps excluded.
Definition collider.h:37
glm::vec3 halfExtents
Box: half-sizes.
Definition collider.h:35
float radius
Capsule: sweep radius.
Definition collider.h:36
MeshHandle mesh
Definition collider.h:38
glm::vec3 center
Local offset from the entity origin.
Definition collider.h:34
glm::vec3 meshScale
Mesh: applied to every vertex, as Transform scale is not.
Definition collider.h:40
Collision geometry attached to an entity, evaluated in its Transform frame.
Definition collider.h:72
std::vector< MeshNode > meshNodes
Bounding hierarchy over meshPoints, built with them.
Definition collider.h:85
std::vector< ColliderPart > parts
One or more parts; a single unit box by default.
Definition collider.h:74
MeshColliderSource meshBuiltFrom
What the two above were built from.
Definition collider.h:86
std::vector< glm::vec3 > meshPoints
The mesh part's triangle corners, three a triangle, in the part's frame, scaled by meshScale.
Definition collider.h:83
bool isTrigger
Definition collider.h:88
bool enabled
False: inert - no broadphase entry, no contacts, no debug draw.
Definition collider.h:90
What a Collider's triangles were built from, so a change to any of it rebuilds them.
Definition collider.h:60
uint64_t uid
The mesh asset, by Resource::uid; zero for none.
Definition collider.h:61
glm::vec3 scale
The part's meshScale when built.
Definition collider.h:63
uint64_t version
Its Resource::version when built.
Definition collider.h:62
One node of a triangle mesh's bounding hierarchy.
Definition collider.h:48
uint32_t firstTriangle
Leaf: first triangle; interior: unused.
Definition collider.h:52
uint32_t rightChild
Interior: the far child; left is this + 1.
Definition collider.h:54
uint32_t triangleCount
0 marks an interior node
Definition collider.h:53
Component representing a renderable mesh (geometry + material) in the world.
Definition mesh.h:13