2
0
Эх сурвалжийг харах

Added event system to ode

rdb 17 жил өмнө
parent
commit
83073537fb

+ 5 - 2
panda/src/ode/Sources.pp

@@ -51,6 +51,7 @@
     odeRayGeom.I odeRayGeom.h \
     odeRayGeom.I odeRayGeom.h \
     odeTriMeshData.I odeTriMeshData.h \
     odeTriMeshData.I odeTriMeshData.h \
     odeTriMeshGeom.I odeTriMeshGeom.h \
     odeTriMeshGeom.I odeTriMeshGeom.h \
+    odeCollisionEntry.h \
     odeHelperStructs.h
     odeHelperStructs.h
 
 
   #define INCLUDED_SOURCES \
   #define INCLUDED_SOURCES \
@@ -74,7 +75,8 @@
     odeSphereGeom.cxx odeBoxGeom.cxx \
     odeSphereGeom.cxx odeBoxGeom.cxx \
     odePlaneGeom.cxx odeCappedCylinderGeom.cxx \
     odePlaneGeom.cxx odeCappedCylinderGeom.cxx \
     odeCylinderGeom.cxx odeRayGeom.cxx \
     odeCylinderGeom.cxx odeRayGeom.cxx \
-    odeTriMeshData.cxx  odeTriMeshGeom.cxx
+    odeTriMeshData.cxx  odeTriMeshGeom.cxx \
+    odeCollisionEntry.cxx
 
 
 
 
   #define INSTALL_HEADERS \
   #define INSTALL_HEADERS \
@@ -113,7 +115,8 @@
     odeCylinderGeom.I odeCylinderGeom.h \
     odeCylinderGeom.I odeCylinderGeom.h \
     odeRayGeom.I odeRayGeom.h \
     odeRayGeom.I odeRayGeom.h \
     odeTriMeshData.I odeTriMeshData.h \
     odeTriMeshData.I odeTriMeshData.h \
-    odeTriMeshGeom.I odeTriMeshGeom.h 
+    odeTriMeshGeom.I odeTriMeshGeom.h  \
+    odeCollisionEntry.h
 
 
   #define IGATESCAN all
   #define IGATESCAN all
 
 

+ 2 - 0
panda/src/ode/config_ode.cxx

@@ -45,6 +45,7 @@
 #include "odeRayGeom.h"
 #include "odeRayGeom.h"
 #include "odeTriMeshData.h"
 #include "odeTriMeshData.h"
 #include "odeTriMeshGeom.h"
 #include "odeTriMeshGeom.h"
+#include "odeCollisionEntry.h"
 #include "dconfig.h"
 #include "dconfig.h"
 
 
 Configure(config_ode);
 Configure(config_ode);
@@ -108,4 +109,5 @@ init_libode() {
   OdeRayGeom::init_type();
   OdeRayGeom::init_type();
   OdeTriMeshData::init_type();
   OdeTriMeshData::init_type();
   OdeTriMeshGeom::init_type();
   OdeTriMeshGeom::init_type();
+  OdeCollisionEntry::init_type();
 }
 }

+ 3 - 0
panda/src/ode/odeBody.h

@@ -25,6 +25,8 @@
 
 
 class OdeJoint;
 class OdeJoint;
 class OdeGeom;
 class OdeGeom;
+class OdeCollisionEntry;
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : OdeBody
 //       Class : OdeBody
 // Description : 
 // Description : 
