forked from lquatrin/cpp_volume_rendering
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcamera.h
More file actions
363 lines (272 loc) · 9.37 KB
/
camera.h
File metadata and controls
363 lines (272 loc) · 9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#ifndef VIS_UTILS_CAMERA_H
#define VIS_UTILS_CAMERA_H
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <iostream>
#include <map>
namespace vis
{
class CameraData
{
public:
CameraData ();
CameraData (std::string setup_name, glm::vec3 ieye, glm::vec3 icenter, glm::vec3 iup);
~CameraData ();
std::string cam_setup_name;
unsigned int c_type;
glm::vec3 eye, center, up;
float aspect_ratio;
float field_of_view_y;
float z_near, z_far;
glm::vec3 x_axis, y_axis, z_axis, c_eye;
protected:
private:
};
class CameraBehaviour
{
public:
CameraBehaviour ();
~CameraBehaviour ();
// virtual void SetInitialState (glm::vec3 eyepos, glm::vec3 center, glm::vec3 up);
//
// virtual bool ComputeKeyInputs (std::map<unsigned char, bool>& input_movements,
// float key_mov, float key_rot, double diff_time) = 0;
//
// virtual bool ComputeMouseInputs (std::map<unsigned int, bool>& input_mouse,
// glm::vec2 mouse_diff, glm::vec2 mouse_last,
// float speed_mouse_rotation, double diff_time) = 0;
//
// virtual void ApplyRotations() = 0;
//
// void SetCameraDataPointer(CameraData* rdata);
protected:
CameraData* m_ref_data;
private:
};
class ArcBallCameraBehaviour : public CameraBehaviour
{
public:
ArcBallCameraBehaviour ();
~ArcBallCameraBehaviour ();
//virtual void SetInitialState (glm::vec3 eyepos, glm::vec3 center, glm::vec3 up);
//virtual bool ComputeKeyInputs(std::map<unsigned char, bool>& input_movements,
// float key_mov, float key_rot, double diff_time);
//virtual bool ComputeMouseInputs (std::map<unsigned int, bool>& input_mouse,
// glm::vec2 mouse_diff, glm::vec2 mouse_last,
// float speed_mouse_rotation, double diff_time);
//virtual void ApplyRotations();
protected:
//glm::vec3 m_global_rotations;
//const float cte_min_radius = 10.0f;
private:
};
class Camera
{
public:
typedef double (*GetCurrentTimeCallback) (void* data);
GetCurrentTimeCallback f_curr_time_func;
void* f_curr_time_data;
enum CAMERA_BEHAVIOUR : unsigned int {
FLIGHT = 0,
ARCBALL = 1,
};
public:
Camera ();
Camera (float _radius, float _min_rad = 1.0f, float _max_rad = 25000.0f);
~Camera ();
bool UpdatePositionAndRotations ();
bool Changing ();
bool KeyboardDown (unsigned char key, int x, int y);
bool KeyboardUp (unsigned char key, int x, int y);
int MouseButton (int bt, int st, int x, int y);
int MouseMotion (int x, int y);
int MouseWheel(int wheel, int direction, int x, int y);
float GetSpeedKeyboardMovement ();
void SetSpeedKeyboardMovement (float sskm);
float GetSpeedKeyboardRotation ();
void SetSpeedKeyboardRotation (float sskr);
float GetSpeedMouseRotation ();
void SetSpeedMouseRotation (float ssmr);
void GenerateCameraVectors (glm::vec3* zaxis, glm::vec3* yaxis, glm::vec3* xaxis)
{
(*zaxis) = glm::normalize(-GetDir());
(*xaxis) = glm::normalize(glm::cross(GetUp(), (*zaxis)));
(*yaxis) = glm::normalize(glm::cross((*zaxis), (*xaxis)));
}
void SetInitialConfig (glm::vec3 _center, glm::vec3 _up);
void SetSpeedRadius (float spd);
glm::mat4 LookAt ();
glm::mat4 Projection ();
glm::vec3 GetDir ();
glm::vec3 GetUp ()
{
return c_data.up;
}
float GetRadius ()
{
return radius;
}
void UpdateAspectRatio (float w, float h);
float GetAspectRatio ();
float GetFovY ();
float GetTanFovY ();
void SetData (CameraData* data);
void GetCameraVectors (glm::vec3* forward, glm::vec3* up, glm::vec3* right);
glm::vec3 GetEye ();
glm::vec3 GetZAxis ();
glm::vec3 GetYAxis ();
glm::vec3 GetXAxis ();
protected:
CameraBehaviour c_behaviour;
CameraData c_data;
bool m_changing_camera;
float radius;
float speed;
float speed_radius;
float speed_zoom = 50.0f;
float min_radius;
float max_radius;
bool perspective;
private:
int last_mx, last_my;
int cur_mx, cur_my;
bool arcball_on;
bool changing_radius;
float speed_keyboard_movement;
float speed_keyboard_rotation;
std::map<unsigned char, bool> input_movements;
float speed_mouse_rotation;
std::map<unsigned int, bool> input_mouse;
glm::vec2 mouse_diff, mouse_last;
double current_elapsed_time;
};
}
#endif
/*
class CameraBehaviour
{
public:
CameraBehaviour ();
~CameraBehaviour ();
virtual void SetInitialState (glm::vec3 eyepos, glm::vec3 center, glm::vec3 up);
virtual bool ComputeKeyInputs (std::map<unsigned char, bool>& input_movements,
float key_mov, float key_rot, double diff_time) = 0;
virtual bool ComputeMouseInputs (std::map<unsigned int, bool>& input_mouse,
glm::vec2 mouse_diff, glm::vec2 mouse_last,
float speed_mouse_rotation, double diff_time) = 0;
virtual void ApplyRotations () = 0;
void SetCameraDataPointer (CameraData* rdata);
protected:
CameraData* m_ref_data;
private:
};
class FlightCameraBehaviour : public CameraBehaviour
{
public:
FlightCameraBehaviour ();
~FlightCameraBehaviour ();
//virtual void SetInitialState (glm::vec3 eyepos, glm::vec3 center, glm::vec3 up);
virtual bool ComputeKeyInputs (std::map<unsigned char, bool>& input_movements,
float key_mov, float key_rot, double diff_time);
virtual bool ComputeMouseInputs (std::map<unsigned int, bool>& input_mouse,
glm::vec2 mouse_diff, glm::vec2 mouse_last,
float speed_mouse_rotation, double diff_time);
virtual void ApplyRotations ();
protected:
glm::vec3 m_input_rotations;
private:
};
class ArcBallCameraBehaviour : public CameraBehaviour
{
public:
ArcBallCameraBehaviour ();
~ArcBallCameraBehaviour ();
//virtual void SetInitialState (glm::vec3 eyepos, glm::vec3 center, glm::vec3 up);
virtual bool ComputeKeyInputs (std::map<unsigned char, bool>& input_movements,
float key_mov, float key_rot, double diff_time);
virtual bool ComputeMouseInputs (std::map<unsigned int, bool>& input_mouse,
glm::vec2 mouse_diff, glm::vec2 mouse_last,
float speed_mouse_rotation, double diff_time);
virtual void ApplyRotations ();
protected:
glm::vec3 m_global_rotations;
const float cte_min_radius = 10.0f;
private:
};
class Camera
{
public:
typedef double (*GetCurrentTimeCallback) (void* data);
GetCurrentTimeCallback f_curr_time_func;
void* f_curr_time_data;
enum CAMERA_BEHAVIOUR : unsigned int {
FLIGHT = 0,
// https://www.talisman.org/~erlkonig/misc/shoemake92-arcball.pdf
ARCBALL = 1,
};
enum PROJECTION_MATRICES : unsigned int {
PERSPECTIVE = 0,
ORTOGRAPHIC = 1,
};
Camera ();
~Camera ();
void SetCameraBehaviour (Camera::CAMERA_BEHAVIOUR cam_beha);
Camera::CAMERA_BEHAVIOUR GetCameraBehaviour ();
void SetCameraData (vis::CameraData* cd);
void SetInitialState (glm::vec3 eyepos, glm::vec3 center, glm::vec3 up);
void SetGetCurrentTimeFunction (GetCurrentTimeCallback f, void* d);
glm::mat4 LookAt (bool use_glm_functions = true);
glm::mat4 Projection (Camera::PROJECTION_MATRICES pm = Camera::PROJECTION_MATRICES::PERSPECTIVE, bool use_glm_functions = true);
// https://stackoverflow.com/questions/5504635/computing-fovx-opengl
float GetFovX (float fov_y);
float GetFovY ()
{
return m_cam_data.field_of_view_y;
}
float GetFovY (float fov_x);
float GetAspectRatio ()
{
return m_cam_data.aspect_ratio;
}
void UpdateAspectRatio (int screen_width, int screen_height);
void SetViewEye (glm::vec3 ve);
glm::vec3 GetViewEye ();
glm::vec3 GetViewDir ();
glm::vec3 GetXAxis ();
glm::vec3 GetYAxis ();
glm::vec3 GetZAxis ();
bool UpdatePositionAndOrientation ();
bool KeyboardDown (unsigned char key, int x, int y);
bool KeyboardUp (unsigned char key, int x, int y);
void MouseButton (int bt, int st, int x, int y);
int MouseMotion (int x, int y);
float GetSpeedKeyboardMovement ();
void SetSpeedKeyboardMovement (float sskm);
float GetSpeedKeyboardRotation ();
void SetSpeedKeyboardRotation (float sskr);
float GetSpeedMouseRotation ();
void SetSpeedMouseRotation (float ssmr);
protected:
CAMERA_BEHAVIOUR current_behaviour;
CameraBehaviour* m_cam_behaviour;
double GetCurrentTime ()
{
if (f_curr_time_func)
return f_curr_time_func(f_curr_time_data);
return -1.0;
}
CameraData m_cam_data;
float speed_keyboard_movement;
float speed_keyboard_rotation;
std::map<unsigned char, bool> input_movements;
float speed_mouse_rotation;
std::map<unsigned int, bool> input_mouse;
glm::vec2 mouse_diff, mouse_last;
double current_elapsed_time;
private:
};
}
#endif
*/