python box2d使用_Box2D python

Try it! Here's Hello.py. (Place it in the Swig directory, so it can find your new Box2D module.)

Code:

from Box2D import *

worldAABB=b2AABB()

worldAABB.minVertex.Set(-100.0, -100.0)

worldAABB.maxVertex.Set(100.0, 100.0)

gravity=b2Vec2(0,-10)

doSleep = True

world=b2World(worldAABB, gravity, doSleep)

groundBoxDef=b2BoxDef()

groundBoxDef.extents.Set(50.0, 10.0)

groundBoxDef.density = 0.0

groundBodyDef=b2BodyDef()

groundBodyDef.position.Set(0.0, -10.0)

groundBodyDef.AddShape(groundBoxDef)

world.CreateBody(groundBodyDef)

boxDef=b2BoxDef()

boxDef.extents.Set(1.0, 1.0)

boxDef.density = 1.0

boxDef.friction = 0.3

bodyDef=b2BodyDef()

bodyDef.position.Set(0.0, 4.0)

bodyDef.AddShape(boxDef)

body = world.CreateBody(bodyDef)

timeStep = 1 / 60.0

iterations = 10

for i in xrange(60):

world.Step(timeStep, iterations)

position = body.GetOriginPosition()

rotation = body.GetRotation()

print "%4.2f %4.2f %4.2f"%(position.x, position.y, rotation)

你可能感兴趣的:(python,box2d使用)