This commit is contained in:
blueloveTH 2023-08-20 15:15:48 +08:00
parent ccb4d84d8b
commit d36ad2081b
2 changed files with 14 additions and 1 deletions

View File

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

View File

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