CameraManager.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreCamera.h>
  17. #include <OgreSingleton.h>
  18. #include "Event.h"
  19. /**
  20. * The camera manager.
  21. */
  22. class CameraManager : public Ogre::Singleton<CameraManager>{
  23. public:
  24. /**
  25. * Constructor.
  26. *
  27. * Initializes the camera with default parameters attached to the root scene
  28. * manager.
  29. */
  30. CameraManager();
  31. /**
  32. * Destructor.
  33. */
  34. virtual ~CameraManager();
  35. /**
  36. * Handles camera actions.
  37. *
  38. * Handles the scene manager camera actions based on events.
  39. *
  40. * @param event[in] Event that triggers the camera action.
  41. * @param time_since_last_frame[in] For speed calculation.
  42. */
  43. void Input(
  44. const QGears::Event& event , Ogre::Real time_since_last_frame
  45. );
  46. /**
  47. * Triggered when updated.
  48. *
  49. * Unused.
  50. */
  51. void Update();
  52. /**
  53. * Trigered when the viewport is resized.
  54. *
  55. * Resets the aspect ratio.
  56. */
  57. void OnResize();
  58. /**
  59. * Enables or disables the free camera.
  60. *
  61. * A free camera moves depending on player input, not according to a
  62. * script. For example, a camera following the PC is a free camera.
  63. *
  64. * @param enable[in] True to enable free camera, false to disable it.
  65. */
  66. void SetCameraFree(const bool enable);
  67. /**
  68. * Sets the camera properties.
  69. *
  70. * @param position[in] Camera coordinates.
  71. * @param orientation[in] Camera rotation, in quaternion format.
  72. * @param fov[in] Field of view, in radians.
  73. */
  74. void Set2DCamera(
  75. const Ogre::Vector3 position, const Ogre::Quaternion orientation,
  76. const Ogre::Radian fov
  77. );
  78. /**
  79. * Sets the camera scroll.
  80. *
  81. * Moves the camera to the desired position. If the camera is in free
  82. * mode, it sets the position, but it won't actually move the camera.
  83. *
  84. * @param position[in] Position to scroll the camera to.
  85. */
  86. void Set2DScroll(const Ogre::Vector2& position);
  87. /**
  88. * Retrieves the camera position.
  89. *
  90. * @return The camera current position, relative to absolute origin.
  91. */
  92. const Ogre::Vector2& Get2DScroll() const;
  93. /**
  94. * Calculates the position of a point in screen.
  95. *
  96. * The calculation is done using A map position and the camera scroll.
  97. *
  98. * @param point[in] Position of the map to be translated to screen
  99. * position.
  100. * @return Position of POINT in screen coordinates.
  101. */
  102. const Ogre::Vector3 ProjectPointToScreen(const Ogre::Vector3& point);
  103. /**
  104. * Retrieves the camera.
  105. *
  106. * @return The current camera.
  107. */
  108. Ogre::Camera* GetCurrentCamera();
  109. /**
  110. * Retrieves the viewport.
  111. *
  112. * @return The camera viewport.
  113. */
  114. Ogre::Viewport* getViewport();
  115. /**
  116. * Enables or disables the camera wireframe.
  117. *
  118. * In wireframe mode, faces will not be rendered, only edges
  119. *
  120. * @param enable[in] True to enable wireframe mode, false to disable.
  121. */
  122. void EnableWireFrame(bool enable);
  123. private:
  124. /**
  125. * Initializes the camera parameters.
  126. *
  127. * Must be called on construction.
  128. */
  129. void InitCommands();
  130. /**
  131. * The camera.
  132. */
  133. Ogre::Camera *camera_;
  134. /**
  135. * The viewport.
  136. */
  137. Ogre::Viewport *viewport_;
  138. /**
  139. * Flag to indicate a free camera.
  140. *
  141. * A free camera moves depending on player input, not according to a
  142. * script. For example, a camera following the PC is a free camera.
  143. */
  144. bool camera_free_;
  145. /**
  146. * Flag to indicate the free camera has rotated.
  147. */
  148. bool camera_free_rotate_;
  149. /**
  150. * Camera position.
  151. */
  152. Ogre::Vector3 d2_position_;
  153. /**
  154. * Camera orientation.
  155. */
  156. Ogre::Quaternion d2_orientation_;
  157. /**
  158. * The field of view.
  159. */
  160. Ogre::Radian d2_fov_;
  161. /**
  162. * The camera scroll.
  163. */
  164. Ogre::Vector2 d2_scroll_;
  165. };