PhysicsPlayerController.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2009-2020, 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. {
  10. /// @addtogroup physics
  11. /// @{
  12. /// Init info for PhysicsPlayerController.
  13. class PhysicsPlayerControllerInitInfo
  14. {
  15. public:
  16. F32 m_mass = 83.0f;
  17. F32 m_innerRadius = 0.30f;
  18. F32 m_outerRadius = 0.50f;
  19. F32 m_height = 1.9f;
  20. F32 m_stepHeight = 1.9f * 0.33f;
  21. Vec4 m_position = Vec4(0.0f);
  22. };
  23. /// A player controller that walks the world.
  24. class PhysicsPlayerController final : public PhysicsFilteredObject
  25. {
  26. ANKI_PHYSICS_OBJECT
  27. public:
  28. static const PhysicsObjectType CLASS_TYPE = PhysicsObjectType::PLAYER_CONTROLLER;
  29. // Update the state machine
  30. void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed, const Vec4& forwardDir)
  31. {
  32. m_controller->setWalkDirection(toBt((forwardDir * forwardSpeed).xyz()));
  33. }
  34. void moveToPosition(const Vec4& position);
  35. Transform getTransform(Bool& updated)
  36. {
  37. Transform out = toAnki(m_ghostObject->getWorldTransform());
  38. updated = m_prevTrf != out;
  39. return out;
  40. }
  41. private:
  42. ClassWrapper<btPairCachingGhostObject> m_ghostObject;
  43. ClassWrapper<btCapsuleShape> m_convexShape;
  44. ClassWrapper<btKinematicCharacterController> m_controller;
  45. Transform m_prevTrf = Transform::getIdentity();
  46. PhysicsPlayerController(PhysicsWorld* world, const PhysicsPlayerControllerInitInfo& init);
  47. ~PhysicsPlayerController();
  48. };
  49. /// @}
  50. } // end namespace anki