Draw separating lines
Also reduce line thickness of shapes to 1
This commit is contained in:
parent
1d84976c99
commit
1662e2e4a9
@ -42,9 +42,19 @@ class SeparatingAxisTheorem:
|
|||||||
if inputs[pygame.K_e]:
|
if inputs[pygame.K_e]:
|
||||||
self.shape2.rotate((1/60) * 90)
|
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)
|
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
|
# axis
|
||||||
line(surface, WHITE,
|
line(surface, WHITE,
|
||||||
add(*scale(*reverse(*normal), 1000), *offset),
|
add(*scale(*reverse(*normal), 1000), *offset),
|
||||||
@ -92,7 +102,7 @@ class SeparatingAxisTheorem:
|
|||||||
overlap = max(min2 - max1, min1 - max2)
|
overlap = max(min2 - max1, min1 - max2)
|
||||||
overlaps.append(overlap)
|
overlaps.append(overlap)
|
||||||
|
|
||||||
self.draw_axis(surface, normal, overlap < 0,
|
self.draw_axis(surface, normal, overlap,
|
||||||
min1, max1, min2, max2)
|
min1, max1, min2, max2)
|
||||||
|
|
||||||
colliding = all(overlap < 0 for overlap in overlaps)
|
colliding = all(overlap < 0 for overlap in overlaps)
|
||||||
@ -100,5 +110,5 @@ class SeparatingAxisTheorem:
|
|||||||
text_screen(surface, WHITE, (10, HEIGHT - 20),
|
text_screen(surface, WHITE, (10, HEIGHT - 20),
|
||||||
f"Min Distance to Resolve: {max(overlaps)}")
|
f"Min Distance to Resolve: {max(overlaps)}")
|
||||||
|
|
||||||
self.shape1.draw(surface, YELLOW, 4)
|
self.shape1.draw(surface, YELLOW, 1)
|
||||||
self.shape2.draw(surface, RED if colliding else WHITE, 4)
|
self.shape2.draw(surface, RED if colliding else WHITE, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user