]> git.tdb.fi Git - libs/gl.git/blob - source/render/camera.h
Rearrange soucre files into subdirectories
[libs/gl.git] / source / render / camera.h
1 #ifndef MSP_GL_CAMERA_H_
2 #define MSP_GL_CAMERA_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "placeable.h"
6
7 namespace Msp {
8 namespace GL {
9
10 class Camera: public Placeable
11 {
12 public:
13         class Loader: public DataFile::ObjectLoader<Camera>
14         {
15         public:
16                 Loader(Camera &);
17
18         private:
19                 void aspect_ratio(float);
20                 void depth_clip(float, float);
21                 void field_of_view(float);
22                 void look_at(float, float, float);
23                 void look_direction(float, float, float);
24                 void orthographic(float, float);
25                 void position(float, float, float);
26                 void up_direction(float, float, float);
27         };
28
29 private:
30         Geometry::Angle<float> fov;
31         float height;
32         float aspect;
33         // Some compilers have "near" and "far" keywords
34         float clip_near;
35         float clip_far;
36         float frustum_x;
37         float frustum_y;
38         Geometry::Angle<float> rotate;
39         Vector3 position;
40         Vector3 look_dir;
41         Vector3 up_dir;
42         Matrix view_matrix;
43         Matrix proj_matrix;
44
45 public:
46         Camera();
47
48         void set_field_of_view(const Geometry::Angle<float> &);
49         void set_orthographic(float, float);
50         void set_aspect_ratio(float);
51         void set_depth_clip(float, float);
52         void set_frustum_axis(float, float);
53         void set_frustum_rotation(const Geometry::Angle<float> &);
54         const Geometry::Angle<float> &get_field_of_view() const { return fov; }
55         bool is_orthographic() const { return fov==Geometry::Angle<float>::zero(); }
56         float get_orthographic_width() const { return height*aspect; }
57         float get_orthographic_height() const { return height; }
58         float get_aspect_ratio() const { return aspect; }
59         float get_near_clip() const { return clip_near; }
60         float get_far_clip() const { return clip_far; }
61         const Geometry::Angle<float> &get_frustum_rotation() const { return rotate; }
62
63         void set_position(const Vector3 &);
64         void set_look_direction(const Vector3 &);
65         void look_at(const Vector3 &);
66         void set_up_direction(const Vector3 &);
67         const Vector3 &get_position() const { return position; }
68         const Vector3 &get_look_direction() const { return look_dir; }
69         const Vector3 &get_up_direction() const { return up_dir; }
70
71         virtual void set_matrix(const Matrix &m) { set_object_matrix(m); }
72
73         /** Sets the position and orientation of the camera from an object matrix. */
74         void set_object_matrix(const Matrix &);
75
76         /** Returns the view matrix, used to transform coordinates from world space
77         to eye space. */
78         const Matrix &get_view_matrix() const { return view_matrix; }
79
80         /** Returns the object matrix, used to transform coordinates from eye space
81         to world space. */
82         const Matrix &get_object_matrix() const { return matrix; }
83
84         /** Returns the projection matrix. */
85         const Matrix &get_projection_matrix() const { return proj_matrix; }
86
87         Vector3 project(const Vector4 &) const;
88         Vector3 project(const Vector3 &) const;
89         Vector4 unproject(const Vector4 &) const;
90         Vector3 unproject(const Vector3 &) const;
91
92 private:
93         void update_projection_matrix();
94         void update_object_matrix();
95 };
96
97 } // namespace GL
98 } // namespcae Msp
99
100 #endif