def joint(self, *args): print "* Add Joint:", args if len(args) == 5: # Tracking Joint b1, b2, p1, p2, flag = args p1 = self.to_b2vec(p1) p2 = self.to_b2vec(p2) jointDef = box2d.b2DistanceJointDef() jointDef.Initialize(b1, b2, p1, p2) jointDef.collideConnected = flag self.parent.world.CreateJoint(jointDef) elif len(args) == 4: # Distance Joint b1, b2, p1, p2 = args p1 = self.to_b2vec(p1) p2 = self.to_b2vec(p2) jointDef = box2d.b2DistanceJointDef() jointDef.Initialize(b1, b2, p1, p2) jointDef.collideConnected = True self.parent.world.CreateJoint(jointDef) elif len(args) == 3: # Revolute Joint between two bodies (unimplemented) pass elif len(args) == 2: # Revolute Joint to the Background, at point b1 = self.parent.world.groundBody b2 = args[0] p1 = self.to_b2vec(args[1]) jointDef = box2d.b2RevoluteJointDef() jointDef.Initialize(b1, b2, p1) self.parent.world.CreateJoint(jointDef) elif len(args) == 1: # Revolute Joint to the Background, body center b1 = self.parent.world.groundBody b2 = args[0] p1 = b2.GetWorldCenter() jointDef = box2d.b2RevoluteJointDef() jointDef.Initialize(b1, b2, p1) self.parent.world.CreateJoint(jointDef)
def distanceJoint(self, b1, b2, p1, p2): # Distance Joint p1 = self.to_b2vec(p1) p2 = self.to_b2vec(p2) jointDef = box2d.b2DistanceJointDef() jointDef.Initialize(b1, b2, p1, p2) jointDef.collideConnected = True self.parent.world.CreateJoint(jointDef)
def distanceJoint(self,b1,b2,p1,p2): # Distance Joint p1 = self.to_b2vec(p1) p2 = self.to_b2vec(p2) jointDef = box2d.b2DistanceJointDef() jointDef.Initialize(b1, b2, p1, p2) jointDef.collideConnected = True self.parent.world.CreateJoint(jointDef)
def joint(self, *args): print "* Add Joint:", args if len(args) == 4: # Distance Joint b1, b2, p1, p2 = args p1 = self.parent.to_world(p1) p2 = self.parent.to_world(p2) p1x, p1y = p1 p2x, p2y = p2 p1x /= self.parent.ppm p1y /= self.parent.ppm p2x /= self.parent.ppm p2y /= self.parent.ppm p1 = box2d.b2Vec2(p1x, p1y) p2 = box2d.b2Vec2(p2x, p2y) jointDef = box2d.b2DistanceJointDef() jointDef.Initialize(b1, b2, p1, p2) jointDef.collideConnected = True self.parent.world.CreateJoint(jointDef) elif len(args) == 3: # Revolute Joint pass elif len(args) == 1: # Fixed Joint to the Background, assume the center of the body b1 = self.parent.world.GetGroundBody() b2 = args[0] p1 = b2.GetWorldCenter() jointDef = box2d.b2RevoluteJointDef() jointDef.Initialize(b1, b2, p1) self.parent.world.CreateJoint(jointDef)