Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Camera.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*!
  2. * \file include/Camera.h
  3. * \brief OpenGL camera class
  4. *
  5. * \author Mongoose
  6. */
  7. #ifndef _CAMERA_H_
  8. #define _CAMERA_H_
  9. #include "utils/math.h"
  10. #include "Matrix.h"
  11. #include "Quaternion.h"
  12. /*!
  13. * \brief Commands for interactive camera control
  14. */
  15. enum camera_command {
  16. CAMERA_MOVE_FORWARD = 1,
  17. CAMERA_MOVE_BACKWARD,
  18. CAMERA_MOVE_UP,
  19. CAMERA_MOVE_DOWN,
  20. CAMERA_ROTATE_RIGHT,
  21. CAMERA_ROTATE_LEFT,
  22. CAMERA_SPEED_UP,
  23. CAMERA_SPEED_DOWN,
  24. CAMERA_ROTATE_UP,
  25. CAMERA_ROTATE_DOWN,
  26. CAMERA_MOVE_LEFT,
  27. CAMERA_MOVE_RIGHT
  28. };
  29. /*!
  30. * \brief Flags a camera can have
  31. */
  32. enum CameraFlags {
  33. Camera_FlyMode = (1 << 0) //!< Camera is flying free?
  34. };
  35. /*!
  36. * \brief OpenGL camera class
  37. *
  38. * 2002.12.16:
  39. * Mongoose - Removed perspective setting and OpenGL dependency
  40. * API changes to reflect new direction of this object:
  41. * Removing outdated algorithms and code
  42. * And refactoring the class in general
  43. *
  44. * 2001.06.06:
  45. * Mongoose - Moving GLU code into here to setup break up
  46. * into Camera base class, DynamicCamera,
  47. * and GLUCamera child classes
  48. *
  49. * 2001.06.04:
  50. * Mongoose - Quaternion based compile option
  51. *
  52. * 2001.05.18:
  53. * Mongoose - Created, based on my old GL camera code
  54. * that has been used in GooseEgg since alpha
  55. * and algorithms from Yuri Zhivago's trview
  56. */
  57. class Camera {
  58. public:
  59. /*!
  60. * \brief Constructs an object of Camera
  61. */
  62. Camera();
  63. /*!
  64. * \brief Deconstructs an object of Camera
  65. */
  66. ~Camera();
  67. /*!
  68. * \brief Returns the current position
  69. * \param pos where the position will be stored
  70. */
  71. void getPosition(vec3_t pos);
  72. /*!
  73. * \brief Returns the up vector
  74. * \param up where the up vector will be stored
  75. */
  76. void getUp(vec3_t up);
  77. /*!
  78. * \brief Get the target currently looked at
  79. * \param target where the target will be stored
  80. */
  81. void getTarget(vec3_t target);
  82. /*!
  83. * \brief Get current yaw in degrees
  84. * \returns yaw in degrees
  85. */
  86. float getYaw();
  87. /*!
  88. * \brief Get angle/yaw of camera
  89. * \returns theta angle/yaw of camera
  90. */
  91. vec_t getRadianYaw();
  92. /*!
  93. * \brief Get current angle/pitch
  94. * \returns current pitch in degrees
  95. */
  96. float getPitch();
  97. /*!
  98. * \brief Get angle/pitch of camera
  99. * \returns phi angle/pitch of camera
  100. */
  101. vec_t getRadianPitch();
  102. /*!
  103. * \brief Rotate the camera
  104. * \param angle angle in radians
  105. * \param x X coordinate of axis
  106. * \param y Y coordinate of axis
  107. * \param z Z coordinate of axis
  108. */
  109. void rotate(float angle, float x, float y, float z);
  110. /*!
  111. * \brief Set Camera position
  112. * \param x new X coordinate
  113. * \param y new Y coordinate
  114. * \param z new Z coordinate
  115. */
  116. void translate(float x, float y, float z);
  117. /*!
  118. * \brief Set the Camera to its initial state
  119. */
  120. void reset();
  121. /*!
  122. * \brief Sets the X rotation delta
  123. * \param angle thetas rotation delta in degrees
  124. */
  125. void setSensitivityX(float angle);
  126. /*!
  127. * \brief Sets the Y rotation delta
  128. * \param angle thetas rotation delta in degrees
  129. */
  130. void setSensitivityY(float angle);
  131. /*!
  132. * \brief Sends interactive command to camera
  133. * \param cmd valid camera command
  134. */
  135. void command(enum camera_command cmd);
  136. /*!
  137. * \brief Sets speed
  138. * \param s new speed, is 256 or greater in general
  139. */
  140. void setSpeed(float s);
  141. /*!
  142. * \brief Updates view target
  143. */
  144. void update();
  145. /*!
  146. * \brief Set current position
  147. * \param pos new position
  148. */
  149. void setPosition(vec3_t pos);
  150. /*!
  151. * \brief Sets the up vector
  152. * \param up new up vector
  153. */
  154. void setUp(vec3_t up);
  155. /*!
  156. * \brief Sets target (look at pos)
  157. * \param target new target
  158. */
  159. void setTarget(vec3_t target);
  160. private:
  161. Quaternion mQ; //!< Quaternion for rotation
  162. unsigned int mFlags; //!< For testing with flags
  163. vec_t mPos[4]; //!< Location in 3 space (aka eye)
  164. vec_t mTarget[4]; //!< Postition we're looking at
  165. vec_t mUp[4]; //!< Up vector
  166. vec_t mSide[4]; //!< Side vector
  167. vec_t mViewDistance; //!< Distance from target
  168. vec_t mTranslateDelta; //!< Step size to move
  169. vec_t mRotateDelta; //!< Radians to rotate Y
  170. vec_t mTheta; //!< View angle Y
  171. vec_t mRotateDelta2; //!< Radians to rotate Z
  172. vec_t mTheta2; //!< View angle Z
  173. };
  174. #endif