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