Bläddra i källkod

is in outer space

Dave Schuyler 22 år sedan
förälder
incheckning
5da93cd1d8

+ 14 - 0
panda/src/collide/collisionHandlerGravity.I

@@ -49,6 +49,8 @@ get_offset() const {
 //               The object might not necessarily be at rest.  Use
 //               is_on_ground() if you want to know whether the
 //               object is on the ground and at rest.
+//
+//               See Also: is_in_outer_space()
 ////////////////////////////////////////////////////////////////////
 INLINE float CollisionHandlerGravity::
 get_airborne_height() const {
@@ -68,6 +70,18 @@ is_on_ground() const {
   return get_airborne_height() == 0.0f && _current_velocity == 0.0f;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionHandlerGravity::is_in_outer_space
+//       Access: Public
+//  Description: The object is in outer space if there is no
+//               ground/floor anywhere below it (I guess you could
+//               also say the height is infinite).
+////////////////////////////////////////////////////////////////////
+INLINE bool CollisionHandlerGravity::
+is_in_outer_space() const {
+  return _outer_space;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CollisionHandlerGravity::get_impact_velocity
 //       Access: Public

+ 5 - 0
panda/src/collide/collisionHandlerGravity.cxx

@@ -38,6 +38,7 @@ CollisionHandlerGravity() {
   _gravity = 32.174f;
   _current_velocity = 0.0f;
   _max_velocity = 400.0f;
+  _outer_space = false;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -63,6 +64,7 @@ CollisionHandlerGravity::
 bool CollisionHandlerGravity::
 handle_entries() {
   bool okflag = true;
+  _outer_space = true;
 
   FromEntries::const_iterator fi;
   for (fi = _from_entries.begin(); fi != _from_entries.end(); ++fi) {
@@ -87,6 +89,9 @@ handle_entries() {
         float max_height = 0.0f;
         
         Entries::const_iterator ei;
+        if (ei != entries.end()) {
+          _outer_space = false;
+        }
         for (ei = entries.begin(); ei != entries.end(); ++ei) {
           CollisionEntry *entry = (*ei);
           nassertr(entry != (CollisionEntry *)NULL, false);

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

@@ -42,6 +42,7 @@ PUBLISHED:
 
   INLINE float get_airborne_height() const;
   INLINE bool is_on_ground() const;
+  INLINE bool is_in_outer_space() const;
   INLINE float get_impact_velocity() const;
 
   INLINE void add_velocity(float velocity);
@@ -65,6 +66,7 @@ private:
   float _gravity;
   float _current_velocity;
   float _max_velocity;
+  bool _outer_space;
 
 
 public: