Skip to content
Permalink
Browse files
Fix ground bodies bug
  • Loading branch information
Cristian García committed Dec 27, 2016
1 parent 65d69bf commit f7e5657
Showing 1 changed file with 29 additions and 30 deletions.
@@ -476,36 +476,35 @@ def get_world_model(self, additional_vars={}, serialize=False):

bodylist = []
for body in self.world.bodies:
if not body == self.world.groundBody:
body.userData["saveid"] = save_id_index # set temporary data
save_id_index += 1
shapelist = body.fixtures
modelbody = {}
modelbody['position'] = body.position.tuple
modelbody['dynamic'] = body.type == box2d.b2_dynamicBody
modelbody['userData'] = body.userData
modelbody['angle'] = body.angle
modelbody['angularVelocity'] = body.angularVelocity
modelbody['linearVelocity'] = body.linearVelocity.tuple
if shapelist and len(shapelist) > 0:
shapes = []
for shape in shapelist:
modelshape = {}
modelshape['density'] = shape.density
modelshape['restitution'] = shape.restitution
modelshape['friction'] = shape.friction
shapename = shape.shape.__class__.__name__
if shapename == "b2CircleShape":
modelshape['type'] = 'circle'
modelshape['radius'] = shape.shape.radius
modelshape['localPosition'] = shape.shape.pos.tuple
if shapename == "b2PolygonShape":
modelshape['type'] = 'polygon'
modelshape['vertices'] = shape.shape.vertices
shapes.append(modelshape)
modelbody['shapes'] = shapes

bodylist.append(modelbody)
body.userData["saveid"] = save_id_index # set temporary data
save_id_index += 1
shapelist = body.fixtures
modelbody = {}
modelbody['position'] = body.position.tuple
modelbody['dynamic'] = body.type == box2d.b2_dynamicBody
modelbody['userData'] = body.userData
modelbody['angle'] = body.angle
modelbody['angularVelocity'] = body.angularVelocity
modelbody['linearVelocity'] = body.linearVelocity.tuple
if shapelist and len(shapelist) > 0:
shapes = []
for shape in shapelist:
modelshape = {}
modelshape['density'] = shape.density
modelshape['restitution'] = shape.restitution
modelshape['friction'] = shape.friction
shapename = shape.shape.__class__.__name__
if shapename == "b2CircleShape":
modelshape['type'] = 'circle'
modelshape['radius'] = shape.shape.radius
modelshape['localPosition'] = shape.shape.pos.tuple
if shapename == "b2PolygonShape":
modelshape['type'] = 'polygon'
modelshape['vertices'] = shape.shape.vertices
shapes.append(modelshape)
modelbody['shapes'] = shapes

bodylist.append(modelbody)

worldmodel['bodylist'] = bodylist

0 comments on commit f7e5657

Please sign in to comment.