Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--elements/add_objects.py27
-rw-r--r--tools.py10
2 files changed, 33 insertions, 4 deletions
diff --git a/elements/add_objects.py b/elements/add_objects.py
index 6ce7773..c89c273 100644
--- a/elements/add_objects.py
+++ b/elements/add_objects.py
@@ -490,6 +490,31 @@ class Add:
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
@@ -522,7 +547,7 @@ class Add:
pass
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()
diff --git a/tools.py b/tools.py
index 0c13581..125d033 100644
--- a/tools.py
+++ b/tools.py
@@ -259,15 +259,19 @@ class JointTool(Tool):
# grab the first body
self.jb1pos = event.pos
self.jb1 = self.game.world.get_bodies_at_pos(event.pos)
- self.jb2 = self.jb2pos = None
+ self.jb2 = self.jb2pos = None
+ if event.button == 2:
+ bodies = self.game.world.get_bodies_at_pos(event.pos)
+ if len(bodies) >=2:
+ self.game.world.add.revoluteJoint(bodies[0],bodies[1],event.pos)
elif event.type == MOUSEBUTTONUP:
if event.button == 1:
# grab the second body
self.jb2pos = event.pos
self.jb2 = self.game.world.get_bodies_at_pos(event.pos)
- # if we have two distinct bodies, add a joint!
+ # if we have two distinct bodies, add a distance joint!
if self.jb1 and self.jb2 and str(self.jb1) != str(self.jb2):
- self.game.world.add.distanceJoint(self.jb1[0],self.jb2[0],self.jb1pos,self.jb2pos)
+ self.game.world.add.distanceJoint(self.jb1[0],self.jb2[0],self.jb1pos,self.jb2pos)
# If there's only one body, add a fixed joint
elif self.jb2:
self.game.world.add.fixedJoint(self.jb2[0],self.jb2pos)