Browse Source

part of the physics changes

Dave Schuyler 22 years ago
parent
commit
73d21894bf

+ 10 - 0
panda/src/collide/collisionHandlerFloor.cxx

@@ -142,6 +142,7 @@ handle_entries() {
             mat(3, 2) += adjust;
             mat(3, 2) += adjust;
             def.set_mat(mat);
             def.set_mat(mat);
           }
           }
+          apply_linear_force(def, LVector3f(0.0f, 0.0f, adjust));
         } else {
         } else {
           if (collide_cat.is_spam()) {
           if (collide_cat.is_spam()) {
             collide_cat.spam()
             collide_cat.spam()
@@ -154,3 +155,12 @@ handle_entries() {
 
 
   return okflag;
   return okflag;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionHandlerFloor::apply_linear_force
+//       Access: Protected, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CollisionHandlerFloor::
+apply_linear_force(ColliderDef &def, const LVector3f &force) {
+}

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

@@ -45,6 +45,7 @@ PUBLISHED:
 
 
 protected:
 protected:
   virtual bool handle_entries();
   virtual bool handle_entries();
+  virtual void apply_linear_force(ColliderDef &def, const LVector3f &force);
 
 
 private:
 private:
   float _offset;
   float _offset;

+ 0 - 4
panda/src/collide/collisionHandlerPhysical.cxx

@@ -34,10 +34,8 @@ void CollisionHandlerPhysical::ColliderDef::
 get_mat(LMatrix4f &mat) const {
 get_mat(LMatrix4f &mat) const {
   if (_node != (PandaNode *)NULL) {
   if (_node != (PandaNode *)NULL) {
     mat = _node->get_transform()->get_mat();
     mat = _node->get_transform()->get_mat();
-
   } else if (_drive_interface != (DriveInterface *)NULL) {
   } else if (_drive_interface != (DriveInterface *)NULL) {
     mat = _drive_interface->get_mat();
     mat = _drive_interface->get_mat();
-
   } else {
   } else {
     collide_cat.error()
     collide_cat.error()
       << "Invalid CollisionHandlerPhysical::ColliderDef\n";
       << "Invalid CollisionHandlerPhysical::ColliderDef\n";
@@ -54,11 +52,9 @@ void CollisionHandlerPhysical::ColliderDef::
 set_mat(const LMatrix4f &mat) {
 set_mat(const LMatrix4f &mat) {
   if (_node != (PandaNode *)NULL) {
   if (_node != (PandaNode *)NULL) {
     _node->set_transform(TransformState::make_mat(mat));
     _node->set_transform(TransformState::make_mat(mat));
-
   } else if (_drive_interface != (DriveInterface *)NULL) {
   } else if (_drive_interface != (DriveInterface *)NULL) {
     _drive_interface->set_mat(mat);
     _drive_interface->set_mat(mat);
     _drive_interface->force_dgraph();
     _drive_interface->force_dgraph();
-
   } else {
   } else {
     collide_cat.error()
     collide_cat.error()
       << "Invalid CollisionHandlerPhysical::ColliderDef\n";
       << "Invalid CollisionHandlerPhysical::ColliderDef\n";

+ 4 - 3
panda/src/collide/collisionHandlerPhysical.h

@@ -45,14 +45,13 @@ public:
   virtual bool end_group();
   virtual bool end_group();
 
 
 PUBLISHED:
 PUBLISHED:
-  void add_collider_drive(CollisionNode *node, DriveInterface *drive_interface);
   void add_collider_node(CollisionNode *node, PandaNode *target);
   void add_collider_node(CollisionNode *node, PandaNode *target);
   bool remove_collider(CollisionNode *node);
   bool remove_collider(CollisionNode *node);
   bool has_collider(CollisionNode *node) const;
   bool has_collider(CollisionNode *node) const;
   void clear_colliders();
   void clear_colliders();
 
 
-protected:
-  virtual bool handle_entries()=0;
+  // add_collider_drive() is becoming obsolete.  If you need let, let us know.
+  void add_collider_drive(CollisionNode *node, DriveInterface *drive_interface);
 
 
 protected:
 protected:
   typedef pvector< PT(CollisionEntry) > Entries;
   typedef pvector< PT(CollisionEntry) > Entries;
@@ -75,6 +74,8 @@ protected:
   typedef pmap<PT(CollisionNode), ColliderDef> Colliders;
   typedef pmap<PT(CollisionNode), ColliderDef> Colliders;
   Colliders _colliders;
   Colliders _colliders;
 
 
+  virtual bool handle_entries()=0;
+  virtual void apply_linear_force(ColliderDef &def, const LVector3f &force)=0;
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {

+ 18 - 9
panda/src/collide/collisionHandlerPusher.cxx

@@ -90,7 +90,6 @@ handle_entries() {
         << "CollisionHandlerPusher doesn't know about "
         << "CollisionHandlerPusher doesn't know about "
         << *from_node << ", disabling.\n";
         << *from_node << ", disabling.\n";
       okflag = false;
       okflag = false;
-
     } else {
     } else {
       ColliderDef &def = (*ci).second;
       ColliderDef &def = (*ci).second;
       if (!def.is_valid()) {
       if (!def.is_valid()) {
@@ -98,7 +97,6 @@ handle_entries() {
           << "Removing invalid collider " << *from_node << " from "
           << "Removing invalid collider " << *from_node << " from "
           << get_type() << "\n";
           << get_type() << "\n";
         _colliders.erase(ci);
         _colliders.erase(ci);
-
       } else {
       } else {
         // How to apply multiple shoves from different solids onto the
         // How to apply multiple shoves from different solids onto the
         // same collider?  One's first intuition is to vector sum all
         // same collider?  One's first intuition is to vector sum all
@@ -119,14 +117,13 @@ handle_entries() {
           
           
           if (!entry->has_from_surface_normal() ||
           if (!entry->has_from_surface_normal() ||
               !entry->has_from_depth()) {
               !entry->has_from_depth()) {
-#ifndef NDEBUG          
+            #ifndef NDEBUG          
             if (collide_cat.is_debug()) {
             if (collide_cat.is_debug()) {
               collide_cat.debug()
               collide_cat.debug()
                 << "Cannot shove on " << *from_node << " for collision into "
                 << "Cannot shove on " << *from_node << " for collision into "
                 << *entry->get_into_node() << "; no normal/depth information.\n";
                 << *entry->get_into_node() << "; no normal/depth information.\n";
             }
             }
-#endif
-            
+            #endif            
           } else {
           } else {
             // Shove it just enough to clear the volume.
             // Shove it just enough to clear the volume.
             if (entry->get_from_depth() != 0.0f) {
             if (entry->get_from_depth() != 0.0f) {
@@ -145,14 +142,14 @@ handle_entries() {
               sd._valid = true;
               sd._valid = true;
               sd._entry = entry;
               sd._entry = entry;
               
               
-#ifndef NDEBUG          
+              #ifndef NDEBUG          
               if (collide_cat.is_debug()) {
               if (collide_cat.is_debug()) {
                 collide_cat.debug()
                 collide_cat.debug()
                   << "Shove on " << *from_node << " from "
                   << "Shove on " << *from_node << " from "
                   << *entry->get_into_node() << ": " << sd._vector
                   << *entry->get_into_node() << ": " << sd._vector
                   << " times " << sd._length << "\n";
                   << " times " << sd._length << "\n";
               }
               }
-#endif
+              #endif
               
               
               shoves.push_back(sd);
               shoves.push_back(sd);
             }
             }
@@ -237,20 +234,22 @@ handle_entries() {
           
           
           // Now we can determine the net shove.
           // Now we can determine the net shove.
           LVector3f net_shove(0.0f, 0.0f, 0.0f);
           LVector3f net_shove(0.0f, 0.0f, 0.0f);
+          LVector3f force_normal(0.0f, 0.0f, 0.0f);
           for (si = shoves.begin(); si != shoves.end(); ++si) {
           for (si = shoves.begin(); si != shoves.end(); ++si) {
             const ShoveData &sd = (*si);
             const ShoveData &sd = (*si);
             if (sd._valid) {
             if (sd._valid) {
               net_shove += sd._vector * sd._length;
               net_shove += sd._vector * sd._length;
+              force_normal += sd._vector;
             }
             }
           }
           }
 
 
-#ifndef NDEBUG          
+          #ifndef NDEBUG          
           if (collide_cat.is_debug()) {
           if (collide_cat.is_debug()) {
             collide_cat.debug()
             collide_cat.debug()
               << "Net shove on " << *from_node << " is: "
               << "Net shove on " << *from_node << " is: "
               << net_shove << "\n";
               << net_shove << "\n";
           }
           }
-#endif
+          #endif
           
           
           if (def._node != (PandaNode *)NULL) {
           if (def._node != (PandaNode *)NULL) {
             // If we are adjusting a plain PandaNode, get the
             // If we are adjusting a plain PandaNode, get the
@@ -267,6 +266,7 @@ handle_entries() {
             def.get_mat(mat);
             def.get_mat(mat);
             def.set_mat(LMatrix4f::translate_mat(net_shove) * mat);
             def.set_mat(LMatrix4f::translate_mat(net_shove) * mat);
           }
           }
+          apply_linear_force(def, force_normal);
         }
         }
       }
       }
     }
     }
@@ -274,3 +274,12 @@ handle_entries() {
 
 
   return okflag;
   return okflag;
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: CollisionHandlerPusher::apply_linear_force
+//       Access: Protected, Virtual
+//  Description: 
+////////////////////////////////////////////////////////////////////
+void CollisionHandlerPusher::
+apply_linear_force(ColliderDef &, const LVector3f &) {
+}

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

@@ -40,6 +40,7 @@ PUBLISHED:
 
 
 protected:
 protected:
   virtual bool handle_entries();
   virtual bool handle_entries();
+  virtual void apply_linear_force(ColliderDef &def, const LVector3f &force);
 
 
 private:
 private:
   bool _horizontal;
   bool _horizontal;