From 022962ca56657debf82dfde4879a3810ad9667c4 Mon Sep 17 00:00:00 2001 From: Sai Vineet Date: Mon, 23 Dec 2013 12:46:12 +0000 Subject: Prelim. box2d 2.3 port --- diff --git a/elements/add_objects.py b/elements/add_objects.py index 728650b..7de1faa 100644 --- a/elements/add_objects.py +++ b/elements/add_objects.py @@ -110,7 +110,6 @@ class Add: circleDef.friction = friction body.CreateShape(circleDef) - body.SetMassFromShapes() return body @@ -201,15 +200,12 @@ class Add: self.parent.element_count += 1 # Add a shape to the Body - boxDef = box2d.b2PolygonDef() + boxDef = box2d.b2PolygonShape() boxDef.SetAsBox(width, height, (0,0), angle) boxDef.density = density boxDef.restitution = restitution boxDef.friction = friction - body.CreateShape(boxDef) - - body.SetMassFromShapes() return body @@ -262,7 +258,7 @@ class Add: self.parent.element_count += 1 # Add a shape to the Body - polyDef = box2d.b2PolygonDef() + polyDef = box2d.b2PolygonShape() polyDef.setVertices(vertices) polyDef.density = density @@ -270,7 +266,6 @@ class Add: polyDef.friction = friction body.CreateShape(polyDef) - body.SetMassFromShapes() return body @@ -312,7 +307,7 @@ class Add: self.parent.element_count += 1 # Create the reusable Box2D polygon and circle definitions - polyDef = box2d.b2PolygonDef() + polyDef = box2d.b2PolygonShape() polyDef.vertexCount = 4 # rectangle polyDef.density = density polyDef.restitution = restitution @@ -360,9 +355,7 @@ class Add: circleDef.localPosition = v2 / self.parent.ppm body.CreateShape(circleDef) - - # Now, all shapes have been attached - body.SetMassFromShapes() + # Return hard and soft reduced vertices return body diff --git a/elements/elements.py b/elements/elements.py index 625844c..8ab4383 100644 --- a/elements/elements.py +++ b/elements/elements.py @@ -104,7 +104,7 @@ class Elements: self.doSleep = True # Create the World - self.world = box2d.b2World(self.worldAABB, self.gravity, self.doSleep) + self.world = box2d.b2World(self.gravity, self.doSleep) # Init Colors self.init_colors() @@ -326,8 +326,9 @@ class Elements: # Walk through all known elements self.renderer.start_drawing() - for body in self.world.bodyList: - xform = body.GetXForm() + for body in self.world.bodies: + print dir(b2Body) + xform = body.GetTransform() shape = body.GetShapeList() angle = body.GetAngle() diff --git a/physics.py b/physics.py index fff69ca..b0e7dcc 100644 --- a/physics.py +++ b/physics.py @@ -36,7 +36,7 @@ from pygame.color import * sys.path.append("lib/") # If your architecture is different, comment these lines and install # the modules in your system. -sys.path.append("lib/Box2D-2.0.2b1-py2.5-linux-i686.egg") +sys.path.append("lib/Box2D-2.3b0-py2.7-linux-i686.egg") import Box2D as box2d import elements @@ -146,7 +146,7 @@ class PhysicsGame: if self.in_focus: # Drive motors if self.world.run_physics: - bodies_present = len(self.world.world.GetBodyList()) + bodies_present = len(self.world.world.bodies) clear_all_active = self.activity.clear_all.get_sensitive() if (bodies_present > 1) and clear_all_active is False: self.activity.clear_all.set_sensitive(True) @@ -191,7 +191,7 @@ class PhysicsGame: except IndexError: self.full_pos_list.append([posx, posy]) - for body in self.world.world.GetBodyList(): + for body in self.world.world.bodies: if isinstance(body.userData, dict): if body.userData.has_key('rollMotor'): diff = body.userData['rollMotor'] \ -- cgit v0.9.1