Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. import sys
  2.  
  3. from direct.showbase.ShowBase import ShowBase
  4.  
  5. from panda3d.core import VBase3
  6. from panda3d.bullet import BulletWorld
  7. from panda3d.bullet import BulletRigidBodyNode
  8. from panda3d.bullet import BulletSphereShape
  9. from panda3d.bullet import BulletDebugNode
  10.  
  11.  
  12. # Basic setup
  13. s = ShowBase()
  14. s.disable_mouse()
  15. s.accept('escape', sys.exit)
  16. s.cam.set_pos(0, -10, 0)
  17.  
  18.  
  19. # Physics
  20. bullet_world = BulletWorld()
  21. def run_physics(task):
  22.     bullet_world.do_physics(globalClock.getDt())
  23.     return task.cont
  24. s.task_mgr.add(run_physics, sort=1)
  25. # Debug visualization
  26. debug_node = BulletDebugNode('Debug')
  27. debug_node.showWireframe(True)
  28. debug_node.showConstraints(True)
  29. debug_node.showBoundingBoxes(False)
  30. debug_node.showNormals(False)
  31. debug_np = s.render.attach_new_node(debug_node)
  32. bullet_world.set_debug_node(debug_node)
  33. debug_np.show()
  34.  
  35.  
  36. # A node between the actual object of interest and the root of the scene graph,
  37. # so that we can test whether measurements are taken in node space or world
  38. # space.
  39. in_between = render.attach_new_node('in_between')
  40. in_between.set_hpr(0, 0, 45)
  41.  
  42.  
  43. # The object in question
  44. mass = BulletRigidBodyNode()
  45. mass.set_mass(1)
  46. mass.setLinearSleepThreshold(0)
  47. mass.setAngularSleepThreshold(0)
  48. shape = BulletSphereShape(1)
  49. mass.add_shape(shape)
  50. mass_node = in_between.attach_new_node(mass)
  51. bullet_world.attach_rigid_body(mass)
  52. model = s.loader.load_model('models/smiley')
  53. model.reparent_to(mass_node)
  54. # Apply torque with 't'
  55. def add_torque():
  56.     mass.apply_torque_impulse(VBase3(0, 0, 1))
  57. s.accept('t', add_torque)
  58.  
  59.  
  60. s.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement