From 8076fedd64e67d97de21e67242f180955ca2c653 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 27 Sep 2013 22:20:44 +0000 Subject: [PATCH] fix incorrect depth computation for OSphereLens --- panda/src/distort/oSphereLens.cxx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/panda/src/distort/oSphereLens.cxx b/panda/src/distort/oSphereLens.cxx index 5fe3d7ace5..1d9ceb7f12 100755 --- a/panda/src/distort/oSphereLens.cxx +++ b/panda/src/distort/oSphereLens.cxx @@ -102,21 +102,19 @@ bool OSphereLens:: do_project(const Lens::CData *lens_cdata, const LPoint3 &point3d, LPoint3 &point2d) const { // First, account for any rotations, etc. on the lens. LPoint3 p = point3d * do_get_lens_mat_inv(lens_cdata) * do_get_projection_mat(lens_cdata); - PN_stdfloat dist = p.length(); + + // To compute the x position on the frame, we only need to consider + // the angle of the vector about the Z axis. Project the vector + // into the XY plane to do this. + LVector2 xy(p[0], p[1]); + + PN_stdfloat dist = xy.length(); if (dist == 0.0f) { point2d.set(0.0f, 0.0f, 0.0f); return false; } - LPoint3 v3 = p / dist; - PN_stdfloat focal_length = do_get_focal_length(lens_cdata); - - // To compute the x position on the frame, we only need to consider - // the angle of the vector about the Z axis. Project the vector - // into the XY plane to do this. - LVector2 xy(v3[0], v3[1]); - // Compute the depth as a linear distance in the range 0 .. 1. PN_stdfloat z = (dist - do_get_near(lens_cdata)) / (do_get_far(lens_cdata) - do_get_near(lens_cdata));