]> git.tdb.fi Git - libs/gl.git/commitdiff
Add orthographic mode to Camera
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:08:14 +0000 (23:08 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 Nov 2014 21:35:21 +0000 (23:35 +0200)
source/camera.cpp
source/camera.h

index fca3ea33d504773d90e073c598175a33d9be2f46..a0c89e0efb6c2129354efa273545bb20605008b6 100644 (file)
@@ -7,6 +7,7 @@ namespace GL {
 
 Camera::Camera():
        fov(Geometry::Angle<float>::from_turns(0.125)),
+       height(0),
        aspect(4.0/3.0),
        clip_near(0.1),
        clip_far(10),
@@ -26,6 +27,15 @@ void Camera::set_field_of_view(const Geometry::Angle<float> &f)
        update_projection_matrix();
 }
 
+void Camera::set_orthographic(float w, float h)
+{
+       fov = Geometry::Angle<float>::zero();
+       height = h;
+       if(w)
+               aspect = w/h;
+       update_projection_matrix();
+}
+
 void Camera::set_aspect(float a)
 {
        aspect = a;
@@ -101,7 +111,10 @@ void Camera::update_projection_matrix()
        float right = frustum_w*(frustum_x+1.0f);
        float bottom = frustum_h*(frustum_y-1.0f);
        float top = frustum_h*(frustum_y+1.0f);
-       proj_matrix = Matrix::frustum(left, right, bottom, top, clip_near, clip_far);
+       if(fov>Geometry::Angle<float>::zero())
+               proj_matrix = Matrix::frustum(left, right, bottom, top, clip_near, clip_far);
+       else
+               proj_matrix = Matrix::ortho(left, right, bottom, top, clip_near, clip_far);
 }
 
 void Camera::update_object_matrix()
index bfcc2987d860b8e258e3f4fa6bcaad3906853295..9a525e6b1d51077af5f06874ba0a4a56a3b6505d 100644 (file)
@@ -11,6 +11,7 @@ class Camera
 {
 private:
        Geometry::Angle<float> fov;
+       float height;
        float aspect;
        // Some compilers have "near" and "far" keywords
        float clip_near;
@@ -28,6 +29,7 @@ public:
        Camera();
 
        void set_field_of_view(const Geometry::Angle<float> &);
+       void set_orthographic(float, float);
        void set_aspect(float);
        void set_depth_clip(float, float);
        void set_frustum_axis(float, float);