mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
52f90b5a65
commit
f62a2d88cf
@ -46,24 +46,11 @@ It hides the details of Box2D's API and provides a high-level interface.
|
|||||||
from linalg import vec2, vec4
|
from linalg import vec2, vec4
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
class _NodeLike: # duck-type protocol
|
class _NodeLike: # duck-type protocol
|
||||||
def on_contact_begin(self, other: 'Body'): ...
|
def on_contact_begin(self, other: 'Body'): ...
|
||||||
def on_contact_end(self, other: 'Body'): ...
|
def on_contact_end(self, other: 'Body'): ...
|
||||||
|
|
||||||
class DebugDraw:
|
class _DrawLike: # duck-type protocol
|
||||||
# enum
|
|
||||||
# {
|
|
||||||
# e_shapeBit = 0x0001, ///< draw shapes
|
|
||||||
# e_jointBit = 0x0002, ///< draw joint connections
|
|
||||||
# e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
|
|
||||||
# e_pairBit = 0x0008, ///< draw broad-phase pairs
|
|
||||||
# e_centerOfMassBit = 0x0010 ///< draw center of mass frame
|
|
||||||
# };
|
|
||||||
|
|
||||||
def set_flags(self, flags: int): ...
|
|
||||||
def get_flags(self) -> int: ...
|
|
||||||
|
|
||||||
# pure virtual functions
|
|
||||||
def draw_polygon(self, vertices: list[vec2], color: vec4): ...
|
def draw_polygon(self, vertices: list[vec2], color: vec4): ...
|
||||||
def draw_solid_polygon(self, vertices: list[vec2], color: vec4): ...
|
def draw_solid_polygon(self, vertices: list[vec2], color: vec4): ...
|
||||||
def draw_circle(self, center: vec2, radius: float, color: vec4): ...
|
def draw_circle(self, center: vec2, radius: float, color: vec4): ...
|
||||||
@ -75,16 +62,13 @@ class DebugDraw:
|
|||||||
class World:
|
class World:
|
||||||
gravity: vec2 # gravity of the world, by default vec2(0, 0)
|
gravity: vec2 # gravity of the world, by default vec2(0, 0)
|
||||||
|
|
||||||
def create_body(self, node: _NodeLike = None) -> 'Body':
|
|
||||||
"""create a body in the world"""
|
|
||||||
|
|
||||||
def get_bodies(self) -> Iterable['Body']:
|
def get_bodies(self) -> Iterable['Body']:
|
||||||
"""return all bodies in the world."""
|
"""return all bodies in the world."""
|
||||||
|
|
||||||
def raycast(self, start: vec2, end: vec2) -> list['Body']:
|
def ray_cast(self, start: vec2, end: vec2) -> list['Body']:
|
||||||
"""raycast from start to end, return all bodies that intersect with the ray."""
|
"""raycast from start to end"""
|
||||||
|
|
||||||
def query_aabb(self, p0: vec2, p1: vec2) -> list['Body']:
|
def box_cast(self, p0: vec2, p1: vec2) -> list['Body']:
|
||||||
"""query bodies in the AABB region."""
|
"""query bodies in the AABB region."""
|
||||||
|
|
||||||
def step(self, dt: float, velocity_iterations: int, position_iterations: int) -> None:
|
def step(self, dt: float, velocity_iterations: int, position_iterations: int) -> None:
|
||||||
@ -93,10 +77,18 @@ class World:
|
|||||||
def destroy(self):
|
def destroy(self):
|
||||||
"""destroy this world."""
|
"""destroy this world."""
|
||||||
|
|
||||||
def debug_draw(self):
|
# enum
|
||||||
|
# {
|
||||||
|
# e_shapeBit = 0x0001, ///< draw shapes
|
||||||
|
# e_jointBit = 0x0002, ///< draw joint connections
|
||||||
|
# e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
|
||||||
|
# e_pairBit = 0x0008, ///< draw broad-phase pairs
|
||||||
|
# e_centerOfMassBit = 0x0010 ///< draw center of mass frame
|
||||||
|
# };
|
||||||
|
def debug_draw(self, flags: int):
|
||||||
"""draw debug shapes of all bodies in the world."""
|
"""draw debug shapes of all bodies in the world."""
|
||||||
|
|
||||||
def set_debug_draw(self, draw: DebugDraw):
|
def set_debug_draw(self, draw: _DrawLike):
|
||||||
"""set the debug draw object."""
|
"""set the debug draw object."""
|
||||||
|
|
||||||
class Body:
|
class Body:
|
||||||
@ -122,6 +114,9 @@ class Body:
|
|||||||
restitution_threshold: float
|
restitution_threshold: float
|
||||||
is_trigger: bool
|
is_trigger: bool
|
||||||
|
|
||||||
|
def __new__(cls, world: World, node: _NodeLike = None):
|
||||||
|
"""create a body in the world."""
|
||||||
|
|
||||||
def set_box_shape(self, hx: float, hy: float): ...
|
def set_box_shape(self, hx: float, hy: float): ...
|
||||||
def set_circle_shape(self, radius: float): ...
|
def set_circle_shape(self, radius: float): ...
|
||||||
def set_polygon_shape(self, points: list[vec2]): ...
|
def set_polygon_shape(self, points: list[vec2]): ...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user