Procházet zdrojové kódy

add `point_cast` for `box2d`

blueloveTH před 2 roky
rodič
revize
dfc656000b
2 změnil soubory, kde provedl 14 přidání a 0 odebrání
  1. 11 0
      3rd/box2d/src/box2d_World.cpp
  2. 3 0
      include/typings/box2d.pyi

+ 11 - 0
3rd/box2d/src/box2d_World.cpp

@@ -98,6 +98,17 @@ void PyWorld::_register(VM* vm, PyObject* mod, PyObject* type){
         return VAR(std::move(callback.result));
         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->bind(type, "step(self, dt: float, velocity_iterations: int, position_iterations: int)",
         [](VM* vm, ArgsView args){
         [](VM* vm, ArgsView args){
             // disable gc during step for safety
             // disable gc during step for safety

+ 3 - 0
include/typings/box2d.pyi

@@ -28,6 +28,9 @@ class World:
     def box_cast(self, lower: vec2, upper: vec2) -> list['Body']:
     def box_cast(self, lower: vec2, upper: vec2) -> list['Body']:
         """query bodies in the AABB region."""
         """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:
     def step(self, dt: float, velocity_iterations: int, position_iterations: int) -> None:
         """step the simulation, e.g. world.step(1/60, 8, 3)"""
         """step the simulation, e.g. world.step(1/60, 8, 3)"""