Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Camera.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 Get this cameras ID
  69. * \returns id
  70. */
  71. unsigned int getId();
  72. /*!
  73. * \brief Returns the current position
  74. * \param pos where the position will be stored
  75. */
  76. void getPosition(vec3_t pos);
  77. /*!
  78. * \brief Returns the up vector
  79. * \param up where the up vector will be stored
  80. */
  81. void getUp(vec3_t up);
  82. /*!
  83. * \brief Get the target currently looked at
  84. * \param target where the target will be stored
  85. */
  86. void getTarget(vec3_t target);
  87. /*!
  88. * \brief Get current yaw in degrees
  89. * \returns yaw in degrees
  90. */
  91. float getYaw();
  92. /*!
  93. * \brief Get angle/yaw of camera
  94. * \returns theta angle/yaw of camera
  95. */
  96. vec_t getRadianYaw();
  97. /*------------------------------------------------------
  98. * Pre :
  99. * Post : Returns theta angle/yaw of camera
  100. *
  101. *-- History ------------------------------------------
  102. *
  103. * 2001.05.26:
  104. * Mongoose - Created
  105. ------------------------------------------------------*/
  106. /*!
  107. * \brief Get current angle/pitch
  108. * \returns current pitch in degrees
  109. */
  110. float getPitch();
  111. /*!
  112. * \brief Get angle/pitch of camera
  113. * \returns phi angle/pitch of camera
  114. */
  115. vec_t getRadianPitch();
  116. /*!
  117. * \brief Check if the coordinate is behind camera eye
  118. * \param x X coordinate to check
  119. * \param z Z coordinate to check
  120. * \returns true if (x, z) is behind camera eye
  121. */
  122. bool isBehind(int x, int z);
  123. /*!
  124. * \brief Rotate the camera
  125. * \param angle angle in radians
  126. * \param x X coordinate of axis
  127. * \param y Y coordinate of axis
  128. * \param z Z coordinate of axis
  129. */
  130. void rotate(float angle, float x, float y, float z);
  131. /*!
  132. * \brief Set Camera position
  133. * \param x new X coordinate
  134. * \param y new Y coordinate
  135. * \param z new Z coordinate
  136. */
  137. void translate(float x, float y, float z);
  138. /*!
  139. * \brief Set the Camera to its initial state
  140. */
  141. void reset();
  142. /*!
  143. * \brief Sets the X rotation delta
  144. * \param angle thetas rotation delta in degrees
  145. */
  146. void setSensitivityX(float angle);
  147. /*!
  148. * \brief Sets the Y rotation delta
  149. * \param angle thetas rotation delta in degrees
  150. */
  151. void setSensitivityY(float angle);
  152. /*!
  153. * \brief Sends interactive command to camera
  154. * \param cmd valid camera command
  155. */
  156. void command(enum camera_command cmd);
  157. /*!
  158. * \brief Sets speed
  159. * \param s new speed, is 256 or greater in general
  160. */
  161. void setSpeed(float s);
  162. /*!
  163. * \brief Updates view target
  164. */
  165. void update();
  166. /*!
  167. * \brief Set current position
  168. * \param pos new position
  169. */
  170. void setPosition(vec3_t pos);
  171. /*!
  172. * \brief Sets the up vector
  173. * \param up new up vector
  174. */
  175. void setUp(vec3_t up);
  176. /*!
  177. * \brief Sets target (look at pos)
  178. * \param target new target
  179. */
  180. void setTarget(vec3_t target);
  181. private:
  182. unsigned int mId; //!< Unique id
  183. Quaternion mQ; //!< Quaternion for rotation
  184. unsigned int mFlags; //!< For testing with flags
  185. vec_t mPos[4]; //!< Location in 3 space (aka eye)
  186. vec_t mTarget[4]; //!< Postition we're looking at
  187. vec_t mUp[4]; //!< Up vector
  188. vec_t mSide[4]; //!< Side vector
  189. vec_t mViewDistance; //!< Distance from target
  190. vec_t mTranslateDelta; //!< Step size to move
  191. vec_t mRotateDelta; //!< Radians to rotate Y
  192. vec_t mTheta; //!< View angle Y
  193. vec_t mRotateDelta2; //!< Radians to rotate Z
  194. vec_t mTheta2; //!< View angle Z
  195. static unsigned int mCounter; //!< Id system use
  196. };
  197. #endif