group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
CollisionShape.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <cmath>
7#include <cstdint>
8#include <glm/vec3.hpp>
9
11enum class CollisionShapeType : uint8_t
12{
13 AABB = 0,
14 Capsule = 1,
15};
16
34{
37
41 glm::vec3 halfExtents{16.0f, 36.0f, 16.0f};
42
44 float radius = 16.0f;
45
48 float halfHeight = 20.0f;
49
54 [[nodiscard]] float minkowskiExtent(const glm::vec3& n) const noexcept
55 {
57 // Capsule projects to a line segment of length 2*halfHeight*|n.y|
58 // plus the radius on each end.
59 return radius + halfHeight * std::abs(n.y);
60 }
61 // AABB:
62 return std::abs(n.x) * halfExtents.x + std::abs(n.y) * halfExtents.y + std::abs(n.z) * halfExtents.z;
63 }
64};
CollisionShapeType
Which shape kind the entity uses for collision queries.
Definition CollisionShape.hpp:12
@ AABB
Axis-aligned box; uses halfExtents.
Definition CollisionShape.hpp:13
@ Capsule
Vertical capsule (axis = +Y); uses radius + halfHeight.
Definition CollisionShape.hpp:14
Collision shape attached to an entity.
Definition CollisionShape.hpp:34
float halfHeight
Capsule cylinder half-height (excludes spherical caps).
Definition CollisionShape.hpp:48
CollisionShapeType type
Which kind of shape this is — selects the runtime collision path.
Definition CollisionShape.hpp:36
float radius
Capsule cylinder radius. Unused when type == AABB.
Definition CollisionShape.hpp:44
glm::vec3 halfExtents
AABB half-dimensions.
Definition CollisionShape.hpp:41
float minkowskiExtent(const glm::vec3 &n) const noexcept
Minkowski extent of the shape along a unit direction n.
Definition CollisionShape.hpp:54