Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Camera.h 4.5KB

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