From 9d14c7867b760c90788a6f51de67cb80a17515cc Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 8 Jun 2010 22:49:44 +0000 Subject: [PATCH] allow far plane to go further out --- panda/src/gobj/config_gobj.cxx | 8 ++++++++ panda/src/gobj/lens.cxx | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/panda/src/gobj/config_gobj.cxx b/panda/src/gobj/config_gobj.cxx index c913dbc8b9..a0f1f52f3b 100644 --- a/panda/src/gobj/config_gobj.cxx +++ b/panda/src/gobj/config_gobj.cxx @@ -369,6 +369,14 @@ ConfigVariableDouble default_far ("default-far", 100000.0, PRC_DESC("The default far clipping distance for all cameras.")); +ConfigVariableDouble lens_far_limit +("lens-far-limit", 0.0000001, + PRC_DESC("This number is used to reduce the effect of numeric inaccuracies " + "in Lens::extrude(). It should be a very small, positive number, " + "almost zero; set it larger if Lens::extrude() returns values " + "that appear meaningless, and set it smaller if you appear to be " + "unable to move the far plane out far enough.")); + ConfigVariableDouble default_fov ("default-fov", 30.0, PRC_DESC("The default field of view in degrees for all cameras. This is " diff --git a/panda/src/gobj/lens.cxx b/panda/src/gobj/lens.cxx index 328960bc7a..f57366e0c1 100644 --- a/panda/src/gobj/lens.cxx +++ b/panda/src/gobj/lens.cxx @@ -1360,7 +1360,7 @@ extrude_impl(const LPoint3f &point2d, LPoint3f &near_point, LPoint3f &far_point) LVecBase4f full(point2d[0], point2d[1], -1.0f, 1.0f); full = projection_mat_inv.xform(full); - float recip_full3 = 1.0f / max(full[3], 0.00001f); + float recip_full3 = 1.0 / max((double)full[3], (double)lens_far_limit); near_point.set(full[0] * recip_full3, full[1] * recip_full3, full[2] * recip_full3); @@ -1374,7 +1374,7 @@ extrude_impl(const LPoint3f &point2d, LPoint3f &near_point, LPoint3f &far_point) // past infinity and comes back in behind the lens, which is just // crazy. Truncating it to zero keeps the far plane from moving // too far out. - float recip_full3 = 1.0f / max(full[3], 0.00001f); + float recip_full3 = 1.0 / max((double)full[3], (double)lens_far_limit); far_point.set(full[0] * recip_full3, full[1] * recip_full3, full[2] * recip_full3);