namespace GL {
Camera::Camera():
- fov(M_PI/4),
+ fov(Geometry::Angle<float>::from_turns(0.125)),
aspect(4.0/3.0),
clip_near(0.1),
clip_far(10),
up_dir(0, 1, 0)
{ }
-void Camera::set_field_of_view(float f)
+void Camera::set_field_of_view(const Geometry::Angle<float> &f)
{
fov = f;
}
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;
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;
class Camera
{
private:
- float fov;
+ Geometry::Angle<float> fov;
float aspect;
// Some compilers have "near" and "far" keywords
float clip_near;
public:
Camera();
- void set_field_of_view(float);
+ void set_field_of_view(const Geometry::Angle<float> &);
void set_aspect(float);
void set_depth_clip(float, float);
- float get_field_of_view() const { return fov; }
+ const Geometry::Angle<float> &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; }
}
// XXX Make the depth range configurable
- camera.set_field_of_view(M_PI/2);
+ camera.set_field_of_view(Geometry::Angle<float>::right());
camera.set_aspect(1);
camera.set_depth_clip(0.1, 100);
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);
}
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
StereoCombiner::StereoCombiner():
width_div(1),
height_div(1),
- keep_aspect(false),
- fov(0)
+ keep_aspect(false)
{ }
} // namespace GL
#ifndef MSP_GL_STEREOCOMBINER_H_
#define MSP_GL_STEREOCOMBINER_H_
+#include <msp/geometry/angle.h>
+
namespace Msp {
namespace GL {
unsigned width_div;
unsigned height_div;
bool keep_aspect;
- float fov;
+ Geometry::Angle<float> fov;
StereoCombiner();
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<float> &get_field_of_view() const { return fov; }
virtual void render(const Texture2D &, const Texture2D &) const = 0;
};
EyeParams params;
params.fov = combiner->get_field_of_view();
- if(!params.fov)
+ if(params.fov==Geometry::Angle<float>::zero())
params.fov = base_camera.get_field_of_view();
params.aspect = base_camera.get_aspect();
#ifndef MSP_GL_STEREOVIEW_H_
#define MSP_GL_STEREOVIEW_H_
+#include <msp/geometry/angle.h>
#include "camera.h"
#include "framebuffer.h"
#include "renderable.h"
struct EyeParams
{
- float fov;
+ Geometry::Angle<float> fov;
float aspect;
float near_clip;
float far_clip;