diff --git a/panda/src/collide/collisionParabola.cxx b/panda/src/collide/collisionParabola.cxx index ae477f273c..53d4cc4a10 100644 --- a/panda/src/collide/collisionParabola.cxx +++ b/panda/src/collide/collisionParabola.cxx @@ -129,7 +129,7 @@ compute_internal_bounds() const { // If p1 and p2 are sufficiently close, just put a sphere around // them. float d2 = pdelta.length_squared(); - if (d2 < 10.0f) { + if (d2 < collision_parabola_bounds_threshold * collision_parabola_bounds_threshold) { LPoint3f pmid = (p1 + p2) * 0.5f; return new BoundingSphere(pmid, csqrt(d2) * 0.5f); } @@ -165,9 +165,9 @@ compute_internal_bounds() const { // We compute a few points along the parabola to attempt to get the // minmax. - float min_z = p1[2]; - float max_z = p1[2]; - static const int num_points = 4; + float min_z = 0.0f; + float max_z = 0.0f; + int num_points = collision_parabola_bounds_sample; for (int i = 0; i < num_points; ++i) { double t = (double)(i + 1) / (double)(num_points + 1); LPoint3f p = psp.calc_point(get_t1() + t * (get_t2() - get_t1())); diff --git a/panda/src/collide/config_collide.cxx b/panda/src/collide/config_collide.cxx index 75ec8aea9e..7820e54d05 100644 --- a/panda/src/collide/config_collide.cxx +++ b/panda/src/collide/config_collide.cxx @@ -87,6 +87,19 @@ ConfigVariableBool flatten_collision_nodes "to be efficient, and combining CollisionNodes is likely " "to merge bounding volumes inappropriately.")); +ConfigVariableDouble collision_parabola_bounds_threshold +("collision-parabola-bounds-threshold", 10.0, + PRC_DESC("This is the threshold size for a CollisionParabola to " + "make a bounding box (BoundingHexahedron). If the parabola " + "is smaller than this, it will make a BoundingSphere instead, " + "which is much easier to make and will be good enough for " + "small parabolas.")); + +ConfigVariableInt collision_parabola_bounds_sample +("collision-parabola-bounds-sample", 10, + PRC_DESC("This is the number of points along a CollisionParabola to " + "sample in order to determine an accurate bounding box.")); + ConfigVariableInt fluid_cap_amount ("fluid-cap-amount", 100, PRC_DESC("ensures that fluid pos doesn't check beyond X feet")); diff --git a/panda/src/collide/config_collide.h b/panda/src/collide/config_collide.h index 4593368c0d..4b17861887 100644 --- a/panda/src/collide/config_collide.h +++ b/panda/src/collide/config_collide.h @@ -23,6 +23,7 @@ #include "notifyCategoryProxy.h" #include "configVariableBool.h" #include "configVariableInt.h" +#include "configVariableDouble.h" NotifyCategoryDecl(collide, EXPCL_PANDA_COLLIDE, EXPTP_PANDA_COLLIDE); @@ -30,6 +31,8 @@ extern EXPCL_PANDA_COLLIDE ConfigVariableBool respect_prev_transform; extern EXPCL_PANDA_COLLIDE ConfigVariableBool respect_effective_normal; extern EXPCL_PANDA_COLLIDE ConfigVariableBool allow_collider_multiple; extern EXPCL_PANDA_COLLIDE ConfigVariableBool flatten_collision_nodes; +extern EXPCL_PANDA_COLLIDE ConfigVariableDouble collision_parabola_bounds_threshold; +extern EXPCL_PANDA_COLLIDE ConfigVariableInt collision_parabola_bounds_sample; extern EXPCL_PANDA_COLLIDE ConfigVariableInt fluid_cap_amount; extern EXPCL_PANDA_COLLIDE void init_libcollide(); diff --git a/panda/src/mathutil/boundingBox.cxx b/panda/src/mathutil/boundingBox.cxx index 3287569c6c..a27d5d7a6b 100644 --- a/panda/src/mathutil/boundingBox.cxx +++ b/panda/src/mathutil/boundingBox.cxx @@ -596,7 +596,7 @@ contains_box(const BoundingBox *box) const { //////////////////////////////////////////////////////////////////// int BoundingBox:: contains_hexahedron(const BoundingHexahedron *hexahedron) const { - return contains_finite(hexahedron); + return hexahedron->contains_box(this) & ~IF_all; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/mathutil/boundingHexahedron.h b/panda/src/mathutil/boundingHexahedron.h index 425e0df5a1..29d79ff3de 100644 --- a/panda/src/mathutil/boundingHexahedron.h +++ b/panda/src/mathutil/boundingHexahedron.h @@ -116,6 +116,7 @@ private: static TypeHandle _type_handle; friend class BoundingSphere; + friend class BoundingBox; }; #include "boundingHexahedron.I"