PlayerControllerComponent.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_SCENE_PLAYER_CONTROLLER_COMPONENT_H
  6. #define ANKI_SCENE_PLAYER_CONTROLLER_COMPONENT_H
  7. #include "anki/scene/SceneComponent.h"
  8. #include "anki/physics/PhysicsPlayerController.h"
  9. namespace anki {
  10. /// @addtogroup scene
  11. /// @{
  12. /// Physics player controller component.
  13. class PlayerControllerComponent: public SceneComponent
  14. {
  15. public:
  16. PlayerControllerComponent(SceneNode* node, PhysicsPlayerController* player)
  17. : SceneComponent(Type::PLAYER_CONTROLLER, node),
  18. m_player(player)
  19. {}
  20. const Transform& getTransform() const
  21. {
  22. return m_trf;
  23. }
  24. void setTransform(const Transform& trf)
  25. {
  26. m_player->moveToPosition(trf.getOrigin());
  27. }
  28. void setVelocity(F32 forwardSpeed, F32 strafeSpeed, F32 jumpSpeed,
  29. const Vec4& forwardDir)
  30. {
  31. m_player->setVelocity(forwardSpeed, strafeSpeed, jumpSpeed, forwardDir);
  32. }
  33. /// @name SceneComponent overrides
  34. /// @{
  35. ANKI_USE_RESULT Error update(SceneNode&, F32, F32, Bool& updated) override
  36. {
  37. m_trf = m_player->getTransform(updated);
  38. return ErrorCode::NONE;
  39. }
  40. /// @}
  41. static constexpr Type getClassType()
  42. {
  43. return Type::PLAYER_CONTROLLER;
  44. }
  45. private:
  46. PhysicsPlayerController* m_player;
  47. Transform m_trf;
  48. };
  49. /// @}
  50. } // end namespace anki
  51. #endif