RotationTest.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from panda3d.core import NodePath
  2. from panda3d.physics import *
  3. class RotationTest(NodePath):
  4. def __init__(self):
  5. NodePath.__init__(self, "RotationTest")
  6. def setup(self):
  7. # Connect to Physics Manager:
  8. self.actorNode=ActorNode("RotationTestActorNode")
  9. #self.actorNode.getPhysicsObject().setOriented(1)
  10. #self.actorNode.getPhysical(0).setViscosity(0.1)
  11. actorNodePath=self.attachNewNode(self.actorNode)
  12. #self.setPos(avatarNodePath, Vec3(0))
  13. #self.setHpr(avatarNodePath, Vec3(0))
  14. avatarNodePath=loader.loadModel("models/misc/smiley")
  15. assert not avatarNodePath.isEmpty()
  16. camLL=render.find("**/camLL")
  17. camLL.reparentTo(avatarNodePath)
  18. camLL.setPosHpr(0, -10, 0, 0, 0, 0)
  19. avatarNodePath.reparentTo(actorNodePath)
  20. #avatarNodePath.setPos(Vec3(0))
  21. #avatarNodePath.setHpr(Vec3(0))
  22. #avatarNodePath.assign(physicsActor)
  23. #self.phys=PhysicsManager()
  24. self.phys=base.physicsMgr
  25. if 0:
  26. fn=ForceNode("RotationTest gravity")
  27. fnp=NodePath(fn)
  28. fnp.reparentTo(self)
  29. fnp.reparentTo(render)
  30. gravity=LinearVectorForce(0.0, 0.0, -.5)
  31. fn.addForce(gravity)
  32. self.phys.addLinearForce(gravity)
  33. self.gravity = gravity
  34. if 1:
  35. fn=ForceNode("RotationTest spin")
  36. fnp=NodePath(fn)
  37. fnp.reparentTo(self)
  38. fnp.reparentTo(render)
  39. spin=AngularVectorForce(0.0, 0.0, 0.5)
  40. fn.addForce(spin)
  41. self.phys.addAngularForce(spin)
  42. self.spin = spin
  43. if 0:
  44. fn=ForceNode("RotationTest viscosity")
  45. fnp=NodePath(fn)
  46. fnp.reparentTo(self)
  47. fnp.reparentTo(render)
  48. self.avatarViscosity=LinearFrictionForce(0.0, 1.0, 0)
  49. #self.avatarViscosity.setCoef(0.9)
  50. fn.addForce(self.avatarViscosity)
  51. self.phys.addLinearForce(self.avatarViscosity)
  52. if 0:
  53. self.phys.attachLinearIntegrator(LinearEulerIntegrator())
  54. if 0:
  55. self.phys.attachAngularIntegrator(AngularEulerIntegrator())
  56. #self.phys.attachPhysicalNode(self.node())
  57. self.phys.attachPhysicalNode(self.actorNode)
  58. if 0:
  59. self.momentumForce=LinearVectorForce(0.0, 0.0, 0.0)
  60. fn=ForceNode("RotationTest momentum")
  61. fnp=NodePath(fn)
  62. fnp.reparentTo(render)
  63. fn.addForce(self.momentumForce)
  64. self.phys.addLinearForce(self.momentumForce)
  65. if 0:
  66. self.acForce=LinearVectorForce(0.0, 0.0, 0.0)
  67. fn=ForceNode("RotationTest avatarControls")
  68. fnp=NodePath(fn)
  69. fnp.reparentTo(render)
  70. fn.addForce(self.acForce)
  71. self.phys.addLinearForce(self.acForce)
  72. #self.phys.removeLinearForce(self.acForce)
  73. #fnp.remove()
  74. #avatarNodePath.reparentTo(render)
  75. self.avatarNodePath = avatarNodePath
  76. #self.actorNode.getPhysicsObject().resetPosition(self.avatarNodePath.getPos())
  77. #self.actorNode.updateTransform()
  78. if __name__ == "__main__":
  79. from direct.directbase.ThreeUpStart import *
  80. test=RotationTest()
  81. test.reparentTo(base.render)
  82. test.setup()
  83. base.camera.setY(-10.0)
  84. base.run()