PhysicsPlayerController.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Physics/PhysicsObject.h>
  7. #include <AnKi/Util/ClassWrapper.h>
  8. namespace anki {
  9. /// @addtogroup physics
  10. /// @{
  11. /// Init info for PhysicsPlayerController.
  12. class PhysicsPlayerControllerInitInfo
  13. {
  14. public:
  15. F32 m_mass = 83.0f;
  16. F32 m_innerRadius = 0.30f;
  17. F32 m_outerRadius = 0.50f;
  18. F32 m_height = 1.9f;
  19. F32 m_stepHeight = 1.9f * 0.33f;
  20. Vec3 m_position = Vec3(0.0f);
  21. };
  22. /// A player controller that walks the world.
  23. class PhysicsPlayerController final : public PhysicsFilteredObject
  24. {
  25. ANKI_PHYSICS_OBJECT(PhysicsObjectType::kPlayerController)
  26. public:
  27. // Update the state machine
  28. void setVelocity(F32 forwardSpeed, [[maybe_unused]] F32 strafeSpeed, [[maybe_unused]] F32 jumpSpeed, const Vec4& forwardDir)
  29. {
  30. m_controller->setWalkDirection(toBt((forwardDir * forwardSpeed).xyz()));
  31. }
  32. /// This is a deferred operation, will happen on the next PhysicsWorld::update.
  33. void moveToPosition(const Vec3& position)
  34. {
  35. m_moveToPosition = position;
  36. }
  37. Transform getTransform()
  38. {
  39. return toAnki(m_ghostObject->getWorldTransform());
  40. }
  41. private:
  42. ClassWrapper<btPairCachingGhostObject> m_ghostObject;
  43. ClassWrapper<btCapsuleShape> m_convexShape;
  44. ClassWrapper<btKinematicCharacterController> m_controller;
  45. Vec3 m_moveToPosition = Vec3(kMaxF32);
  46. PhysicsPlayerController(const PhysicsPlayerControllerInitInfo& init);
  47. ~PhysicsPlayerController();
  48. void registerToWorld() override;
  49. void unregisterFromWorld() override;
  50. /// Called in PhysicsWorld::update.
  51. void moveToPositionForReal();
  52. };
  53. /// @}
  54. } // end namespace anki