blueloveTH 2 年 前
コミット
d36ad2081b
2 ファイル変更14 行追加1 行削除
  1. 11 1
      3rd/box2d/src/box2d_World.cpp
  2. 3 0
      docs/modules/box2d.md

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

@@ -156,5 +156,15 @@ void PyWorld::_register(VM* vm, PyObject* mod, PyObject* type){
         self._debug_draw.draw_like = args[1];
         return vm->None;
     });
-}
+
+    // joints
+    vm->bind(type, "create_weld_joint(self, a, b)", [](VM* vm, ArgsView args){
+        PyWorld& self = _CAST(PyWorld&, args[0]);
+        PyBody& bodyA = CAST(PyBody&, args[1]);
+        PyBody& bodyB = CAST(PyBody&, args[2]);
+        b2WeldJointDef def;
+        def.Initialize(bodyA.body, bodyB.body, bodyA.body->GetWorldCenter());
+        b2Joint* p = self.world.CreateJoint(&def);
+        return VAR(p);      // void_p
+    });
 }   // namespace pkpy

+ 3 - 0
docs/modules/box2d.md

@@ -88,6 +88,9 @@ class World:
     def set_debug_draw(self, draw: _DrawLike):
         """set the debug draw object."""
 
+    def create_weld_joint(self, body_a: 'Body', body_b: 'Body'):
+        """create a weld joint between two bodies."""
+
 class Body:
     type: int           # 0-static, 1-kinematic, 2-dynamic, by default 2
     gravity_scale: float