]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/camera.h
Rearrange soucre files into subdirectories
[libs/gl.git] / source / render / camera.h
diff --git a/source/render/camera.h b/source/render/camera.h
new file mode 100644 (file)
index 0000000..b10ccb9
--- /dev/null
@@ -0,0 +1,100 @@
+#ifndef MSP_GL_CAMERA_H_
+#define MSP_GL_CAMERA_H_
+
+#include <msp/datafile/objectloader.h>
+#include "placeable.h"
+
+namespace Msp {
+namespace GL {
+
+class Camera: public Placeable
+{
+public:
+       class Loader: public DataFile::ObjectLoader<Camera>
+       {
+       public:
+               Loader(Camera &);
+
+       private:
+               void aspect_ratio(float);
+               void depth_clip(float, float);
+               void field_of_view(float);
+               void look_at(float, float, float);
+               void look_direction(float, float, float);
+               void orthographic(float, float);
+               void position(float, float, float);
+               void up_direction(float, float, float);
+       };
+
+private:
+       Geometry::Angle<float> fov;
+       float height;
+       float aspect;
+       // Some compilers have "near" and "far" keywords
+       float clip_near;
+       float clip_far;
+       float frustum_x;
+       float frustum_y;
+       Geometry::Angle<float> rotate;
+       Vector3 position;
+       Vector3 look_dir;
+       Vector3 up_dir;
+       Matrix view_matrix;
+       Matrix proj_matrix;
+
+public:
+       Camera();
+
+       void set_field_of_view(const Geometry::Angle<float> &);
+       void set_orthographic(float, float);
+       void set_aspect_ratio(float);
+       void set_depth_clip(float, float);
+       void set_frustum_axis(float, float);
+       void set_frustum_rotation(const Geometry::Angle<float> &);
+       const Geometry::Angle<float> &get_field_of_view() const { return fov; }
+       bool is_orthographic() const { return fov==Geometry::Angle<float>::zero(); }
+       float get_orthographic_width() const { return height*aspect; }
+       float get_orthographic_height() const { return height; }
+       float get_aspect_ratio() const { return aspect; }
+       float get_near_clip() const { return clip_near; }
+       float get_far_clip() const { return clip_far; }
+       const Geometry::Angle<float> &get_frustum_rotation() const { return rotate; }
+
+       void set_position(const Vector3 &);
+       void set_look_direction(const Vector3 &);
+       void look_at(const Vector3 &);
+       void set_up_direction(const Vector3 &);
+       const Vector3 &get_position() const { return position; }
+       const Vector3 &get_look_direction() const { return look_dir; }
+       const Vector3 &get_up_direction() const { return up_dir; }
+
+       virtual void set_matrix(const Matrix &m) { set_object_matrix(m); }
+
+       /** Sets the position and orientation of the camera from an object matrix. */
+       void set_object_matrix(const Matrix &);
+
+       /** Returns the view matrix, used to transform coordinates from world space
+       to eye space. */
+       const Matrix &get_view_matrix() const { return view_matrix; }
+
+       /** Returns the object matrix, used to transform coordinates from eye space
+       to world space. */
+       const Matrix &get_object_matrix() const { return matrix; }
+
+       /** Returns the projection matrix. */
+       const Matrix &get_projection_matrix() const { return proj_matrix; }
+
+       Vector3 project(const Vector4 &) const;
+       Vector3 project(const Vector3 &) const;
+       Vector4 unproject(const Vector4 &) const;
+       Vector3 unproject(const Vector3 &) const;
+
+private:
+       void update_projection_matrix();
+       void update_object_matrix();
+};
+
+} // namespace GL
+} // namespcae Msp
+
+#endif