Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
2aad981804

+ 12 - 5
panda/src/collide/collisionHandlerQueue.cxx

@@ -13,14 +13,17 @@ class CollisionEntrySorter {
 public:
   CollisionEntrySorter(CollisionEntry *entry) {
     _entry = entry;
-    _dist = (entry->get_from_intersection_point() - LPoint3f::origin()).length();
+    LVector3f vec = 
+      entry->get_from_intersection_point() - 
+      entry->get_from()->get_collision_origin();
+    _dist2 = vec.length_squared();
   }
   bool operator < (const CollisionEntrySorter &other) const {
-    return _dist < other._dist;
+    return _dist2 < other._dist2;
   }
 
   CollisionEntry *_entry;
-  double _dist;
+  float _dist2;
 };
 
 ////////////////////////////////////////////////////////////////////
@@ -62,7 +65,9 @@ add_entry(CollisionEntry *entry) {
 //       Access: Public
 //  Description: Sorts all the detected collisions front-to-back by
 //               from_intersection_point() so that those intersection
-//               points closest to the origin appear first.
+//               points closest to the collider's origin (e.g., the
+//               center of the CollisionSphere, or the point_a of a
+//               CollisionSegment) appear first.
 ////////////////////////////////////////////////////////////////////
 void CollisionHandlerQueue::
 sort_entries() {
@@ -80,7 +85,9 @@ sort_entries() {
   sort(sorter.begin(), sorter.end());
   nassertv(sorter.size() == _entries.size());
 
-  // Now that they're sorted, get them back.
+  // Now that they're sorted, get them back.  We do this in two steps,
+  // building up a temporary vector first, so we don't accidentally
+  // delete all the entries when the pointers go away.
   Entries sorted_entries;
   sorted_entries.reserve(sorter.size());
   Sorter::const_iterator si;

+ 16 - 0
panda/src/collide/collisionPlane.cxx

@@ -58,6 +58,22 @@ xform(const LMatrix4f &mat) {
   mark_bound_stale();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionPlane::get_collision_origin
+//       Access: Public, Virtual
+//  Description: Returns the point in space deemed to be the "origin"
+//               of the solid for collision purposes.  The closest
+//               intersection point to this origin point is considered
+//               to be the most significant.
+////////////////////////////////////////////////////////////////////
+LPoint3f CollisionPlane::
+get_collision_origin() const {
+  // No real sensible origin exists for a plane.  We return 0, 0, 0,
+  // without even bothering to ensure that that point exists on the
+  // plane.
+  return LPoint3f::origin();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionPlane::output
 //       Access: Public, Virtual

+ 2 - 0
panda/src/collide/collisionPlane.h

@@ -34,6 +34,8 @@ public:
 		    const CollisionSolid *into) const;
 
   virtual void xform(const LMatrix4f &mat);
+  virtual LPoint3f get_collision_origin() const;
+
   virtual void output(ostream &out) const;
 
 PUBLISHED:

+ 13 - 0
panda/src/collide/collisionPolygon.cxx

@@ -153,6 +153,19 @@ xform(const LMatrix4f &mat) {
   mark_bound_stale();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionPolygon::get_collision_origin
+//       Access: Public, Virtual
+//  Description: Returns the point in space deemed to be the "origin"
+//               of the solid for collision purposes.  The closest
+//               intersection point to this origin point is considered
+//               to be the most significant.
+////////////////////////////////////////////////////////////////////
+LPoint3f CollisionPolygon::
+get_collision_origin() const {
+  return to_3d(_median);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionPolygon::output
 //       Access: Public, Virtual

+ 1 - 0
panda/src/collide/collisionPolygon.h

@@ -42,6 +42,7 @@ public:
 		    const CollisionSolid *into) const;
 
   virtual void xform(const LMatrix4f &mat);
+  virtual LPoint3f get_collision_origin() const;
 
   virtual void output(ostream &out) const;
 

+ 13 - 0
panda/src/collide/collisionRay.cxx

@@ -52,6 +52,19 @@ xform(const LMatrix4f &mat) {
   mark_bound_stale();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionRay::get_collision_origin
+//       Access: Public, Virtual
+//  Description: Returns the point in space deemed to be the "origin"
+//               of the solid for collision purposes.  The closest
+//               intersection point to this origin point is considered
+//               to be the most significant.
+////////////////////////////////////////////////////////////////////
+LPoint3f CollisionRay::
+get_collision_origin() const {
+  return get_origin();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionRay::output
 //       Access: Public, Virtual

+ 1 - 0
panda/src/collide/collisionRay.h

@@ -37,6 +37,7 @@ public:
 		    const CollisionSolid *into) const;
 
   virtual void xform(const LMatrix4f &mat);
+  virtual LPoint3f get_collision_origin() const;
 
   virtual void output(ostream &out) const;
 

+ 13 - 0
panda/src/collide/collisionSegment.cxx

@@ -52,6 +52,19 @@ xform(const LMatrix4f &mat) {
   mark_bound_stale();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionSegment::get_collision_origin
+//       Access: Public, Virtual
+//  Description: Returns the point in space deemed to be the "origin"
+//               of the solid for collision purposes.  The closest
+//               intersection point to this origin point is considered
+//               to be the most significant.
+////////////////////////////////////////////////////////////////////
+LPoint3f CollisionSegment::
+get_collision_origin() const {
+  return get_point_a();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionSegment::output
 //       Access: Public, Virtual

+ 1 - 0
panda/src/collide/collisionSegment.h

@@ -40,6 +40,7 @@ public:
 		    const CollisionSolid *into) const;
 
   virtual void xform(const LMatrix4f &mat);
+  virtual LPoint3f get_collision_origin() const;
 
   virtual void output(ostream &out) const;
 

+ 1 - 0
panda/src/collide/collisionSolid.h

@@ -42,6 +42,7 @@ public:
   virtual ~CollisionSolid();
 
   virtual CollisionSolid *make_copy()=0;
+  virtual LPoint3f get_collision_origin() const=0;
 
 PUBLISHED:
   INLINE void set_tangible(bool tangible);

+ 13 - 0
panda/src/collide/collisionSphere.cxx

@@ -60,6 +60,19 @@ xform(const LMatrix4f &mat) {
   mark_bound_stale();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionSphere::get_collision_origin
+//       Access: Public, Virtual
+//  Description: Returns the point in space deemed to be the "origin"
+//               of the solid for collision purposes.  The closest
+//               intersection point to this origin point is considered
+//               to be the most significant.
+////////////////////////////////////////////////////////////////////
+LPoint3f CollisionSphere::
+get_collision_origin() const {
+  return get_center();
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionSphere::output
 //       Access: Public, Virtual

+ 1 - 0
panda/src/collide/collisionSphere.h

@@ -29,6 +29,7 @@ public:
 		    const CollisionSolid *into) const;
 
   virtual void xform(const LMatrix4f &mat);
+  virtual LPoint3f get_collision_origin() const;
 
   virtual void output(ostream &out) const;