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,