mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
add point_cast
for box2d
This commit is contained in:
parent
c2f13e4f03
commit
dfc656000b
@ -98,6 +98,17 @@ void PyWorld::_register(VM* vm, PyObject* mod, PyObject* type){
|
||||
return VAR(std::move(callback.result));
|
||||
});
|
||||
|
||||
vm->bind(type, "point_cast(self, point: vec2) -> list[Body]", [](VM* vm, ArgsView args){
|
||||
auto _lock = vm->heap.gc_scope_lock();
|
||||
PyWorld& self = _CAST(PyWorld&, args[0]);
|
||||
b2AABB aabb;
|
||||
aabb.lowerBound = CAST(b2Vec2, args[1]);
|
||||
aabb.upperBound = CAST(b2Vec2, args[1]);
|
||||
MyBoxCastCallback callback(vm);
|
||||
self.world.QueryAABB(&callback, aabb);
|
||||
return VAR(std::move(callback.result));
|
||||
});
|
||||
|
||||
vm->bind(type, "step(self, dt: float, velocity_iterations: int, position_iterations: int)",
|
||||
[](VM* vm, ArgsView args){
|
||||
// disable gc during step for safety
|
||||
|
@ -28,6 +28,9 @@ class World:
|
||||
def box_cast(self, lower: vec2, upper: vec2) -> list['Body']:
|
||||
"""query bodies in the AABB region."""
|
||||
|
||||
def point_cast(self, point: vec2) -> list['Body']:
|
||||
"""query bodies that contain the point."""
|
||||
|
||||
def step(self, dt: float, velocity_iterations: int, position_iterations: int) -> None:
|
||||
"""step the simulation, e.g. world.step(1/60, 8, 3)"""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user