Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import direct.directbase.DirectStart
- from panda3d.core import Vec3
- from panda3d.bullet import BulletWorld
- from panda3d.bullet import BulletPlaneShape
- from panda3d.bullet import BulletRigidBodyNode
- from panda3d.bullet import BulletBoxShape
- from panda3d.bullet import BulletDebugNode
- base.cam.setPos(10, -60, 10)
- base.cam.lookAt(0, 0, 0)
- base.setFrameRateMeter(True)
- base.frmin = 1000
- base.frmax = 0
- base.deltatime = 0
- debugNode = BulletDebugNode('Debug')
- debugNode.showWireframe(True)
- debugNode.showConstraints(True)
- debugNode.showBoundingBoxes(False)
- debugNode.showNormals(False)
- debugNP = render.attachNewNode(debugNode)
- debugNP.show()
- # World
- world = BulletWorld()
- world.setGravity(Vec3(0, 0, -9.81))
- world.setDebugNode(debugNP.node())
- # Plane
- ##shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
- ##node = BulletRigidBodyNode('Ground')
- ##node.addShape(shape)
- ##np = render.attachNewNode(node)
- ##np.setPos(0, 0, -2)
- ##world.attachRigidBody(node)
- #big box
- model = loader.loadModel('models/box.egg')
- model.setScale(20,20,2)
- model.setPos(-10, -10, -1)
- #model.flattenLight()
- shape = BulletBoxShape(Vec3(10,10,1))
- node = BulletRigidBodyNode('Ground')
- node.addShape(shape)
- np = render.attachNewNode(node)
- np.setPos(0, 0, -2)
- world.attachRigidBody(node)
- model.copyTo(np)
- # Boxes
- model = loader.loadModel('models/box.egg')
- model.setPos(-0.5, -0.5, -0.5)
- model.flattenLight()
- shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
- #shape = BulletSphereShape(.5)
- brange=30
- for i in range(brange):
- node = BulletRigidBodyNode('Box')
- node.setMass(2.0)
- node.addShape(shape)
- np = render.attachNewNode(node)
- np.setPos(i/brange, i/brange, 4+i*2)
- np.setHpr(i*10,-(i*10),0)
- world.attachRigidBody(node)
- model.copyTo(np)
- # Update
- def update(task):
- dt = globalClock.getDt()
- world.doPhysics(dt)
- return task.cont
- def movl():
- for node in render.findAllMatches('Ground'):
- print node.getX()
- node.setX(node.getX()-.5)
- def movr():
- for node in render.findAllMatches('Ground'):
- print node.getX()
- node.setX(node.getX()+.5)
- base.accept('a',movl)
- base.accept('d',movr)
- taskMgr.add(update, 'update')
- run()
Add Comment
Please, Sign In to add comment