group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
SweptCollision.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <glm/vec3.hpp>
7#include <span>
8
18namespace physics
19{
20
22struct Plane
23{
24 glm::vec3 normal;
25 float distance;
26};
27
30{
31 glm::vec3 min;
32 glm::vec3 max;
33};
34
40{
41 static constexpr int k_maxPlanes = 8;
43 int planeCount{0};
44};
45
48{
49 std::span<const Plane> planes;
50 std::span<const WorldAABB> boxes;
51 std::span<const WorldBrush> brushes;
52};
53
56{
57 bool hit{false};
58 float tFirst{1.0f};
59 glm::vec3 normal{0.0f, 1.0f, 0.0f};
60};
61
74HitResult sweepAABB(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, std::span<const Plane> planes);
75
81HitResult sweepAABBvsBox(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldAABB& box);
82
87HitResult sweepAABBvsBrush(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldBrush& brush);
88
90HitResult sweepAll(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldGeometry& world);
91
92// Sphere cast
93
96{
97 bool hit{false};
98 float t{1.0f};
99 glm::vec3 normal{0.0f, 1.0f, 0.0f};
100 glm::vec3 point{0.0f};
101};
102
113SphereHitResult sphereCast(float radius, glm::vec3 start, glm::vec3 end, const WorldGeometry& world);
114
115} // namespace physics
Pure physics math — no ECS types, no registry.
Definition Movement.cpp:14
HitResult sweepAll(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldGeometry &world)
Sweep an AABB against all world geometry, returning the earliest hit.
Definition SweptCollision.cpp:197
HitResult sweepAABBvsBox(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldAABB &box)
Sweep an AABB against a static axis-aligned box.
Definition SweptCollision.cpp:58
SphereHitResult sphereCast(float radius, glm::vec3 start, glm::vec3 end, const WorldGeometry &world)
Cast a sphere along the path [start, end] against all world geometry.
Definition SweptCollision.cpp:224
HitResult sweepAABB(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, std::span< const Plane > planes)
Sweep an AABB along the path [start, end] against a list of infinite planes.
Definition SweptCollision.cpp:13
HitResult sweepAABBvsBrush(glm::vec3 halfExtents, glm::vec3 start, glm::vec3 end, const WorldBrush &brush)
Sweep an AABB against a convex brush (set of bounding planes).
Definition SweptCollision.cpp:133
Result of a swept AABB collision query.
Definition SweptCollision.hpp:56
glm::vec3 normal
Surface normal at the contact point.
Definition SweptCollision.hpp:59
float tFirst
Fraction along the movement path [0..1] where the first hit occurs.
Definition SweptCollision.hpp:58
bool hit
True if the sweep intersected a plane.
Definition SweptCollision.hpp:57
An infinite plane dividing free space from solid geometry.
Definition SweptCollision.hpp:23
glm::vec3 normal
Unit vector pointing into free (non-solid) space.
Definition SweptCollision.hpp:24
float distance
Signed offset: dot(normal, p) == distance for points on the plane.
Definition SweptCollision.hpp:25
Result of a sphere-cast query (includes world-space hit point).
Definition SweptCollision.hpp:96
glm::vec3 point
World-space contact point on the surface.
Definition SweptCollision.hpp:100
bool hit
Definition SweptCollision.hpp:97
float t
Fraction along path [0..1].
Definition SweptCollision.hpp:98
glm::vec3 normal
Surface normal at contact.
Definition SweptCollision.hpp:99
An axis-aligned box in world space, used as static collision geometry.
Definition SweptCollision.hpp:30
glm::vec3 max
Maximum corner (highest x, y, z).
Definition SweptCollision.hpp:32
glm::vec3 min
Minimum corner (lowest x, y, z).
Definition SweptCollision.hpp:31
A convex volume defined by bounding planes (for ramps, angled walls, etc.).
Definition SweptCollision.hpp:40
Plane planes[k_maxPlanes]
Definition SweptCollision.hpp:42
static constexpr int k_maxPlanes
Definition SweptCollision.hpp:41
int planeCount
Definition SweptCollision.hpp:43
All world collision geometry for one tick.
Definition SweptCollision.hpp:48
std::span< const Plane > planes
Definition SweptCollision.hpp:49
std::span< const WorldAABB > boxes
Definition SweptCollision.hpp:50
std::span< const WorldBrush > brushes
Definition SweptCollision.hpp:51