@@ -32,6 +34,7 @@ class OdeGeom;
 class EXPCL_PANDAODE OdeBody : public TypedObject {
 class EXPCL_PANDAODE OdeBody : public TypedObject {
   friend class OdeJoint;
   friend class OdeJoint;
   friend class OdeGeom;
   friend class OdeGeom;
+  friend class OdeCollisionEntry;
 
 
 protected:
 protected:
   OdeBody(dBodyID id);
   OdeBody(dBodyID id);

+ 67 - 0
panda/src/ode/odeCollisionEntry.cxx

@@ -0,0 +1,67 @@
+// Filename: odeCollisionEntry.cxx
+// Created by:  pro-rsoft (05Mar09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#include "odeCollisionEntry.h"
+
+TypeHandle OdeCollisionEntry::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: OdeCollisionEntry::Constructor
+//       Access: Private
+//  Description: 
+////////////////////////////////////////////////////////////////////
+OdeCollisionEntry::
+OdeCollisionEntry() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: OdeCollisionEntry::get_geom1
+//       Access: Published
+//  Description: Returns the first geom in the collision.
+////////////////////////////////////////////////////////////////////
+const OdeGeom OdeCollisionEntry::
+get_geom1() {
+  return OdeGeom(_geom1);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: OdeCollisionEntry::get_geom2
+//       Access: Published
+//  Description: Returns the second geom in the collision.
+////////////////////////////////////////////////////////////////////
+const OdeGeom OdeCollisionEntry::
+get_geom2() {
+  return OdeGeom(_geom2);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: OdeCollisionEntry::get_body1
+//       Access: Published
+//  Description: Returns the first body in the collision.
+////////////////////////////////////////////////////////////////////
+const OdeBody OdeCollisionEntry::
+get_body1() {
+  return OdeBody(_body1);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: OdeCollisionEntry::get_body2
+//       Access: Published
+//  Description: Returns the second body in the collision.
+////////////////////////////////////////////////////////////////////
+const OdeBody OdeCollisionEntry::
+get_body2() {
+  return OdeBody(_body2);
+}
+

+ 66 - 0
panda/src/ode/odeCollisionEntry.h

@@ -0,0 +1,66 @@
+// Filename: odeCollisionEntry.h
+// Created by:  pro-rsoft (05Mar09)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) Carnegie Mellon University.  All rights reserved.
+//
+// All use of this software is subject to the terms of the revised BSD
+// license.  You should have received a copy of this license along
+// with this source code in a file named "LICENSE."
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef ODECOLLISIONENTRY_H
+#define ODECOLLISIONENTRY_H
+
+#include "pandabase.h"
+#include "typedReferenceCount.h"
+
+class OdeGeom;
+
+////////////////////////////////////////////////////////////////////
+//       Class : OdeCollisionEntry
+// Description : A class used to hold information about a collision
+//               that has occurred.
+////////////////////////////////////////////////////////////////////
+class EXPCL_PANDASKEL OdeCollisionEntry : public TypedReferenceCount {
+PUBLISHED:
+  virtual ~OdeCollisionEntry() {};
+  
+  const OdeGeom get_geom1();
+  const OdeGeom get_geom2();
+  const OdeBody get_body1();
+  const OdeBody get_body2();
+
+private:
+  OdeCollisionEntry();
+  dGeomID _geom1, _geom2;
+  dBodyID _body1, _body2;
+  LPoint3f *_points;
+
+public:
+  static TypeHandle get_class_type() {
+    return _type_handle;
+  }
+  static void init_type() {
+    TypedReferenceCount::init_type();
+    register_type(_type_handle, "OdeCollisionEntry",
+                  TypedReferenceCount::get_class_type());
+  }
+  virtual TypeHandle get_type() const {
+    return get_class_type();
+  }
+  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
+
+private:
+
+  static TypeHandle _type_handle;
+
+  friend class OdeSpace;
+};
+
+
+#endif
+

+ 3 - 0
panda/src/ode/odeGeom.h

@@ -37,6 +37,8 @@ class OdeSimpleSpace;
 class OdeHashSpace;
 class OdeHashSpace;
 class OdeQuadTreeSpace;
 class OdeQuadTreeSpace;
 
 
+class OdeCollisionEntry;
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : OdeGeom
 //       Class : OdeGeom
 // Description : 
 // Description : 
@@ -44,6 +46,7 @@ class OdeQuadTreeSpace;
 class EXPCL_PANDAODE OdeGeom : public TypedObject {
 class EXPCL_PANDAODE OdeGeom : public TypedObject {
   friend class OdeContactGeom;
   friend class OdeContactGeom;
   friend class OdeSpace;
   friend class OdeSpace;
+  friend class OdeCollisionEntry;
 
 
 protected:
 protected:
   OdeGeom(dGeomID id);
   OdeGeom(dGeomID id);

+ 10 - 0
panda/src/ode/odeSpace.I

@@ -91,3 +91,13 @@ is_enabled() {
   return dGeomIsEnabled((dGeomID)_id);
   return dGeomIsEnabled((dGeomID)_id);
 }
 }
 
 
+INLINE void OdeSpace::
+set_collision_event(const string &event_name) {
+  _collision_event = event_name;
+}
+
+INLINE string OdeSpace::
+get_collision_event() {
+  return _collision_event;
+}
+

+ 21 - 0
panda/src/ode/odeSpace.cxx

@@ -15,6 +15,8 @@
 #include "config_ode.h"
 #include "config_ode.h"
 #include "odeSpace.h"
 #include "odeSpace.h"
 
 
+#include "throw_event.h"
+
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
   #include "py_panda.h"
   #include "py_panda.h"
   #include "typedReferenceCount.h"
   #include "typedReferenceCount.h"
@@ -194,6 +196,16 @@ auto_callback(void *data, dGeomID o1, dGeomID o2)
         }
         }
         autoCallbackCounter += 1;
         autoCallbackCounter += 1;
 
 
+        PT(OdeCollisionEntry) entry;
+        if (!_collide_space->_collision_event.empty()) {
+          entry = new OdeCollisionEntry;
+          entry->_geom1 = o1;
+          entry->_geom2 = o2;
+          entry->_body1 = b1;
+          entry->_body2 = b2;
+          entry->_points = new LPoint3f[numc];
+        }
+        
         for(i=0; i < numc; i++)
         for(i=0; i < numc; i++)
         {
         {
             dJointID c = dJointCreateContact(_collide_world->get_id(), _collide_joint_group, contact + i);
             dJointID c = dJointCreateContact(_collide_world->get_id(), _collide_joint_group, contact + i);
@@ -201,6 +213,11 @@ auto_callback(void *data, dGeomID o1, dGeomID o2)
             {
             {
                 dJointAttach(c, b1, b2);
                 dJointAttach(c, b1, b2);
             }
             }
+            if (!_collide_space->_collision_event.empty()) {
+              entry->_points[i][0] = contact[i].geom.pos[0];
+              entry->_points[i][1] = contact[i].geom.pos[1];
+              entry->_points[i][2] = contact[i].geom.pos[2];
+            }
             // this creates contact position data for python. It is useful for debugging only 64 points are stored
             // this creates contact position data for python. It is useful for debugging only 64 points are stored
             if(contactCount < 64)
             if(contactCount < 64)
             {
             {
@@ -213,6 +230,10 @@ auto_callback(void *data, dGeomID o1, dGeomID o2)
             }
             }
         }
         }
         _collide_world->set_dampen_on_bodies(b1, b2, collide_params.dampen);
         _collide_world->set_dampen_on_bodies(b1, b2, collide_params.dampen);
+        
+        if (!_collide_space->_collision_event.empty()) {
+          throw_event(_collide_space->_collision_event, EventParameter(entry));
+        }
     }
     }
 
 
 }
 }

