aboutsummaryrefslogtreecommitdiff
path: root/src/phys
diff options
context:
space:
mode:
Diffstat (limited to 'src/phys')
-rw-r--r--src/phys/body.odin12
-rw-r--r--src/phys/world.odin35
2 files changed, 29 insertions, 18 deletions
diff --git a/src/phys/body.odin b/src/phys/body.odin
index 6734b2b..5a7838f 100644
--- a/src/phys/body.odin
+++ b/src/phys/body.odin
@@ -63,3 +63,15 @@ aabb_vert :: proc(a: Rect, b: Rect) -> bool {
aabb :: proc(a: Rect, b: Rect) -> bool {
return aabb_hori(a, b) && aabb_vert(a, b)
}
+
+point_aabb_hori :: proc(r: Rect, p: Vec2) -> bool {
+ return r.start.x < p.x && r.start.x + r.size.x > p.x
+}
+
+point_aabb_vert :: proc(r: Rect, p: Vec2) -> bool {
+ return r.start.y < p.y && r.start.y + r.size.y > p.y
+}
+
+point_aabb :: proc(r: Rect, p: Vec2) -> bool {
+ return point_aabb_hori(r, p) && point_aabb_vert(r, p)
+}
diff --git a/src/phys/world.odin b/src/phys/world.odin
index 0f1451c..70309b5 100644
--- a/src/phys/world.odin
+++ b/src/phys/world.odin
@@ -40,8 +40,7 @@ _world_to_bin :: proc(point: Vec2) -> (i32, i32) {
i32(math.floor(point.y / BIN_SIZE))
}
-@(private = "file")
-_get_surrounding_bins :: proc(
+get_surrounding_bins :: proc(
pos: Vec2,
allocator := context.temp_allocator,
) -> []^[dynamic]Body_Handle {
@@ -169,7 +168,7 @@ get_colliding_bodies :: proc(
rect := b.rect
rect.start += b.pos
- bin_list := _get_surrounding_bins(rect.start)
+ bin_list := get_surrounding_bins(rect.start)
for bin in bin_list {
for c_h in bin {
@@ -212,7 +211,7 @@ update_body :: proc(h: Body_Handle) {
res_rect := b.rect
res_rect.start += b.pos + b.vel * dt * p
- bin_list := _get_surrounding_bins(res_rect.start)
+ bin_list := get_surrounding_bins(res_rect.start)
for bin in bin_list {
for c_h in bin {
@@ -234,20 +233,20 @@ update_body :: proc(h: Body_Handle) {
if b.vel.y > 0 {
res_pos.y = c_rect.start.y - b.rect.size.y - b.rect.start.y
b.collisions += {.Down}
- } else {
- res_pos.y = c_rect.start.y + c_rect.size.y - b.rect.start.y
- b.collisions += {.Up}
- }
- b.collisions += {.Vertical}
- } else if aabb_vert(rect, c.rect) {
- if b.vel.x > 0 {
- res_pos.x = c_rect.start.x - b.rect.size.x - b.rect.start.x
- b.collisions += {.Left}
- } else {
- res_pos.x = c_rect.start.x + c_rect.size.x - b.rect.start.x
- b.collisions += {.Right}
- }
- b.collisions += {.Horizontal}
+ } else {
+ res_pos.y = c_rect.start.y + c_rect.size.y - b.rect.start.y
+ b.collisions += {.Up}
+ }
+ b.collisions += {.Vertical}
+ } else if aabb_vert(rect, c.rect) {
+ if b.vel.x > 0 {
+ res_pos.x = c_rect.start.x - b.rect.size.x - b.rect.start.x
+ b.collisions += {.Left}
+ } else {
+ res_pos.x = c_rect.start.x + c_rect.size.x - b.rect.start.x
+ b.collisions += {.Right}
+ }
+ b.collisions += {.Horizontal}
}
}
}