From 02dad9779326e5b8acc1fddbaec3a2f36da15c16 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 25 Feb 2010 16:47:26 +0000 Subject: [PATCH] Fix projection calculations in camera.cpp --- source/camera.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/camera.cpp b/source/camera.cpp index c63fc930..ad1a3e94 100644 --- a/source/camera.cpp +++ b/source/camera.cpp @@ -78,27 +78,27 @@ void Camera::look_at(const Vector3 &p) Vector3 Camera::project(const Vector4 &p) const { - float near_h = tan(fov/2)*clip_near; - float near_w = near_h*aspect; + float frustum_h = tan(fov/2); + float frustum_w = frustum_h*aspect; float z_range = clip_far-clip_near; float eye_x = matrix[0]*p.x+matrix[4]*p.y+matrix[8]*p.z+matrix[12]*p.w; float eye_y = matrix[1]*p.x+matrix[5]*p.y+matrix[9]*p.z+matrix[13]*p.w; float eye_z = matrix[2]*p.x+matrix[6]*p.y+matrix[10]*p.z+matrix[14]*p.w; - return Vector3(eye_x/near_w/-eye_z, eye_y/near_h/-eye_z, + return Vector3(eye_x/frustum_w/-eye_z, eye_y/frustum_h/-eye_z, (clip_far+clip_near)/z_range+2*clip_far*clip_near/(eye_z*z_range)); } Vector4 Camera::unproject(const Vector4 &p) const { - float near_h = tan(fov/2)*clip_near; - float near_w = near_h*aspect; + float frustum_h = tan(fov/2); + float frustum_w = frustum_h*aspect; float z_range = clip_far-clip_near; float z = (2*clip_far*clip_near)/(p.z*z_range-(clip_far+clip_near))-matrix[14]*p.w; - float x = p.x*-z*near_w-matrix[12]*p.w; - float y = p.y*-z*near_h-matrix[13]*p.w; + float x = p.x*-z*frustum_w-matrix[12]*p.w; + float y = p.y*-z*frustum_h-matrix[13]*p.w; return Vector4(matrix[0]*x+matrix[1]*y+matrix[2]*z, matrix[4]*x+matrix[5]*y+matrix[6]*z, -- 2.43.0