Guest User

Untitled

a guest
Jun 25th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import direct.directbase.DirectStart
  2. from panda3d.core import Vec3
  3. from panda3d.bullet import BulletWorld
  4. from panda3d.bullet import BulletPlaneShape
  5. from panda3d.bullet import BulletRigidBodyNode
  6. from panda3d.bullet import BulletBoxShape
  7. from panda3d.bullet import BulletDebugNode
  8.  
  9.  
  10. base.cam.setPos(10, -60, 10)
  11. base.cam.lookAt(0, 0, 0)
  12.  
  13. base.setFrameRateMeter(True)
  14.  
  15. base.frmin = 1000
  16. base.frmax = 0
  17. base.deltatime = 0
  18.  
  19. debugNode = BulletDebugNode('Debug')
  20. debugNode.showWireframe(True)
  21. debugNode.showConstraints(True)
  22. debugNode.showBoundingBoxes(False)
  23. debugNode.showNormals(False)
  24. debugNP = render.attachNewNode(debugNode)
  25. debugNP.show()
  26.  
  27.  
  28.  
  29. # World
  30. world = BulletWorld()
  31. world.setGravity(Vec3(0, 0, -9.81))
  32. world.setDebugNode(debugNP.node())
  33.  
  34. # Plane
  35. ##shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
  36. ##node = BulletRigidBodyNode('Ground')
  37. ##node.addShape(shape)
  38. ##np = render.attachNewNode(node)
  39. ##np.setPos(0, 0, -2)
  40. ##world.attachRigidBody(node)
  41.  
  42. #big box
  43. model = loader.loadModel('models/box.egg')
  44. model.setScale(20,20,2)
  45. model.setPos(-10, -10, -1)
  46. #model.flattenLight()
  47. shape = BulletBoxShape(Vec3(10,10,1))
  48.  
  49. node = BulletRigidBodyNode('Ground')
  50. node.addShape(shape)
  51. np = render.attachNewNode(node)
  52. np.setPos(0, 0, -2)
  53. world.attachRigidBody(node)
  54. model.copyTo(np)
  55.  
  56.  
  57. # Boxes
  58. model = loader.loadModel('models/box.egg')
  59. model.setPos(-0.5, -0.5, -0.5)
  60. model.flattenLight()
  61. shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
  62. #shape = BulletSphereShape(.5)
  63. brange=30
  64.  
  65. for i in range(brange):
  66. node = BulletRigidBodyNode('Box')
  67. node.setMass(2.0)
  68.  
  69. node.addShape(shape)
  70. np = render.attachNewNode(node)
  71. np.setPos(i/brange, i/brange, 4+i*2)
  72. np.setHpr(i*10,-(i*10),0)
  73. world.attachRigidBody(node)
  74. model.copyTo(np)
  75.  
  76. # Update
  77. def update(task):
  78. dt = globalClock.getDt()
  79. world.doPhysics(dt)
  80. return task.cont
  81.  
  82. def movl():
  83. for node in render.findAllMatches('Ground'):
  84. print node.getX()
  85. node.setX(node.getX()-.5)
  86. def movr():
  87. for node in render.findAllMatches('Ground'):
  88. print node.getX()
  89. node.setX(node.getX()+.5)
  90.  
  91. base.accept('a',movl)
  92. base.accept('d',movr)
  93. taskMgr.add(update, 'update')
  94. run()
Add Comment
Please, Sign In to add comment