ignore linear impulse if bodies are separating
This commit is contained in:
27
tools.py
27
tools.py
@@ -1,7 +1,9 @@
|
||||
import pygame as pg
|
||||
from queue import Queue
|
||||
from functools import reduce
|
||||
|
||||
from collider.types import CircleCollider, ConvexCollider, BaseCollider
|
||||
|
||||
from collider.types import CircleCollider, ConvexCollider, BaseCollider, ColliderContact
|
||||
from transform import Transform
|
||||
|
||||
def _debug(fn):
|
||||
@@ -23,30 +25,37 @@ class Debug:
|
||||
self._debug_queue.get()()
|
||||
|
||||
@_debug
|
||||
def draw_lines(self, points) -> None:
|
||||
def draw_contact(self, contact: ColliderContact) -> None:
|
||||
def _draw_lines():
|
||||
if len(points) > 1:
|
||||
if len(contact.points) > 1:
|
||||
pg.draw.lines(
|
||||
self._screen,
|
||||
(255,0,255),
|
||||
False,
|
||||
points=points,
|
||||
width=3
|
||||
points=contact.points,
|
||||
width=1
|
||||
)
|
||||
for point in points:
|
||||
for point in contact.points:
|
||||
pg.draw.circle(
|
||||
self._screen,
|
||||
(255,0,255),
|
||||
point,
|
||||
2
|
||||
1
|
||||
)
|
||||
if len(points) > 0:
|
||||
if len(contact.points) > 0:
|
||||
pg.draw.circle(
|
||||
self._screen,
|
||||
(255,0,255),
|
||||
points[0],
|
||||
contact.points[0],
|
||||
2
|
||||
)
|
||||
base = reduce(lambda a,b: a+b,contact.points) / len(contact.points)
|
||||
pg.draw.line(
|
||||
self._screen,
|
||||
(255,255,0),
|
||||
base,
|
||||
base+(contact.normal*15)
|
||||
)
|
||||
self._debug_queue.put(_draw_lines)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user