AABB rendering

This commit is contained in:
2025-03-23 00:42:56 +01:00
parent 2208a7200f
commit 74268015a0
3 changed files with 156 additions and 22 deletions

View File

@@ -51,6 +51,7 @@ Collider :: struct {
override_aabb: bool;
render_aabb: bool;
aabb_color: Vector4 = .{0,1,0,1};
aabb: AABB;
union {
@@ -231,33 +232,41 @@ physics_step :: (scene: *Scene, timestep: float) {
if !can_collide(e, other_e) continue;
if other_e.flags & .COLLISION {
point := gjk(e.collider, other_e.collider);
if other_e.collider.type == .AABB {
inv_matrix := inverse(other_e.transform.model_matrix);
aabb := other_e.collider.aabb;
if point_inside_aabb(aabb, transform_position(e.transform.position, inv_matrix)) {
//add_trigger_overlap_if_new(other_e, e);
}
} else {
point := gjk(e.collider, other_e.collider);
if point.has_collision {
if other_e.flags & .TRIGGER {
// TRIGGER CALLBACK
add_trigger_overlap_if_new(other_e, e);
} else {
n := -point.normal;
speed_along_normal := dot(e.body.velocity, n);
if point.has_collision {
if other_e.flags & .TRIGGER {
// TRIGGER CALLBACK
add_trigger_overlap_if_new(other_e, e);
} else {
n := -point.normal;
speed_along_normal := dot(e.body.velocity, n);
restitution := e.body.bounciness;
impulse := n * (-(1.0 + restitution) * speed_along_normal);
e.body.velocity += impulse;
restitution := e.body.bounciness;
impulse := n * (-(1.0 + restitution) * speed_along_normal);
e.body.velocity += impulse;
percent := 0.1;
slop := 0.005;
correction := n * max(point.penetration_depth - slop, 0.0) / (1.0 / percent);
set_position(*e.transform, e.transform.position + correction);
percent := 0.1;
slop := 0.005;
correction := n * max(point.penetration_depth - slop, 0.0) / (1.0 / percent);
set_position(*e.transform, e.transform.position + correction);
if e.body.check_for_grounded {
e.body.grounded = dot(n, WORLD_UP) > 0.6; // @Incomplete: Add allowed angle variable at some point?
if e.body.check_for_grounded {
e.body.grounded = dot(n, WORLD_UP) > 0.6; // @Incomplete: Add allowed angle variable at some point?
}
// @Incomplete: This shouldn't be in here
//if e.type == Diamond && length(impulse) > 2.0 {
// play_audio_event(sfx_diamond_hit);
//}
}
// @Incomplete: This shouldn't be in here
//if e.type == Diamond && length(impulse) > 2.0 {
// play_audio_event(sfx_diamond_hit);
//}
}
}
}