Просмотр исходного кода

fluid collision fix: extend bounding spheres of fluid-moved solids to include previous position

Darren Ranalli 18 лет назад
Родитель
Сommit
b2e5b098c8
1 измененных файлов с 8 добавлено и 12 удалено
  1. 8 12
      panda/src/collide/collisionLevelStateBase.cxx

+ 8 - 12
panda/src/collide/collisionLevelStateBase.cxx

@@ -64,6 +64,7 @@ prepare_collider(const ColliderDef &def, const NodePath &root) {
   if (!bv->is_of_type(GeometricBoundingVolume::get_class_type())) {
     _local_bounds.push_back((GeometricBoundingVolume *)NULL);
   } else {
+    LPoint3f pos_delta = def._node_path.get_pos_delta(root);
     GeometricBoundingVolume *gbv;
     DCAST_INTO_V(gbv, bv->make_copy());
 
@@ -71,20 +72,15 @@ prepare_collider(const ColliderDef &def, const NodePath &root) {
     // world.  The bounding volume should be extended by the object's
     // motion relative to each object it is considering a collision
     // with.  That makes things complicated!
-    /*
-    if (def._delta != LVector3f::zero()) {
+    if (pos_delta != LVector3f::zero()) {
       // If the node has a delta, we have to include the starting
-      // point in the volume as well.
-
-      // Strictly speaking, we should actually transform gbv backward
-      // by the delta(), and extend by *that* volume, instead of
-      // just extending by the single point at -get_velocity().
-      // However, assuming the solids within a moving CollisionNode
-      // tend to be near the origin, this will generally produce the
-      // same results, and is much easier to compute.
-      gbv->extend_by(LPoint3f(-def._delta));
+      // position in the volume as well.
+      LMatrix4f inv_trans = LMatrix4f::translate_mat(-pos_delta);
+      GeometricBoundingVolume *gbv_prev;
+      DCAST_INTO_V(gbv_prev, bv->make_copy());
+      gbv_prev->xform(inv_trans);
+      gbv->extend_by(gbv_prev);
     }
-    */
 
     CPT(TransformState) rel_transform = def._node_path.get_transform(root.get_parent());
     gbv->xform(rel_transform->get_mat());