MovableCamera.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  3. Permission is hereby granted, free of charge, to any person
  4. obtaining a copy of this software and associated documentation
  5. files (the "Software"), to deal in the Software without
  6. restriction, including without limitation the rights to use,
  7. copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the
  9. Software is furnished to do so, subject to the following
  10. conditions:
  11. The above copyright notice and this permission notice shall be
  12. included in all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  15. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  17. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  18. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #pragma once
  23. #include "Types.h"
  24. #include "Camera.h"
  25. #include "Vec2.h"
  26. #include "Mouse.h"
  27. #include "Keyboard.h"
  28. namespace crown
  29. {
  30. class MovableCamera : public Camera, public MouseListener, public KeyboardListener
  31. {
  32. public:
  33. //! Constructor
  34. MovableCamera(const Vec3& position, bool visible, float fov, float aspect,
  35. bool active, float speed, float sensibility);
  36. //! Destructor
  37. ~MovableCamera();
  38. //! Returns the camera's mouse movement sensibility
  39. float GetMouseSensibility() const;
  40. //! Sets the camera's mouse movement sensibility
  41. void SetMouseSensibility(float sensibility);
  42. //! Returns the camera's speed
  43. float GetSpeed() const;
  44. //! Sets the camera speed
  45. void SetSpeed(float speed);
  46. void SetActive(bool active);
  47. //! Loads the view matrix
  48. virtual void Render();
  49. virtual void KeyPressed(const KeyboardEvent& event);
  50. virtual void KeyReleased(const KeyboardEvent& event);
  51. protected:
  52. void MoveForward();
  53. void MoveBackward();
  54. void StrafeLeft();
  55. void StrafeRight();
  56. void SetViewByMouse();
  57. Vec2 mRotFactor;
  58. float mAngleX;
  59. float mAngleY;
  60. float mSpeed;
  61. float mMouseSensibility;
  62. bool mUpPressed : 1;
  63. bool mRightPressed : 1;
  64. bool mDownPressed : 1;
  65. bool mLeftPressed : 1;
  66. };
  67. } // namespace crown