Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import direct.directbase.DirectStart
- from direct.showbase.DirectObject import DirectObject
- from panda3d.core import Vec3
- from panda3d.core import Point3
- from panda3d.core import TransformState
- 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
- from panda3d.bullet import BulletSliderConstraint
- base.setBackgroundColor(0.0, 0.0, 0.6, 1)
- base.setFrameRateMeter(True)
- base.cam.setPos(0, -20, 0)
- base.cam.lookAt(0, 0, 0)
- # Debug
- debugNP = render.attachNewNode(BulletDebugNode('Debug'))
- debugNP.show()
- debugNP.node().setVerbose(True)
- # World
- world = BulletWorld()
- world.setGravity(Vec3(0, 0, -9.81))
- world.setDebugNode(debugNP.node())
- # Box 1
- shape = BulletBoxShape(Vec3(.5, .5, .5))
- node = BulletRigidBodyNode('box1')
- node.addShape(shape)
- np1 = render.attachNewNode(node)
- np1.setPos(0, 0, 4)
- world.attachRigidBody(np1.node())
- # Box 2
- shape = BulletBoxShape(Vec3(.3, .3, .3))
- node = BulletRigidBodyNode('box2')
- node.setMass(1)
- node.addShape(shape)
- np2 = render.attachNewNode(node)
- np2.setPos(0, 0, 2)
- world.attachRigidBody(np2.node())
- # Slider
- t1 = TransformState.makePosHpr(Point3(0, 0, -1), Vec3(0, 0, 45))
- t2 = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 0))
- con = BulletSliderConstraint(np1.node(), np2.node(), t1, t2, True)
- con.setLowerLinearLimit(1)
- con.setUpperLinearLimit(8)
- world.attachConstraint(con)
- # Update
- def update(task):
- dt = globalClock.getDt()
- world.doPhysics(dt)
- return task.cont
- taskMgr.add(update, 'update')
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement