Bläddra i källkod

tighten up parabola collisions

David Rose 18 år sedan
förälder
incheckning
df36a1791a

+ 4 - 4
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()));

+ 13 - 0
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"));

+ 3 - 0
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();

+ 1 - 1
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;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 1 - 0
panda/src/mathutil/boundingHexahedron.h

@@ -116,6 +116,7 @@ private:
   static TypeHandle _type_handle;
 
   friend class BoundingSphere;
+  friend class BoundingBox;
 };
 
 #include "boundingHexahedron.I"