Advertisement
Guest User

Untitled

a guest
Aug 10th, 2011
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. import direct.directbase.DirectStart
  2. from direct.showbase.DirectObject import DirectObject
  3. from panda3d.core import Vec3
  4. from panda3d.core import Point3
  5. from panda3d.core import TransformState
  6. from panda3d.bullet import BulletWorld
  7. from panda3d.bullet import BulletPlaneShape
  8. from panda3d.bullet import BulletRigidBodyNode
  9. from panda3d.bullet import BulletBoxShape
  10. from panda3d.bullet import BulletDebugNode
  11. from panda3d.bullet import BulletSliderConstraint
  12.  
  13. base.setBackgroundColor(0.0, 0.0, 0.6, 1)
  14. base.setFrameRateMeter(True)
  15.  
  16. base.cam.setPos(0, -20, 0)
  17. base.cam.lookAt(0, 0, 0)
  18.  
  19. # Debug
  20. debugNP = render.attachNewNode(BulletDebugNode('Debug'))
  21. debugNP.show()
  22. debugNP.node().setVerbose(True)
  23.  
  24. # World
  25. world = BulletWorld()
  26. world.setGravity(Vec3(0, 0, -9.81))
  27. world.setDebugNode(debugNP.node())
  28.  
  29. # Box 1
  30. shape = BulletBoxShape(Vec3(.5, .5, .5))
  31. node = BulletRigidBodyNode('box1')
  32. node.addShape(shape)
  33. np1 = render.attachNewNode(node)
  34. np1.setPos(0, 0, 4)
  35. world.attachRigidBody(np1.node())
  36.  
  37. # Box 2
  38. shape = BulletBoxShape(Vec3(.3, .3, .3))
  39. node = BulletRigidBodyNode('box2')
  40. node.setMass(1)
  41. node.addShape(shape)
  42. np2 = render.attachNewNode(node)
  43. np2.setPos(0, 0, 2)
  44. world.attachRigidBody(np2.node())
  45.  
  46. # Slider
  47. t1 = TransformState.makePosHpr(Point3(0, 0, -1), Vec3(0, 0, 45))
  48. t2 = TransformState.makePosHpr(Point3(0, 0, 0), Vec3(0, 0, 0))
  49. con = BulletSliderConstraint(np1.node(), np2.node(), t1, t2, True)
  50. con.setLowerLinearLimit(1)
  51. con.setUpperLinearLimit(8)
  52. world.attachConstraint(con)
  53.  
  54. # Update
  55. def update(task):
  56.   dt = globalClock.getDt()
  57.   world.doPhysics(dt)
  58.   return task.cont
  59.  
  60. taskMgr.add(update, 'update')
  61. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement