]> git.tdb.fi Git - libs/gl.git/blob - source/camera.h
Rename various get/set_aspect functions to aspect_ratio
[libs/gl.git] / source / camera.h
1 #ifndef MSP_GL_CAMERA_H_
2 #define MSP_GL_CAMERA_H_
3
4 #include "placeable.h"
5
6 namespace Msp {
7 namespace GL {
8
9 class Camera: public Placeable
10 {
11 private:
12         Geometry::Angle<float> fov;
13         float height;
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         Geometry::Angle<float> rotate;
21         Vector3 position;
22         Vector3 look_dir;
23         Vector3 up_dir;
24         Matrix view_matrix;
25         Matrix proj_matrix;
26
27 public:
28         Camera();
29
30         void set_field_of_view(const Geometry::Angle<float> &);
31         void set_orthographic(float, float);
32         void set_aspect_ratio(float);
33         void set_depth_clip(float, float);
34         void set_frustum_axis(float, float);
35         void set_frustum_rotation(const Geometry::Angle<float> &);
36         const Geometry::Angle<float> &get_field_of_view() const { return fov; }
37         bool is_orthographic() const { return fov==Geometry::Angle<float>::zero(); }
38         float get_orthographic_width() const { return height*aspect; }
39         float get_orthographic_height() const { return height; }
40         float get_aspect_ratio() const { return aspect; }
41         float get_near_clip() const { return clip_near; }
42         float get_far_clip() const { return clip_far; }
43         const Geometry::Angle<float> &get_frustum_rotation() const { return rotate; }
44
45         // Deprecated, use set/get_aspect_ratio instead
46         void set_aspect(float a) { set_aspect_ratio(a); }
47         float get_aspect() const { return get_aspect_ratio(); }
48
49         void set_position(const Vector3 &);
50         void set_look_direction(const Vector3 &);
51         void look_at(const Vector3 &);
52         void set_up_direction(const Vector3 &);
53         const Vector3 &get_position() const { return position; }
54         const Vector3 &get_look_direction() const { return look_dir; }
55         const Vector3 &get_up_direction() const { return up_dir; }
56
57         virtual void set_matrix(const Matrix &m) { set_object_matrix(m); }
58
59         /** Sets the position and orientation of the camera from an object matrix. */
60         void set_object_matrix(const Matrix &);
61
62         /** Returns the view matrix, used to transform coordinates from world space
63         to eye space. */
64         const Matrix &get_view_matrix() const { return view_matrix; }
65
66         /** Returns the object matrix, used to transform coordinates from eye space
67         to world space. */
68         const Matrix &get_object_matrix() const { return matrix; }
69
70         /** Returns the projection matrix. */
71         const Matrix &get_projection_matrix() const { return proj_matrix; }
72
73         Vector3 project(const Vector4 &) const;
74         Vector3 project(const Vector3 &) const;
75         Vector4 unproject(const Vector4 &) const;
76         Vector3 unproject(const Vector3 &) const;
77
78         void apply() const;
79
80 private:
81         void update_projection_matrix();
82         void update_object_matrix();
83 };
84
85 } // namespace GL
86 } // namespcae Msp
87
88 #endif