test_rotation.py 3.6 KB

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