Panda3D
 All Classes Functions Variables Enumerations
bulletContactCallbacks.h
00001 // Filename: bulletContactCallbacks.h
00002 // Created by:  enn0x (10Apr10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef __BULLET_CONTACT_CALLBACKS_H__
00016 #define __BULLET_CONTACT_CALLBACKS_H__
00017 
00018 #include "pandabase.h"
00019 
00020 #include "bullet_includes.h"
00021 
00022 #include "config_bullet.h" // required for: bullet_cat.debug()
00023 
00024 #include "event.h"
00025 #include "eventQueue.h"
00026 #include "eventParameter.h"
00027 #include "eventStorePandaNode.h"
00028 #include "pandaNode.h"
00029 
00030 struct UserPersitentData {
00031   PT(PandaNode) node0;
00032   PT(PandaNode) node1;
00033 };
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: contact_added_callback
00037 //  Description: 
00038 ////////////////////////////////////////////////////////////////////
00039 static bool
00040 contact_added_callback(btManifoldPoint &cp,
00041                        const btCollisionObject *obj0,
00042                        int id0,
00043                        int index0,
00044                        const btCollisionObject *obj1,
00045                        int id1,
00046                        int index1) {
00047 
00048   if (cp.m_userPersistentData == NULL) {
00049     PT(PandaNode) node0 = (PandaNode *)obj0->getUserPointer();
00050     PT(PandaNode) node1 = (PandaNode *)obj1->getUserPointer();
00051 
00052     bullet_cat.debug() << "contact added: " << cp.m_userPersistentData << endl;
00053 
00054     // Gather persistent data
00055     UserPersitentData *data = new UserPersitentData();
00056     data->node0 = node0;
00057     data->node1 = node1;
00058 
00059     cp.m_userPersistentData = (void *)data;
00060 
00061     // Send event
00062     if (bullet_enable_contact_events) {
00063 
00064       Event *event = new Event("bullet-contact-added");
00065       event->add_parameter(EventParameter(new EventStorePandaNode(node0)));
00066       event->add_parameter(EventParameter(new EventStorePandaNode(node1)));
00067 
00068       EventQueue::get_global_event_queue()->queue_event(event);
00069     }
00070   }
00071 
00072   return true;
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: contact_processed_callback
00077 //  Description: 
00078 ////////////////////////////////////////////////////////////////////
00079 static bool
00080 contact_processed_callback(btManifoldPoint &cp,
00081                            void *body0,
00082                            void *body1) {
00083 
00084 /*
00085   btCollisionObject *obj0 = (btCollisionObject *)body0;
00086   btCollisionObject *colobj1Obj1 = (btCollisionObject *)body1;
00087 
00088   int flags0 = obj0->getCollisionFlags();
00089   int flags1 = obj1->getCollisionFlags();
00090 
00091   if ((flags0 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
00092    || (flags1 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)) {
00093 
00094     // do something...
00095   }
00096 */
00097 
00098   return false;
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: contact_destroyed_callback
00103 //  Description: 
00104 ////////////////////////////////////////////////////////////////////
00105 static bool
00106 contact_destroyed_callback(void *userPersistentData) {
00107 
00108   bullet_cat.debug() << "contact removed: " << userPersistentData << endl;
00109 
00110   UserPersitentData *data = (UserPersitentData *)userPersistentData;
00111 
00112   // Send event
00113   if (bullet_enable_contact_events) {
00114 
00115     Event *event = new Event("bullet-contact-destroyed");
00116     event->add_parameter(EventParameter(new EventStorePandaNode(data->node0)));
00117     event->add_parameter(EventParameter(new EventStorePandaNode(data->node1)));
00118 
00119     EventQueue::get_global_event_queue()->queue_event(event);
00120   }
00121 
00122   // Delete persitent data
00123   delete data;
00124 
00125   return false;
00126 }
00127 
00128 #endif // __BULLET_CONTACT_CALLBACKS_H__
 All Classes Functions Variables Enumerations