oculus1
diff src/camera.h @ 5:681046a82ed2
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 15 Sep 2013 05:01:38 +0300 |
parents | c7b50cd7184c |
children | b66b54a68dfd |
line diff
1.1 --- a/src/camera.h Sun Sep 15 04:47:12 2013 +0300 1.2 +++ b/src/camera.h Sun Sep 15 05:01:38 2013 +0300 1.3 @@ -1,8 +1,69 @@ 1.4 #ifndef CAMERA_H_ 1.5 #define CAMERA_H_ 1.6 1.7 +#include "vmath/vmath.h" 1.8 + 1.9 class Camera { 1.10 +protected: 1.11 + mutable struct { 1.12 + bool valid; 1.13 + Matrix4x4 mat; 1.14 + } mcache, mcache_inv; 1.15 + 1.16 + virtual void calc_matrix(Matrix4x4 *mat) const = 0; 1.17 + virtual void calc_inv_matrix(Matrix4x4 *mat) const; 1.18 + 1.19 + void inval_cache() { mcache.valid = mcache_inv.valid = false; } 1.20 + void set_glmat(const Matrix4x4 &m) const; 1.21 + 1.22 public: 1.23 + Camera(); 1.24 + virtual ~Camera(); 1.25 + 1.26 + const Matrix4x4 &matrix() const; 1.27 + const Matrix4x4 &inv_matrix() const; 1.28 + 1.29 + void use() const; 1.30 + void use_inverse() const; 1.31 + 1.32 + // these do nothing, override to provide input handling 1.33 + virtual void input_move(float x, float y, float z); 1.34 + virtual void input_rotate(float x, float y, float z); 1.35 + virtual void input_zoom(float factor); 1.36 }; 1.37 1.38 +class OrbitCamera : public Camera { 1.39 +private: 1.40 + float theta, phi, rad; 1.41 + 1.42 + void calc_matrix(Matrix4x4 *mat) const; 1.43 + void calc_inv_matrix(Matrix4x4 *mat) const; 1.44 + 1.45 +public: 1.46 + OrbitCamera(); 1.47 + virtual ~OrbitCamera(); 1.48 + 1.49 + void input_rotate(float x, float y, float z); 1.50 + void input_zoom(float factor); 1.51 +}; 1.52 + 1.53 +class FlyCamera : public Camera { 1.54 +private: 1.55 + Vector3 pos; 1.56 + Quaternion rot; 1.57 + 1.58 + void calc_matrix(Matrix4x4 *mat) const; 1.59 + //void calc_inv_matrix(Matrix4x4 *mat) const; 1.60 + 1.61 +public: 1.62 + FlyCamera(); 1.63 + 1.64 + const Vector3 &get_position() const; 1.65 + const Quaternion &get_rotation() const; 1.66 + 1.67 + void input_move(float x, float y, float z); 1.68 + void input_rotate(float x, float y, float z); 1.69 +}; 1.70 + 1.71 + 1.72 #endif // CAMERA_H_