BsFPSCamera.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "Scene/BsComponent.h"
  4. #include "Math/BsDegree.h"
  5. #include "Input/BsVirtualInput.h"
  6. namespace bs
  7. {
  8. /**
  9. * Component that controls rotation of the scene objects it's attached to through mouse input. Used for first person
  10. * views.
  11. */
  12. class FPSCamera : public Component
  13. {
  14. public:
  15. FPSCamera(const HSceneObject& parent);
  16. /**
  17. * Sets the character scene object to manipulate during rotations. When set, all yaw rotations will be applied to
  18. * the provided scene object, otherwise they will be applied to the current object.
  19. */
  20. void setCharacter(const HSceneObject& characterSO) { mCharacterSO = characterSO; }
  21. /** Triggered once per frame. Allows the component to handle input and move. */
  22. void update() override;
  23. private:
  24. /** Applies the current yaw and pitch angles, rotating the object. Also wraps and clamps the angles as necessary. */
  25. void applyAngles();
  26. HSceneObject mCharacterSO; /**< Optional parent object to manipulate. */
  27. Degree mPitch = Degree(0.0f); /**< Current pitch rotation of the camera (looking up or down). */
  28. Degree mYaw = Degree(0.0f); /**< Current yaw rotation of the camera (looking left or right). */
  29. VirtualAxis mVerticalAxis; /**< Input device axis used for controlling camera's pitch rotation (up/down). */
  30. VirtualAxis mHorizontalAxis; /**< Input device axis used for controlling camera's yaw rotation (left/right). */
  31. };
  32. using HFPSCamera = GameObjectHandle<FPSCamera>;
  33. }