add point_cast for box2d

This commit is contained in:
blueloveTH 2023-11-11 03:18:15 +08:00
parent c2f13e4f03
commit dfc656000b
2 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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)"""