00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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"
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
00037
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
00055 UserPersitentData *data = new UserPersitentData();
00056 data->node0 = node0;
00057 data->node1 = node1;
00058
00059 cp.m_userPersistentData = (void *)data;
00060
00061
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
00077
00078
00079 static bool
00080 contact_processed_callback(btManifoldPoint &cp,
00081 void *body0,
00082 void *body1) {
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 return false;
00099 }
00100
00101
00102
00103
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
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
00123 delete data;
00124
00125 return false;
00126 }
00127
00128 #endif // __BULLET_CONTACT_CALLBACKS_H__