goat3dgfx

annotate src/camera.h @ 11:d061fe1a31ec

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