goat3dgfx

view src/camera.h @ 34:3eb6c8f89fe1

merge
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 02 Mar 2014 17:41:10 +0200
parents d061fe1a31ec
children
line source
1 #ifndef CAMERA_H_
2 #define CAMERA_H_
4 #include <vmath/vmath.h>
6 namespace goatgfx {
8 class Camera {
9 protected:
10 float roll;
12 mutable struct {
13 bool valid;
14 Matrix4x4 mat;
15 } mcache, mcache_inv;
17 virtual void calc_matrix(Matrix4x4 *mat) const = 0;
18 virtual void calc_inv_matrix(Matrix4x4 *mat) const;
20 void inval_cache() { mcache.valid = mcache_inv.valid = false; }
21 void set_glmat(const Matrix4x4 &m) const;
23 public:
24 Camera();
25 virtual ~Camera();
27 const Matrix4x4 &matrix() const;
28 const Matrix4x4 &inv_matrix() const;
30 void use() const;
31 void use_inverse() const;
33 // these do nothing, override to provide input handling
34 virtual void input_move(float x, float y, float z);
35 virtual void input_rotate(float x, float y, float z);
36 virtual void input_zoom(float factor);
37 };
39 class OrbitCamera : public Camera {
40 protected:
41 float theta, phi, rad;
43 void calc_matrix(Matrix4x4 *mat) const;
44 void calc_inv_matrix(Matrix4x4 *mat) const;
46 public:
47 OrbitCamera();
48 virtual ~OrbitCamera();
50 void input_rotate(float x, float y, float z);
51 void input_zoom(float factor);
52 };
54 class FpsCamera : public OrbitCamera {
55 protected:
56 Vector3 pos;
58 void calc_matrix(Matrix4x4 *mat) const;
59 void calc_inv_matrix(Matrix4x4 *mat) const;
61 public:
62 void input_move(float x, float y, float z);
64 const Vector3 &get_position() const;
65 };
67 class FlyCamera : public Camera {
68 private:
69 Vector3 pos;
70 Quaternion rot;
72 void calc_matrix(Matrix4x4 *mat) const;
73 //void calc_inv_matrix(Matrix4x4 *mat) const;
75 public:
76 FlyCamera();
78 const Vector3 &get_position() const;
79 const Quaternion &get_rotation() const;
81 void input_move(float x, float y, float z);
82 void input_rotate(float x, float y, float z);
83 };
86 class VRFpsCamera : public FpsCamera {
87 private:
88 float neck_eye_dist;
89 float prev_angles[3];
91 void calc_matrix(Matrix4x4 *mat) const;
92 void calc_inv_matrix(Matrix4x4 *mat) const;
94 public:
95 VRFpsCamera();
97 void track_vr();
98 };
100 } // namespace goatgfx
102 #endif // CAMERA_H_