]> git.tdb.fi Git - libs/gl.git/blob - source/camera.h
Make better use of matrix operations in Camera
[libs/gl.git] / source / camera.h
1 #ifndef MSP_GL_CAMERA_H_
2 #define MSP_GL_CAMERA_H_
3
4 #include "matrix.h"
5 #include "vector.h"
6
7 namespace Msp {
8 namespace GL {
9
10 class Camera
11 {
12 private:
13         Geometry::Angle<float> fov;
14         float aspect;
15         // Some compilers have "near" and "far" keywords
16         float clip_near;
17         float clip_far;
18         float frustum_x;
19         float frustum_y;
20         Vector3 position;
21         Vector3 look_dir;
22         Vector3 up_dir;
23         Matrix view_matrix;
24         Matrix object_matrix;
25
26 public:
27         Camera();
28
29         void set_field_of_view(const Geometry::Angle<float> &);
30         void set_aspect(float);
31         void set_depth_clip(float, float);
32         void set_frustum_axis(float, float);
33         const Geometry::Angle<float> &get_field_of_view() const { return fov; }
34         float get_aspect() const { return aspect; }
35         float get_near_clip() const { return clip_near; }
36         float get_far_clip() const { return clip_far; }
37
38         void set_position(const Vector3 &);
39         void set_look_direction(const Vector3 &);
40         void look_at(const Vector3 &);
41         void set_up_direction(const Vector3 &);
42         const Vector3 &get_position() const { return position; }
43         const Vector3 &get_look_direction() const { return look_dir; }
44         const Vector3 &get_up_direction() const { return up_dir; }
45
46         /** Deprecated alias for get_view_matrix. */
47         const Matrix &get_matrix() const { return get_view_matrix(); }
48
49         /** Returns the view matrix, used to transform coordinates from world space
50         to eye space. */
51         const Matrix &get_view_matrix() const { return view_matrix; }
52
53         /** Returns the object matrix, used to transform coordinates from eye space
54         to world space. */
55         const Matrix &get_object_matrix() const { return object_matrix; }
56
57         Vector3 project(const Vector4 &) const;
58         Vector3 project(const Vector3 &) const;
59         Vector4 unproject(const Vector4 &) const;
60
61         void apply() const;
62
63 private:
64         void update_object_matrix();
65 };
66
67 } // namespace GL
68 } // namespcae Msp
69
70 #endif