X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcamera.cpp;fp=source%2Fcamera.cpp;h=274604f27f32e74833925d29828ec1628d22f36a;hb=fac4decfa4744ac6dc7f13c0348b0ec1ec80f6a4;hp=a3ab730d98ddd06ed167a8a0bd739b0e56554890;hpb=c87860db3b23a98eda1adfe59acddffdb6eb8420;p=libs%2Fgl.git diff --git a/source/camera.cpp b/source/camera.cpp index a3ab730d..274604f2 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -10,6 +10,8 @@ Camera::Camera(): 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) @@ -31,6 +33,12 @@ void Camera::set_depth_clip(float n, float 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; @@ -91,7 +99,13 @@ Vector4 Camera::unproject(const Vector4 &p) const 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; }