Quellcode durchsuchen

allow far plane to go further out

David Rose vor 15 Jahren
Ursprung
Commit
9d14c7867b
2 geänderte Dateien mit 10 neuen und 2 gelöschten Zeilen
  1. 8 0
      panda/src/gobj/config_gobj.cxx
  2. 2 2
      panda/src/gobj/lens.cxx

+ 8 - 0
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 "

+ 2 - 2
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);