bloboland

annotate src/camera.h @ 1:cfe68befb7cc

some progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Dec 2012 23:43:03 +0200
parents
children
rev   line source
nuclear@1 1 #ifndef CAMERA_H_
nuclear@1 2 #define CAMERA_H_
nuclear@1 3
nuclear@1 4 #include "vmath/vmath.h"
nuclear@1 5
nuclear@1 6 class Camera {
nuclear@1 7 protected:
nuclear@1 8 mutable struct {
nuclear@1 9 bool valid;
nuclear@1 10 Matrix4x4 mat;
nuclear@1 11 } mcache, mcache_inv;
nuclear@1 12
nuclear@1 13 virtual void calc_matrix(Matrix4x4 *mat) const = 0;
nuclear@1 14 virtual void calc_inv_matrix(Matrix4x4 *mat) const;
nuclear@1 15
nuclear@1 16 void inval_cache() { mcache.valid = mcache_inv.valid = false; }
nuclear@1 17 void set_glmat(const Matrix4x4 &m) const;
nuclear@1 18
nuclear@1 19 public:
nuclear@1 20 Camera();
nuclear@1 21 virtual ~Camera();
nuclear@1 22
nuclear@1 23 const Matrix4x4 &matrix() const;
nuclear@1 24 const Matrix4x4 &inv_matrix() const;
nuclear@1 25
nuclear@1 26 void use() const;
nuclear@1 27 void use_inverse() const;
nuclear@1 28
nuclear@1 29 // these do nothing, override to provide input handling
nuclear@1 30 virtual void input_move(float x, float y, float z);
nuclear@1 31 virtual void input_rotate(float x, float y, float z);
nuclear@1 32 virtual void input_zoom(float factor);
nuclear@1 33 };
nuclear@1 34
nuclear@1 35 class OrbitCamera : public Camera {
nuclear@1 36 protected:
nuclear@1 37 float theta, phi, rad;
nuclear@1 38 float min_phi, max_phi;
nuclear@1 39
nuclear@1 40 void calc_matrix(Matrix4x4 *mat) const;
nuclear@1 41 void calc_inv_matrix(Matrix4x4 *mat) const;
nuclear@1 42
nuclear@1 43 public:
nuclear@1 44 OrbitCamera();
nuclear@1 45 virtual ~OrbitCamera();
nuclear@1 46
nuclear@1 47 void set_distance(float dist);
nuclear@1 48 void set_vertical_limits(float a, float b);
nuclear@1 49
nuclear@1 50 void input_rotate(float x, float y, float z);
nuclear@1 51 void input_zoom(float factor);
nuclear@1 52 };
nuclear@1 53
nuclear@1 54 class FpsCamera : public OrbitCamera {
nuclear@1 55 protected:
nuclear@1 56 Vector3 pos;
nuclear@1 57
nuclear@1 58 void calc_matrix(Matrix4x4 *mat) const;
nuclear@1 59 void calc_inv_matrix(Matrix4x4 *mat) const;
nuclear@1 60
nuclear@1 61 public:
nuclear@1 62 void input_move(float x, float y, float z);
nuclear@1 63
nuclear@1 64 const Vector3 &get_position() const;
nuclear@1 65 };
nuclear@1 66
nuclear@1 67
nuclear@1 68 class FlyCamera : public Camera {
nuclear@1 69 private:
nuclear@1 70 Vector3 pos;
nuclear@1 71 Quaternion rot;
nuclear@1 72
nuclear@1 73 void calc_matrix(Matrix4x4 *mat) const;
nuclear@1 74 //void calc_inv_matrix(Matrix4x4 *mat) const;
nuclear@1 75
nuclear@1 76 public:
nuclear@1 77 FlyCamera();
nuclear@1 78
nuclear@1 79 const Vector3 &get_position() const;
nuclear@1 80 const Quaternion &get_rotation() const;
nuclear@1 81
nuclear@1 82 void input_move(float x, float y, float z);
nuclear@1 83 void input_rotate(float x, float y, float z);
nuclear@1 84 };
nuclear@1 85
nuclear@1 86
nuclear@1 87 #endif // CAMERA_H_