symmetry
diff src/camera.h @ 0:a90a71a74f0b
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 25 Feb 2014 19:53:34 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/camera.h Tue Feb 25 19:53:34 2014 +0200 1.3 @@ -0,0 +1,102 @@ 1.4 +#ifndef CAMERA_H_ 1.5 +#define CAMERA_H_ 1.6 + 1.7 +#include <vmath/vmath.h> 1.8 + 1.9 +namespace goatgfx { 1.10 + 1.11 +class Camera { 1.12 +protected: 1.13 + float roll; 1.14 + 1.15 + mutable struct { 1.16 + bool valid; 1.17 + Matrix4x4 mat; 1.18 + } mcache, mcache_inv; 1.19 + 1.20 + virtual void calc_matrix(Matrix4x4 *mat) const = 0; 1.21 + virtual void calc_inv_matrix(Matrix4x4 *mat) const; 1.22 + 1.23 + void inval_cache() { mcache.valid = mcache_inv.valid = false; } 1.24 + void set_glmat(const Matrix4x4 &m) const; 1.25 + 1.26 +public: 1.27 + Camera(); 1.28 + virtual ~Camera(); 1.29 + 1.30 + const Matrix4x4 &matrix() const; 1.31 + const Matrix4x4 &inv_matrix() const; 1.32 + 1.33 + void use() const; 1.34 + void use_inverse() const; 1.35 + 1.36 + // these do nothing, override to provide input handling 1.37 + virtual void input_move(float x, float y, float z); 1.38 + virtual void input_rotate(float x, float y, float z); 1.39 + virtual void input_zoom(float factor); 1.40 +}; 1.41 + 1.42 +class OrbitCamera : public Camera { 1.43 +protected: 1.44 + float theta, phi, rad; 1.45 + 1.46 + void calc_matrix(Matrix4x4 *mat) const; 1.47 + void calc_inv_matrix(Matrix4x4 *mat) const; 1.48 + 1.49 +public: 1.50 + OrbitCamera(); 1.51 + virtual ~OrbitCamera(); 1.52 + 1.53 + void input_rotate(float x, float y, float z); 1.54 + void input_zoom(float factor); 1.55 +}; 1.56 + 1.57 +class FpsCamera : public OrbitCamera { 1.58 +protected: 1.59 + Vector3 pos; 1.60 + 1.61 + void calc_matrix(Matrix4x4 *mat) const; 1.62 + void calc_inv_matrix(Matrix4x4 *mat) const; 1.63 + 1.64 +public: 1.65 + void input_move(float x, float y, float z); 1.66 + 1.67 + const Vector3 &get_position() const; 1.68 +}; 1.69 + 1.70 +class FlyCamera : public Camera { 1.71 +private: 1.72 + Vector3 pos; 1.73 + Quaternion rot; 1.74 + 1.75 + void calc_matrix(Matrix4x4 *mat) const; 1.76 + //void calc_inv_matrix(Matrix4x4 *mat) const; 1.77 + 1.78 +public: 1.79 + FlyCamera(); 1.80 + 1.81 + const Vector3 &get_position() const; 1.82 + const Quaternion &get_rotation() const; 1.83 + 1.84 + void input_move(float x, float y, float z); 1.85 + void input_rotate(float x, float y, float z); 1.86 +}; 1.87 + 1.88 + 1.89 +class VRFpsCamera : public FpsCamera { 1.90 +private: 1.91 + float neck_eye_dist; 1.92 + float prev_angles[3]; 1.93 + 1.94 + void calc_matrix(Matrix4x4 *mat) const; 1.95 + void calc_inv_matrix(Matrix4x4 *mat) const; 1.96 + 1.97 +public: 1.98 + VRFpsCamera(); 1.99 + 1.100 + void track_vr(); 1.101 +}; 1.102 + 1.103 +} // namespace goatgfx 1.104 + 1.105 +#endif // CAMERA_H_