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 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
  2. /*================================================================
  3. *
  4. * Project : Hel
  5. * Author : Mongoose
  6. * Website : http://www.westga.edu/~stu7440/
  7. * Email : stu7440@westga.edu
  8. * Object : Camera
  9. * License : No use w/o permission (C) 2001 Mongoose
  10. * Comments: OpenGL camera class for Freyja
  11. *
  12. * This file was generated using Mongoose's C++
  13. * template generator script. <stu7440@westga.edu>
  14. *
  15. *-- History ------------------------------------------------
  16. *
  17. * 2002.12.16:
  18. * Mongoose - Removed perspective setting and OpenGL dependency
  19. * API changes to reflect new direction of this object:
  20. * Removing outdated algorithms and code
  21. * And refactoring the class in general
  22. *
  23. * 2001.06.06:
  24. * Mongoose - Moving GLU code into here to setup break up
  25. * into Camera base class, DynamicCamera,
  26. * and GLUCamera child classes
  27. *
  28. * 2001.06.04:
  29. * Mongoose - Quaternion based compile option
  30. *
  31. * 2001.05.18:
  32. * Mongoose - Created, based on my old GL camera code
  33. * that has been used in GooseEgg since alpha
  34. * and algorithms from Yuri Zhivago's trview
  35. ================================================================*/
  36. #ifndef _CAMERA_H_
  37. #define _CAMERA_H_
  38. #include <MatMath.h>
  39. #include <Matrix.h>
  40. #include <Quaternion.h>
  41. enum camera_command /* Interactive camera control */
  42. {
  43. CAMERA_MOVE_FORWARD = 1,
  44. CAMERA_MOVE_BACKWARD,
  45. CAMERA_MOVE_UP,
  46. CAMERA_MOVE_DOWN,
  47. CAMERA_ROTATE_RIGHT,
  48. CAMERA_ROTATE_LEFT,
  49. CAMERA_SPEED_UP,
  50. CAMERA_SPEED_DOWN,
  51. CAMERA_ROTATE_UP,
  52. CAMERA_ROTATE_DOWN,
  53. CAMERA_MOVE_LEFT,
  54. CAMERA_MOVE_RIGHT
  55. };
  56. enum CameraFlags
  57. {
  58. Camera_FlyMode = 1
  59. };
  60. class Camera
  61. {
  62. public:
  63. ////////////////////////////////////////////////////////////
  64. // Constructors
  65. ////////////////////////////////////////////////////////////
  66. Camera();
  67. /*------------------------------------------------------
  68. * Pre :
  69. * Post : Constructs an object of Camera
  70. *
  71. *-- History ------------------------------------------
  72. *
  73. * 2001.05.18:
  74. * Mongoose - Created
  75. ------------------------------------------------------*/
  76. ~Camera();
  77. /*------------------------------------------------------
  78. * Pre : Camera object is allocated
  79. * Post : Deconstructs an object of Camera
  80. *
  81. *-- History ------------------------------------------
  82. *
  83. * 2001.05.18:
  84. * Mongoose - Created
  85. ------------------------------------------------------*/
  86. ////////////////////////////////////////////////////////////
  87. // Public Accessors
  88. ////////////////////////////////////////////////////////////
  89. unsigned int getId();
  90. /*------------------------------------------------------
  91. * Pre :
  92. * Post : Returns this camera's id
  93. *
  94. *-- History ------------------------------------------
  95. *
  96. * 2001.05.18:
  97. * Mongoose - Created
  98. ------------------------------------------------------*/
  99. void getPosition(vec3_t pos);
  100. /*------------------------------------------------------
  101. * Pre :
  102. * Post : Returns current position
  103. *
  104. *-- History ------------------------------------------
  105. *
  106. * 2002.06.16:
  107. * Mongoose - Created
  108. ------------------------------------------------------*/
  109. void getUp(vec3_t up);
  110. /*------------------------------------------------------
  111. * Pre :
  112. * Post : Returns up vector
  113. *
  114. *-- History ------------------------------------------
  115. *
  116. * 2001.05.18:
  117. * Mongoose - Created
  118. ------------------------------------------------------*/
  119. void getTarget(vec3_t target);
  120. /*------------------------------------------------------
  121. * Pre :
  122. * Post : Returns target ( look at pos )
  123. *
  124. *-- History ------------------------------------------
  125. *
  126. * 2001.05.18:
  127. * Mongoose - Created
  128. ------------------------------------------------------*/
  129. float getYaw();
  130. /*------------------------------------------------------
  131. * Pre : Get current yaw in degrees
  132. * Post :
  133. *
  134. *-- History ------------------------------------------
  135. *
  136. * 2002.06.22:
  137. * Mongoose - Created
  138. ------------------------------------------------------*/
  139. double getRadianYaw();
  140. /*------------------------------------------------------
  141. * Pre :
  142. * Post : Returns theta angle/yaw of camera
  143. *
  144. *-- History ------------------------------------------
  145. *
  146. * 2001.05.26:
  147. * Mongoose - Created
  148. ------------------------------------------------------*/
  149. float getPitch();
  150. /*------------------------------------------------------
  151. * Pre : Get current pitch in degrees
  152. * Post :
  153. *
  154. *-- History ------------------------------------------
  155. *
  156. * 2002.06.22:
  157. * Mongoose - Created
  158. ------------------------------------------------------*/
  159. double getRadianPitch();
  160. /*------------------------------------------------------
  161. * Pre :
  162. * Post : Returns phi angle/pitch of camera
  163. *
  164. *-- History ------------------------------------------
  165. *
  166. * 2001.05.26:
  167. * Mongoose - Created
  168. ------------------------------------------------------*/
  169. bool isBehind(int x, int z);
  170. /*------------------------------------------------------
  171. * Pre :
  172. * Post : Returns true if (x, z) is behind camera eye
  173. *
  174. *-- History ------------------------------------------
  175. *
  176. * 2001.05.26:
  177. * Mongoose - Created
  178. ------------------------------------------------------*/
  179. ////////////////////////////////////////////////////////////
  180. // Public Mutators
  181. ////////////////////////////////////////////////////////////
  182. void rotate(float angle, float x, float y, float z);
  183. /*------------------------------------------------------
  184. * Pre : x,y,z axis; angle in radians
  185. * Post : Rotates camera
  186. *
  187. *-- History ------------------------------------------
  188. *
  189. * 2001.06.04:
  190. * Mongoose - Created
  191. ------------------------------------------------------*/
  192. void translate(float x, float y, float z);
  193. /*------------------------------------------------------
  194. * Pre :
  195. * Post : Camera position is set to x,y,z
  196. *
  197. *-- History ------------------------------------------
  198. *
  199. * 2001.05.18:
  200. * Mongoose - Created
  201. ------------------------------------------------------*/
  202. void reset();
  203. /*------------------------------------------------------
  204. * Pre :
  205. * Post : Camera is set to inital state
  206. *
  207. *-- History ------------------------------------------
  208. *
  209. * 2001.05.18:
  210. * Mongoose - Created
  211. ------------------------------------------------------*/
  212. void setSensitivityX(float angle);
  213. /*------------------------------------------------------
  214. * Pre : angle is theta's rotation delta in degrees
  215. * Post : Sets rotation delta
  216. *
  217. *-- History ------------------------------------------
  218. *
  219. * 2001.06.04:
  220. * Mongoose - Created
  221. ------------------------------------------------------*/
  222. void setSensitivityY(float angle);
  223. /*------------------------------------------------------
  224. * Pre : angle is theta's rotation delta in degrees
  225. * Post : Sets rotation delta
  226. *
  227. *-- History ------------------------------------------
  228. *
  229. * 2001.06.04:
  230. * Mongoose - Created
  231. ------------------------------------------------------*/
  232. void command(enum camera_command cmd);
  233. /*------------------------------------------------------
  234. * Pre : Command is valid camera command
  235. * Post : Sends interactive command to camera
  236. *
  237. *-- History ------------------------------------------
  238. *
  239. * 2001.05.18:
  240. * Mongoose - Created
  241. ------------------------------------------------------*/
  242. void setSpeed(float s);
  243. /*------------------------------------------------------
  244. * Pre : s is 256 or greater in general
  245. * Post : Sets 'speed'
  246. *
  247. *-- History ------------------------------------------
  248. *
  249. * 2002.01.02:
  250. * Mongoose - Created
  251. ------------------------------------------------------*/
  252. void update();
  253. /*------------------------------------------------------
  254. * Pre :
  255. * Post : Updates view target
  256. *
  257. *-- History ------------------------------------------
  258. *
  259. * 2001.05.18:
  260. * Mongoose - Created
  261. ------------------------------------------------------*/
  262. void setPosition(vec3_t pos);
  263. /*------------------------------------------------------
  264. * Pre : Set current position
  265. * Post :
  266. *
  267. *-- History ------------------------------------------
  268. *
  269. * 2002.06.16:
  270. * Mongoose - Created
  271. ------------------------------------------------------*/
  272. void setUp(vec3_t up);
  273. /*------------------------------------------------------
  274. * Pre :
  275. * Post : Sets up vector
  276. *
  277. *-- History ------------------------------------------
  278. *
  279. * 2001.05.18:
  280. * Mongoose - Created
  281. ------------------------------------------------------*/
  282. void setTarget(vec3_t target);
  283. /*------------------------------------------------------
  284. * Pre :
  285. * Post : Sets target ( look at pos )
  286. *
  287. *-- History ------------------------------------------
  288. *
  289. * 2001.05.18:
  290. * Mongoose - Created
  291. ------------------------------------------------------*/
  292. private:
  293. ////////////////////////////////////////////////////////////
  294. // Private Accessors
  295. ////////////////////////////////////////////////////////////
  296. ////////////////////////////////////////////////////////////
  297. // Private Mutators
  298. ////////////////////////////////////////////////////////////
  299. unsigned int mId; /* Unquie id */
  300. Quaternion mQ; /* Quaternion for rotation */
  301. unsigned int mFlags; /* For testing with flags */
  302. double mPos[4]; /* Location in 3 space (aka eye) */
  303. double mTarget[4]; /* Postition we're looking at */
  304. double mUp[4]; /* Up vector */
  305. double mSide[4]; /* Side vector */
  306. double mViewDistance; /* Distance from target */
  307. double mTranslateDelta; /* Step size to move */
  308. double mRotateDelta; /* Radians to rotate Y */
  309. double mTheta; /* View angle Y */
  310. double mRotateDelta2; /* Radians to rotate Z */
  311. double mTheta2; /* View angle Z */
  312. bool mUpdate; /* Check to see if view needs updating */
  313. static unsigned int mCounter; /* Id system use */
  314. };
  315. #endif