PhysicsPlayerController.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2009-2022, 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::PLAYER_CONTROLLER)
  26. public:
  27. // Update the state machine
  28. void setVelocity(F32 forwardSpeed, [[maybe_unused]] F32 strafeSpeed, [[maybe_unused]] F32 jumpSpeed,
  29. const Vec4& forwardDir)
  30. {
  31. m_controller->setWalkDirection(toBt((forwardDir * forwardSpeed).xyz()));
  32. }
  33. /// This is a deferred operation, will happen on the next PhysicsWorld::update.
  34. void moveToPosition(const Vec3& position)
  35. {
  36. m_moveToPosition = position;
  37. }
  38. Transform getTransform()
  39. {
  40. return toAnki(m_ghostObject->getWorldTransform());
  41. }
  42. private:
  43. ClassWrapper<btPairCachingGhostObject> m_ghostObject;
  44. ClassWrapper<btCapsuleShape> m_convexShape;
  45. ClassWrapper<btKinematicCharacterController> m_controller;
  46. Vec3 m_moveToPosition = Vec3(MAX_F32);
  47. PhysicsPlayerController(PhysicsWorld* world, const PhysicsPlayerControllerInitInfo& init);
  48. ~PhysicsPlayerController();
  49. void registerToWorld() override;
  50. void unregisterFromWorld() override;
  51. /// Called in PhysicsWorld::update.
  52. void moveToPositionForReal();
  53. };
  54. /// @}
  55. } // end namespace anki