bloboland

view src/camera.h @ 3:a39c301cdcce

terrain raytracing pretty much done
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 16 Dec 2012 14:24:16 +0200
parents
children
line source
1 #ifndef CAMERA_H_
2 #define CAMERA_H_
4 #include "vmath/vmath.h"
6 class Camera {
7 protected:
8 mutable struct {
9 bool valid;
10 Matrix4x4 mat;
11 } mcache, mcache_inv;
13 virtual void calc_matrix(Matrix4x4 *mat) const = 0;
14 virtual void calc_inv_matrix(Matrix4x4 *mat) const;
16 void inval_cache() { mcache.valid = mcache_inv.valid = false; }
17 void set_glmat(const Matrix4x4 &m) const;
19 public:
20 Camera();
21 virtual ~Camera();
23 const Matrix4x4 &matrix() const;
24 const Matrix4x4 &inv_matrix() const;
26 void use() const;
27 void use_inverse() const;
29 // these do nothing, override to provide input handling
30 virtual void input_move(float x, float y, float z);
31 virtual void input_rotate(float x, float y, float z);
32 virtual void input_zoom(float factor);
33 };
35 class OrbitCamera : public Camera {
36 protected:
37 float theta, phi, rad;
38 float min_phi, max_phi;
40 void calc_matrix(Matrix4x4 *mat) const;
41 void calc_inv_matrix(Matrix4x4 *mat) const;
43 public:
44 OrbitCamera();
45 virtual ~OrbitCamera();
47 void set_distance(float dist);
48 void set_vertical_limits(float a, float b);
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 };
68 class FlyCamera : public Camera {
69 private:
70 Vector3 pos;
71 Quaternion rot;
73 void calc_matrix(Matrix4x4 *mat) const;
74 //void calc_inv_matrix(Matrix4x4 *mat) const;
76 public:
77 FlyCamera();
79 const Vector3 &get_position() const;
80 const Quaternion &get_rotation() const;
82 void input_move(float x, float y, float z);
83 void input_rotate(float x, float y, float z);
84 };
87 #endif // CAMERA_H_