Skip to content

Commit fdbdcc2

Browse files
committed
Adding a checkCollisionTraceWithSize function to the quakemap util
1 parent f8a7a9f commit fdbdcc2

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/framework/utils/quakemap.zig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,20 @@ pub const Solid = struct {
305305
return true;
306306
}
307307

308+
/// A helper to sweep the collision of a bounding box with a given velocity
308309
pub fn checkBoundingBoxCollisionWithVelocity(self: *const Solid, bounds: BoundingBox, velocity: Vec3) ?QuakeMapHit {
310+
return self.checkCollisionTraceWithSize(bounds, bounds.center, bounds.center.add(velocity));
311+
}
312+
313+
/// Sweeps a collision trace with a size
314+
pub fn checkCollisionTraceWithSize(self: *const Solid, bounds: BoundingBox, start: Vec3, end: Vec3) ?QuakeMapHit {
309315
var worldhit: ?QuakeMapHit = null;
310316

311317
const size = bounds.max.sub(bounds.min).scale(0.5);
312318
const planes = self.getExpandedPlanes(size);
313319

314-
const point = bounds.center;
315-
const next = point.add(velocity);
320+
const point = start;
321+
const next = end;
316322

317323
if (planes.len == 0)
318324
return null;
@@ -358,7 +364,8 @@ pub const Solid = struct {
358364
return worldhit;
359365
}
360366

361-
pub fn checkLineCollision(self: *const Solid, start: Vec3, end: Vec3) ?QuakeMapHit {
367+
/// Checks a collision trace with no size
368+
pub fn checkCollisionTrace(self: *const Solid, start: Vec3, end: Vec3) ?QuakeMapHit {
362369
var worldhit: ?QuakeMapHit = null;
363370

364371
if (self.faces.items.len == 0)

0 commit comments

Comments
 (0)