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),
+ frustum_x(0),
+ frustum_y(0),
position(0, 0, 0),
look_dir(0, 0, -1),
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;
}
clip_far = f;
}
+void Camera::set_frustum_axis(float x, float y)
+{
+ frustum_x = x;
+ frustum_y = y;
+}
+
void Camera::set_position(const Vector3 &p)
{
position = 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;
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;
void Camera::apply() const
{
- MatrixStack::projection() = Matrix::perspective(fov, aspect, clip_near, clip_far);
+ float frustum_h = tan(fov/2.0f)*clip_near;
+ float frustum_w = frustum_h*aspect;
+ float left = frustum_w*(frustum_x-1.0f);
+ float right = frustum_w*(frustum_x+1.0f);
+ float bottom = frustum_h*(frustum_y-1.0f);
+ float top = frustum_h*(frustum_y+1.0f);
+ MatrixStack::projection() = Matrix::frustum(left, right, bottom, top, clip_near, clip_far);
MatrixStack::modelview() = matrix;
}