Advertisement
Guest User

Bullet and DAG problem

a guest
Jan 8th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. import direct.directbase.DirectStart
  2. from panda3d.core import Vec3, NodePath
  3. from panda3d.bullet import BulletWorld, BulletDebugNode
  4. from panda3d.bullet import BulletPlaneShape
  5. from panda3d.bullet import BulletRigidBodyNode
  6. from panda3d.bullet import BulletBoxShape
  7.  
  8. base.cam.setPos(10, -30, 20)
  9. base.cam.lookAt(0, 0, 5)
  10.  
  11. # World
  12. world = BulletWorld()
  13. world.setGravity(Vec3(0, 0, -9.81))
  14.  
  15. # Root node A, its content node and neighbour node
  16. node_A = NodePath("region_node_A")
  17. content_A = NodePath("region_content_node_A")
  18. neighbour_A_to_B = NodePath("region_A_to_B")
  19. neighbour_A_to_B.reparentTo(node_A)
  20.  
  21. # Root node B and its content
  22. node_B = NodePath("region_node_B")
  23. content_B = NodePath("region_content_node_B")
  24. neighbour_B_to_A = NodePath("region_B_to_A")
  25. neighbour_B_to_A.reparentTo(node_B)
  26.  
  27. # Reparent content_A to node_A and content_B to node_B
  28. node_A.attachNewNode(content_A.node())
  29. node_B.attachNewNode(content_B.node())
  30.  
  31. neighbour_A_to_B.attachNewNode(content_B.node())
  32. neighbour_B_to_A.attachNewNode(content_A.node())
  33.  
  34. ## A to render!
  35. node_B.reparentTo(render)
  36.  
  37. neighbour_A_to_B.setPos(-2.5, 0, 0)
  38. neighbour_B_to_A.setPos(-5.0, 0, 0)
  39.  
  40. # Plane
  41. shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
  42. node = BulletRigidBodyNode('Ground')
  43. node.addShape(shape)
  44. np = render.attachNewNode(node)
  45. np.setPos(0, 0, -2)
  46. world.attachRigidBody(node)
  47.  
  48. ## Debug on
  49. debugNode = BulletDebugNode('Debug')
  50. debugNode.showWireframe(True)
  51. debugNode.showConstraints(True)
  52. debugNode.showBoundingBoxes(False)
  53. debugNode.showNormals(False)
  54. debugNP = render.attachNewNode(debugNode)
  55. debugNP.show()
  56.  
  57. world.setDebugNode(debugNP.node())
  58.  
  59. # Boxes
  60. model = loader.loadModel('models/box.egg')
  61. model.setPos(-0.5, -0.5, -0.5)
  62. model.flattenLight()
  63. shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
  64. for i in range(10):
  65.     node = BulletRigidBodyNode('Box')
  66.     node.setMass(1.0)
  67.     node.addShape(shape)
  68.     np = None
  69.     if i < 5:
  70.       np = content_A.attachNewNode(node)
  71.     else:
  72.       np = content_B.attachNewNode(node)
  73.  
  74.     np.setPos(0, 0, 2+i*2)
  75.     world.attachRigidBody(node)
  76.     model.copyTo(np)
  77.  
  78. # Update
  79. def update(task):
  80.   dt = globalClock.getDt()
  81.   world.doPhysics(dt)
  82.   return task.cont
  83.  
  84. taskMgr.add(update, 'update')
  85. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement