rev |
line source |
nuclear@11
|
1 #ifndef CAMERA_H_
|
nuclear@11
|
2 #define CAMERA_H_
|
nuclear@11
|
3
|
nuclear@11
|
4 #include <vmath/vmath.h>
|
nuclear@11
|
5
|
nuclear@15
|
6 namespace goatgfx {
|
nuclear@15
|
7
|
nuclear@11
|
8 class Camera {
|
nuclear@11
|
9 protected:
|
nuclear@11
|
10 float roll;
|
nuclear@11
|
11
|
nuclear@11
|
12 mutable struct {
|
nuclear@11
|
13 bool valid;
|
nuclear@11
|
14 Matrix4x4 mat;
|
nuclear@11
|
15 } mcache, mcache_inv;
|
nuclear@11
|
16
|
nuclear@11
|
17 virtual void calc_matrix(Matrix4x4 *mat) const = 0;
|
nuclear@11
|
18 virtual void calc_inv_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
19
|
nuclear@11
|
20 void inval_cache() { mcache.valid = mcache_inv.valid = false; }
|
nuclear@11
|
21 void set_glmat(const Matrix4x4 &m) const;
|
nuclear@11
|
22
|
nuclear@11
|
23 public:
|
nuclear@11
|
24 Camera();
|
nuclear@11
|
25 virtual ~Camera();
|
nuclear@11
|
26
|
nuclear@11
|
27 const Matrix4x4 &matrix() const;
|
nuclear@11
|
28 const Matrix4x4 &inv_matrix() const;
|
nuclear@11
|
29
|
nuclear@11
|
30 void use() const;
|
nuclear@11
|
31 void use_inverse() const;
|
nuclear@11
|
32
|
nuclear@11
|
33 // these do nothing, override to provide input handling
|
nuclear@11
|
34 virtual void input_move(float x, float y, float z);
|
nuclear@11
|
35 virtual void input_rotate(float x, float y, float z);
|
nuclear@11
|
36 virtual void input_zoom(float factor);
|
nuclear@11
|
37 };
|
nuclear@11
|
38
|
nuclear@11
|
39 class OrbitCamera : public Camera {
|
nuclear@11
|
40 protected:
|
nuclear@11
|
41 float theta, phi, rad;
|
nuclear@11
|
42
|
nuclear@11
|
43 void calc_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
44 void calc_inv_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
45
|
nuclear@11
|
46 public:
|
nuclear@11
|
47 OrbitCamera();
|
nuclear@11
|
48 virtual ~OrbitCamera();
|
nuclear@11
|
49
|
nuclear@11
|
50 void input_rotate(float x, float y, float z);
|
nuclear@11
|
51 void input_zoom(float factor);
|
nuclear@11
|
52 };
|
nuclear@11
|
53
|
nuclear@11
|
54 class FpsCamera : public OrbitCamera {
|
nuclear@11
|
55 protected:
|
nuclear@11
|
56 Vector3 pos;
|
nuclear@11
|
57
|
nuclear@11
|
58 void calc_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
59 void calc_inv_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
60
|
nuclear@11
|
61 public:
|
nuclear@11
|
62 void input_move(float x, float y, float z);
|
nuclear@11
|
63
|
nuclear@11
|
64 const Vector3 &get_position() const;
|
nuclear@11
|
65 };
|
nuclear@11
|
66
|
nuclear@11
|
67 class FlyCamera : public Camera {
|
nuclear@11
|
68 private:
|
nuclear@11
|
69 Vector3 pos;
|
nuclear@11
|
70 Quaternion rot;
|
nuclear@11
|
71
|
nuclear@11
|
72 void calc_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
73 //void calc_inv_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
74
|
nuclear@11
|
75 public:
|
nuclear@11
|
76 FlyCamera();
|
nuclear@11
|
77
|
nuclear@11
|
78 const Vector3 &get_position() const;
|
nuclear@11
|
79 const Quaternion &get_rotation() const;
|
nuclear@11
|
80
|
nuclear@11
|
81 void input_move(float x, float y, float z);
|
nuclear@11
|
82 void input_rotate(float x, float y, float z);
|
nuclear@11
|
83 };
|
nuclear@11
|
84
|
nuclear@11
|
85
|
nuclear@11
|
86 class VRFpsCamera : public FpsCamera {
|
nuclear@11
|
87 private:
|
nuclear@11
|
88 float neck_eye_dist;
|
nuclear@11
|
89 float prev_angles[3];
|
nuclear@11
|
90
|
nuclear@11
|
91 void calc_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
92 void calc_inv_matrix(Matrix4x4 *mat) const;
|
nuclear@11
|
93
|
nuclear@11
|
94 public:
|
nuclear@11
|
95 VRFpsCamera();
|
nuclear@11
|
96
|
nuclear@11
|
97 void track_vr();
|
nuclear@11
|
98 };
|
nuclear@11
|
99
|
nuclear@15
|
100 } // namespace goatgfx
|
nuclear@15
|
101
|
nuclear@11
|
102 #endif // CAMERA_H_
|