From: Mikko Rasa Date: Tue, 18 Jun 2013 21:30:18 +0000 (+0300) Subject: Field of view is an angle too X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=60ca0094db80ea88ad546c98866f73a8d152e02b;p=libs%2Fgl.git Field of view is an angle too --- diff --git a/source/camera.cpp b/source/camera.cpp index 40613579..a3ab730d 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -6,7 +6,7 @@ namespace Msp { namespace GL { Camera::Camera(): - fov(M_PI/4), + fov(Geometry::Angle::from_turns(0.125)), aspect(4.0/3.0), clip_near(0.1), clip_far(10), @@ -15,7 +15,7 @@ Camera::Camera(): up_dir(0, 1, 0) { } -void Camera::set_field_of_view(float f) +void Camera::set_field_of_view(const Geometry::Angle &f) { fov = f; } @@ -58,7 +58,7 @@ void Camera::look_at(const Vector3 &p) Vector3 Camera::project(const Vector4 &p) const { - float frustum_h = tan(fov/2); + float frustum_h = tan(fov/2.0f); float frustum_w = frustum_h*aspect; float z_range = clip_far-clip_near; @@ -75,7 +75,7 @@ Vector3 Camera::project(const Vector3 &p) const Vector4 Camera::unproject(const Vector4 &p) const { - float frustum_h = tan(fov/2); + float frustum_h = tan(fov/2.0f); float frustum_w = frustum_h*aspect; float z_range = clip_far-clip_near; diff --git a/source/camera.h b/source/camera.h index d86725e6..11d42985 100644 --- a/source/camera.h +++ b/source/camera.h @@ -10,7 +10,7 @@ namespace GL { class Camera { private: - float fov; + Geometry::Angle fov; float aspect; // Some compilers have "near" and "far" keywords float clip_near; @@ -23,10 +23,10 @@ private: public: Camera(); - void set_field_of_view(float); + void set_field_of_view(const Geometry::Angle &); void set_aspect(float); void set_depth_clip(float, float); - float get_field_of_view() const { return fov; } + const Geometry::Angle &get_field_of_view() const { return fov; } float get_aspect() const { return aspect; } float get_near_clip() const { return clip_near; } float get_far_clip() const { return clip_far; } diff --git a/source/environmentmap.cpp b/source/environmentmap.cpp index 82e1f1d9..8a1dfe39 100644 --- a/source/environmentmap.cpp +++ b/source/environmentmap.cpp @@ -24,7 +24,7 @@ EnvironmentMap::EnvironmentMap(unsigned s, Renderable &r, Renderable &e): } // XXX Make the depth range configurable - camera.set_field_of_view(M_PI/2); + camera.set_field_of_view(Geometry::Angle::right()); camera.set_aspect(1); camera.set_depth_clip(0.1, 100); diff --git a/source/matrix.cpp b/source/matrix.cpp index 092d2c62..cac4a4fc 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -140,9 +140,9 @@ Matrix Matrix::frustum_centered(double w, double h, double n, double f) return frustum(-w/2, w/2, -h/2, h/2, n, f); } -Matrix Matrix::perspective(double h, double a, double n, double f) +Matrix Matrix::perspective(const Angle &h, double a, double n, double f) { - double hh = tan(h/2)*n; + double hh = tan(h/2.0)*n; return frustum(-hh*a, hh*a, -hh, hh, n, f); } diff --git a/source/matrix.h b/source/matrix.h index 539a613e..ce21b46f 100644 --- a/source/matrix.h +++ b/source/matrix.h @@ -61,7 +61,7 @@ public: static Matrix ortho_topleft(double, double); static Matrix frustum(double, double, double, double, double, double); static Matrix frustum_centered(double, double, double, double); - static Matrix perspective(double, double, double, double); + static Matrix perspective(const Angle &, double, double, double); }; class MatrixStack diff --git a/source/stereocombiner.cpp b/source/stereocombiner.cpp index 27cbb8f7..be0b01e9 100644 --- a/source/stereocombiner.cpp +++ b/source/stereocombiner.cpp @@ -6,8 +6,7 @@ namespace GL { StereoCombiner::StereoCombiner(): width_div(1), height_div(1), - keep_aspect(false), - fov(0) + keep_aspect(false) { } } // namespace GL diff --git a/source/stereocombiner.h b/source/stereocombiner.h index 10179309..a4b91bfb 100644 --- a/source/stereocombiner.h +++ b/source/stereocombiner.h @@ -1,6 +1,8 @@ #ifndef MSP_GL_STEREOCOMBINER_H_ #define MSP_GL_STEREOCOMBINER_H_ +#include + namespace Msp { namespace GL { @@ -12,7 +14,7 @@ protected: unsigned width_div; unsigned height_div; bool keep_aspect; - float fov; + Geometry::Angle fov; StereoCombiner(); public: @@ -21,7 +23,7 @@ public: unsigned get_width_divisor() const { return width_div; } unsigned get_height_divisor() const { return height_div; } bool is_aspect_kept() const { return keep_aspect; } - float get_field_of_view() const { return fov; } + const Geometry::Angle &get_field_of_view() const { return fov; } virtual void render(const Texture2D &, const Texture2D &) const = 0; }; diff --git a/source/stereoview.cpp b/source/stereoview.cpp index 9a4b0e0c..419e95c5 100644 --- a/source/stereoview.cpp +++ b/source/stereoview.cpp @@ -39,7 +39,7 @@ void StereoView::setup_frame() const EyeParams params; params.fov = combiner->get_field_of_view(); - if(!params.fov) + if(params.fov==Geometry::Angle::zero()) params.fov = base_camera.get_field_of_view(); params.aspect = base_camera.get_aspect(); diff --git a/source/stereoview.h b/source/stereoview.h index 63ee1834..4dce63b9 100644 --- a/source/stereoview.h +++ b/source/stereoview.h @@ -1,6 +1,7 @@ #ifndef MSP_GL_STEREOVIEW_H_ #define MSP_GL_STEREOVIEW_H_ +#include #include "camera.h" #include "framebuffer.h" #include "renderable.h" @@ -26,7 +27,7 @@ private: struct EyeParams { - float fov; + Geometry::Angle fov; float aspect; float near_clip; float far_clip;