From 1662e2e4a9846ce0a593661c360ec7ecd6c80b12 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Sun, 15 Nov 2020 13:26:20 +0400 Subject: [PATCH] Draw separating lines Also reduce line thickness of shapes to 1 --- geom/demos/sat.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/geom/demos/sat.py b/geom/demos/sat.py index a0361cd..403c365 100644 --- a/geom/demos/sat.py +++ b/geom/demos/sat.py @@ -42,9 +42,19 @@ class SeparatingAxisTheorem: if inputs[pygame.K_e]: self.shape2.rotate((1/60) * 90) - def draw_axis(self, surface, normal, colliding, min1, max1, min2, max2): + def draw_axis(self, surface, normal, overlap, min1, max1, min2, max2): offset = scale(*rnormal(*normal), 300) + colliding = overlap < 0 + + if not colliding: + # separating line + dist = scale(*normal, + (min1 if min1 > min2 else min2) - overlap * 0.5) + line(surface, BLUE, + add(*dist, *offset), + add(*dist, *scale(*lnormal(*normal), 1000))) + # axis line(surface, WHITE, add(*scale(*reverse(*normal), 1000), *offset), @@ -92,7 +102,7 @@ class SeparatingAxisTheorem: overlap = max(min2 - max1, min1 - max2) overlaps.append(overlap) - self.draw_axis(surface, normal, overlap < 0, + self.draw_axis(surface, normal, overlap, min1, max1, min2, max2) colliding = all(overlap < 0 for overlap in overlaps) @@ -100,5 +110,5 @@ class SeparatingAxisTheorem: text_screen(surface, WHITE, (10, HEIGHT - 20), f"Min Distance to Resolve: {max(overlaps)}") - self.shape1.draw(surface, YELLOW, 4) - self.shape2.draw(surface, RED if colliding else WHITE, 4) + self.shape1.draw(surface, YELLOW, 1) + self.shape2.draw(surface, RED if colliding else WHITE, 1)