Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from direct.showbase.ShowBase import ShowBase
- from panda3d.core import VBase3
- from panda3d.bullet import BulletWorld
- from panda3d.bullet import BulletRigidBodyNode
- from panda3d.bullet import BulletSphereShape
- from panda3d.bullet import BulletDebugNode
- # Basic setup
- s = ShowBase()
- s.disable_mouse()
- s.accept('escape', sys.exit)
- s.cam.set_pos(0, -10, 0)
- # Physics
- bullet_world = BulletWorld()
- def run_physics(task):
- bullet_world.do_physics(globalClock.getDt())
- return task.cont
- s.task_mgr.add(run_physics, sort=1)
- # Debug visualization
- debug_node = BulletDebugNode('Debug')
- debug_node.showWireframe(True)
- debug_node.showConstraints(True)
- debug_node.showBoundingBoxes(False)
- debug_node.showNormals(False)
- debug_np = s.render.attach_new_node(debug_node)
- bullet_world.set_debug_node(debug_node)
- debug_np.show()
- # A node between the actual object of interest and the root of the scene graph,
- # so that we can test whether measurements are taken in node space or world
- # space.
- in_between = render.attach_new_node('in_between')
- in_between.set_hpr(0, 0, 45)
- # The object in question
- mass = BulletRigidBodyNode()
- mass.set_mass(1)
- mass.setLinearSleepThreshold(0)
- mass.setAngularSleepThreshold(0)
- shape = BulletSphereShape(1)
- mass.add_shape(shape)
- mass_node = in_between.attach_new_node(mass)
- bullet_world.attach_rigid_body(mass)
- model = s.loader.load_model('models/smiley')
- model.reparent_to(mass_node)
- # Apply torque with 't'
- def add_torque():
- mass.apply_torque_impulse(VBase3(0, 0, 1))
- s.accept('t', add_torque)
- s.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement