diff options
author | Brian <brian@laptop.org> | 2008-07-10 19:49:14 (GMT) |
---|---|---|
committer | Brian <brian@laptop.org> | 2008-07-10 19:49:14 (GMT) |
commit | 91e065f49dae9d7afe5e3a53c191b1b6926b8b16 (patch) | |
tree | 17aaeee2d3fc17bd9fc4599cd934a5118a5de080 /elements/add_objects.py | |
parent | 25452a24cfb3bea22d2b90ccc2eb0adf5e61329f (diff) | |
parent | 1772023f122fe0ceab52edd0124272247a144c5b (diff) |
Merge branch 'master' of git+ssh://bjordan@dev.laptop.org/git/activities/physics
Diffstat (limited to 'elements/add_objects.py')
-rw-r--r-- | elements/add_objects.py | 92 |
1 files changed, 73 insertions, 19 deletions
diff --git a/elements/add_objects.py b/elements/add_objects.py index 72dc21e..c89c273 100644 --- a/elements/add_objects.py +++ b/elements/add_objects.py @@ -445,8 +445,77 @@ class Add: # Define the body
x, y = c = tools_poly.calc_center(vertices_orig_reduced)
return self.poly((x,y), vertices, dynamic, density, restitution, friction)
-
- def joint(self, *args):
+ + # Alex Levenson's added joint methods: + def distanceJoint(self,b1,b2,p1,p2):
+ # Distance Joint
+ 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) + + def fixedJoint(self, *args): + if len(args) == 2: + # Fixed Joint to the Background, don't assume the center of the body
+ b1 = self.parent.world.GetGroundBody()
+ b2 = args[0]
+ p1 = self.parent.to_world(args[1])
+ p1x, p1y = p1
+ p1x /= self.parent.ppm
+ p1y /= self.parent.ppm
+ p1 = box2d.b2Vec2(p1x, p1y) +
+ jointDef = box2d.b2RevoluteJointDef()
+ jointDef.Initialize(b1, b2, p1)
+
+ self.parent.world.CreateJoint(jointDef)
+ 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) + + def revoluteJoint(self,b1,b2,p1): + # revolute joint between to bodies
+ p1 = self.parent.to_world(p1)
+ p1x, p1y = p1
+ p1x /= self.parent.ppm
+ p1y /= self.parent.ppm
+ p1 = box2d.b2Vec2(p1x, p1y) +
+ jointDef = box2d.b2RevoluteJointDef()
+ jointDef.Initialize(b1, b2, p1)
+
+ self.parent.world.CreateJoint(jointDef) + + def prismaticJoint(self,b1,b2,Axis=(0.0,1.0),lower=-2,upper=2): + jointDef = box2d.b2PrismaticJointDef() + worldAxis = box2d.b2Vec2(Axis[0],Axis[1]) + jointDef.Initialize(b1, b2, b1.GetWorldCenter(), worldAxis) + jointDef.lowerTranslation = lower + jointDef.upperTranslation = upper + jointDef.enableLimit = True + + self.parent.world.CreateJoint(jointDef) + + def + + def joint(self, *args): print "* Add Joint:", args
if len(args) == 4:
@@ -476,24 +545,9 @@ class Add: elif len(args) == 3:
# Revolute Joint
pass
- - elif len(args) == 2: - - # Revolute Joint to the Background, don't assume the center of the body
- b1 = self.parent.world.GetGroundBody()
- b2 = args[0]
- p1 = self.parent.to_world(args[1])
- p1x, p1y = p1
- p1x /= self.parent.ppm
- p1y /= self.parent.ppm
- p1 = box2d.b2Vec2(p1x, p1y) -
- jointDef = box2d.b2RevoluteJointDef()
- jointDef.Initialize(b1, b2, p1)
-
- self.parent.world.CreateJoint(jointDef)
+
elif len(args) == 1:
- # Revolute Joint to the Background, assume the center of the body
+ # Fixed Joint to the Background, assume the center of the body
b1 = self.parent.world.GetGroundBody()
b2 = args[0]
p1 = b2.GetWorldCenter()
|