Allow changing polygon sides in SAT demo
This commit is contained in:
parent
518f0e55ef
commit
1d84976c99
@ -9,6 +9,9 @@ class AABBDistance:
|
||||
|
||||
title = "AABB Distance"
|
||||
|
||||
def handle_key_down(self, key):
|
||||
pass
|
||||
|
||||
def render(self, surface):
|
||||
rect_a = AxisAlignedBB(
|
||||
-(WIDTH / 8),
|
||||
@ -51,6 +54,9 @@ class PointAABBDistance:
|
||||
|
||||
title = "Point-AABB Distance"
|
||||
|
||||
def handle_key_down(self, key):
|
||||
pass
|
||||
|
||||
def render(self, surface):
|
||||
rect_a = AxisAlignedBB(
|
||||
-(WIDTH / 8),
|
||||
|
@ -1,3 +1,4 @@
|
||||
import pygame
|
||||
from ..geom import Polygon, generate_polygon
|
||||
from .. import WIDTH, HEIGHT, get_cursor_pos, get_inputs
|
||||
from ..colors import *
|
||||
@ -12,12 +13,25 @@ class SeparatingAxisTheorem:
|
||||
def __init__(self):
|
||||
self.shape1 = generate_polygon(0, 0, sides=4, radius=60)
|
||||
|
||||
self.shape2 = Polygon(*get_cursor_pos(), [
|
||||
(60, 60),
|
||||
(60, -60),
|
||||
(-60, -60),
|
||||
(-60, 60)
|
||||
])
|
||||
self.shape2 = None
|
||||
self.shape2_sides = 4
|
||||
self.shape2_radius = 60
|
||||
self.generate_shape2()
|
||||
|
||||
def generate_shape2(self):
|
||||
rotation = 45 if self.shape2 is None else self.shape2.rotation
|
||||
self.shape2 = generate_polygon(*get_cursor_pos(),
|
||||
rotation,
|
||||
sides=self.shape2_sides,
|
||||
radius=self.shape2_radius)
|
||||
|
||||
def handle_key_down(self, key):
|
||||
if key == pygame.K_a:
|
||||
self.shape2_sides = max(self.shape2_sides - 1, 3)
|
||||
self.generate_shape2()
|
||||
if key == pygame.K_d:
|
||||
self.shape2_sides = min(self.shape2_sides + 1, 31)
|
||||
self.generate_shape2()
|
||||
|
||||
def handle_input(self):
|
||||
self.shape2.set_position(*get_cursor_pos())
|
||||
|
@ -7,6 +7,9 @@ class VecProj:
|
||||
|
||||
title = "Vector Projection"
|
||||
|
||||
def handle_key_down(self, key):
|
||||
pass
|
||||
|
||||
def render(self, surface):
|
||||
x1 = -(WIDTH / 4)
|
||||
y1 = 100
|
||||
|
@ -17,6 +17,8 @@ class Screen:
|
||||
|
||||
def handle_input(self):
|
||||
for event in pygame.event.get(pygame.KEYDOWN):
|
||||
self.demos[self.demo].handle_key_down(event.key)
|
||||
|
||||
if event.key == pygame.K_DOWN:
|
||||
self.demo += 1
|
||||
if self.demo >= len(self.demos):
|
||||
|
Loading…
Reference in New Issue
Block a user