Add generate_polygon, rename Rect -> AxisAlignedBB
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
from pygame import draw
|
||||
from ..geom import Rect
|
||||
from ..geom import AxisAlignedBB
|
||||
from .. import WIDTH, HEIGHT, get_cursor_pos
|
||||
from ..colors import *
|
||||
from ..math import *
|
||||
@ -10,13 +10,13 @@ class AABBDistance:
|
||||
title = "AABB Distance"
|
||||
|
||||
def render(self, surface):
|
||||
rect_a = Rect(
|
||||
rect_a = AxisAlignedBB(
|
||||
-(WIDTH / 8),
|
||||
-(HEIGHT / 8),
|
||||
WIDTH / 4,
|
||||
HEIGHT / 4,
|
||||
)
|
||||
rect_b = Rect(
|
||||
rect_b = AxisAlignedBB(
|
||||
*get_cursor_pos(),
|
||||
WIDTH / 5,
|
||||
HEIGHT / 5
|
||||
@ -52,7 +52,7 @@ class PointAABBDistance:
|
||||
title = "Point-AABB Distance"
|
||||
|
||||
def render(self, surface):
|
||||
rect_a = Rect(
|
||||
rect_a = AxisAlignedBB(
|
||||
-(WIDTH / 8),
|
||||
-(HEIGHT / 8),
|
||||
WIDTH / 4,
|
||||
|
@ -1,4 +1,4 @@
|
||||
from ..geom import Rect, Polygon
|
||||
from ..geom import Polygon, generate_polygon
|
||||
from .. import WIDTH, HEIGHT, get_cursor_pos, get_inputs
|
||||
from ..colors import *
|
||||
from ..math import *
|
||||
@ -10,12 +10,7 @@ class SeparatingAxisTheorem:
|
||||
title = "Separating Axis Theorem"
|
||||
|
||||
def __init__(self):
|
||||
self.shape1 = Polygon(0, 0, [
|
||||
(0, 60),
|
||||
(60, 0),
|
||||
(0, -60),
|
||||
(-60, 0)
|
||||
])
|
||||
self.shape1 = generate_polygon(0, 0, sides=4, radius=60)
|
||||
|
||||
self.shape2 = Polygon(*get_cursor_pos(), [
|
||||
(60, 60),
|
||||
@ -83,7 +78,8 @@ class SeparatingAxisTheorem:
|
||||
overlap = max(min2 - max1, min1 - max2)
|
||||
overlaps.append(overlap)
|
||||
|
||||
self.draw_axis(surface, normal, overlap < 0, min1, max1, min2, max2)
|
||||
self.draw_axis(surface, normal, overlap < 0,
|
||||
min1, max1, min2, max2)
|
||||
|
||||
colliding = all(overlap < 0 for overlap in overlaps)
|
||||
if colliding:
|
||||
|
Reference in New Issue
Block a user