+ 4 - 0
panda/src/ode/odeSpace.h

@@ -101,6 +101,9 @@ PUBLISHED:
   int get_collide_id(dGeomID o1);
   int get_collide_id(dGeomID o1);
   int get_collide_id(OdeGeom& geom);
   int get_collide_id(OdeGeom& geom);
 
 
+  INLINE void set_collision_event(const string &event_name);
+  INLINE string get_collision_event();
+
 public:
 public:
   static void auto_callback(void*, dGeomID, dGeomID);
   static void auto_callback(void*, dGeomID, dGeomID);
 #ifdef HAVE_PYTHON
 #ifdef HAVE_PYTHON
@@ -115,6 +118,7 @@ public:
   static PyObject* _python_callback;
   static PyObject* _python_callback;
 #endif
 #endif
   static int contactCount;
   static int contactCount;
+  string _collision_event;
 
 
   static double contact_data[192]; // 64 times three
   static double contact_data[192]; // 64 times three
   static int contact_ids[128]; // 64 times two
   static int contact_ids[128]; // 64 times two

+ 1 - 0
panda/src/ode/pode_composite3.cxx

@@ -10,3 +10,4 @@
 #include "odeSimpleSpace.cxx"
 #include "odeSimpleSpace.cxx"
 #include "odeHashSpace.cxx"
 #include "odeHashSpace.cxx"
 #include "odeQuadTreeSpace.cxx"
 #include "odeQuadTreeSpace.cxx"
+#include "odeCollisionEntry.cxx"