Panda3D
bulletContactCallbacks.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file bulletContactCallbacks.h
10  * @author enn0x
11  * @date 2010-04-10
12  */
13 
14 #ifndef __BULLET_CONTACT_CALLBACKS_H__
15 #define __BULLET_CONTACT_CALLBACKS_H__
16 
17 #include "pandabase.h"
18 
19 #include "bullet_includes.h"
20 #include "bulletWorld.h"
22 #include "config_bullet.h" // required for: bullet_cat.debug()
23 
24 #include "event.h"
25 #include "eventQueue.h"
26 #include "eventParameter.h"
27 #include "pandaNode.h"
28 
30  PT(PandaNode) node0;
31  PT(PandaNode) node1;
32 };
33 
34 /**
35  *
36  */
37 static bool
38 contact_added_callback(btManifoldPoint &cp,
39 #if BT_BULLET_VERSION >= 281
40  const btCollisionObjectWrapper *wrap0,
41 #else
42  const btCollisionObject *obj0,
43 #endif
44  int id0,
45  int index0,
46 #if BT_BULLET_VERSION >= 281
47  const btCollisionObjectWrapper *wrap1,
48 #else
49  const btCollisionObject *obj1,
50 #endif
51  int id1,
52  int index1) {
53 
54  if (cp.m_userPersistentData == nullptr) {
55 
56 #if BT_BULLET_VERSION >= 281
57  PT(PandaNode) node0 = (PandaNode *)wrap0->getCollisionObject()->getUserPointer();
58  PT(PandaNode) node1 = (PandaNode *)wrap1->getCollisionObject()->getUserPointer();
59 #else
60  PT(PandaNode) node0 = (PandaNode *)obj0->getUserPointer();
61  PT(PandaNode) node1 = (PandaNode *)obj1->getUserPointer();
62 #endif
63 
64  if (bullet_cat.is_debug()) {
65  bullet_cat.debug() << "contact added: " << cp.m_userPersistentData << std::endl;
66  }
67 
68  // Gather persistent data
70  data->node0 = node0;
71  data->node1 = node1;
72 
73  cp.m_userPersistentData = (void *)data;
74 
75  // Send event
76  if (bullet_enable_contact_events) {
77 
78  Event *event = new Event("bullet-contact-added");
79  event->add_parameter(EventParameter(node0));
80  event->add_parameter(EventParameter(node1));
81 
82  EventQueue::get_global_event_queue()->queue_event(event);
83  }
84 
85  // Callback
86  if (bullet_contact_added_callback) {
87 
88  BulletManifoldPoint mp(cp);
89  BulletContactCallbackData cbdata(mp, node0, node1, id0, id1, index0, index1);
90 
91  bullet_contact_added_callback->do_callback(&cbdata);
92  }
93  }
94 
95  return true;
96 }
97 
98 /**
99  *
100  */
101 static bool
102 contact_processed_callback(btManifoldPoint &cp,
103  void *body0,
104  void *body1) {
105 
106 /*
107  btCollisionObject *obj0 = (btCollisionObject *)body0;
108  btCollisionObject *obj1 = (btCollisionObject *)body1;
109 
110  int flags0 = obj0->getCollisionFlags();
111  int flags1 = obj1->getCollisionFlags();
112 
113  if ((flags0 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
114  || (flags1 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)) {
115 
116  // do something...
117  }
118 */
119 
120  return false;
121 }
122 
123 /**
124  *
125  */
126 static bool
127 contact_destroyed_callback(void *userPersistentData) {
128  if (bullet_cat.is_debug()) {
129  bullet_cat.debug() << "contact removed: " << userPersistentData << std::endl;
130  }
131 
132  UserPersistentData *data = (UserPersistentData *)userPersistentData;
133 
134  // Send event
135  if (bullet_enable_contact_events) {
136 
137  Event *event = new Event("bullet-contact-destroyed");
138  event->add_parameter(EventParameter(data->node0));
139  event->add_parameter(EventParameter(data->node1));
140 
141  EventQueue::get_global_event_queue()->queue_event(event);
142  }
143 
144  // Delete persitent data
145  delete data;
146 
147  return false;
148 }
149 
150 #endif // __BULLET_CONTACT_CALLBACKS_H__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An optional parameter associated with an event.
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
Definition: eventQueue.I:19
A named event, possibly with parameters.
Definition: event.h:33
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.