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  bullet_cat.debug() << "contact added: " << cp.m_userPersistentData << std::endl;
65 
66  // Gather persistent data
68  data->node0 = node0;
69  data->node1 = node1;
70 
71  cp.m_userPersistentData = (void *)data;
72 
73  // Send event
74  if (bullet_enable_contact_events) {
75 
76  Event *event = new Event("bullet-contact-added");
77  event->add_parameter(EventParameter(node0));
78  event->add_parameter(EventParameter(node1));
79 
80  EventQueue::get_global_event_queue()->queue_event(event);
81  }
82 
83  // Callback
84  if (bullet_contact_added_callback) {
85 
86  BulletManifoldPoint mp(cp);
87  BulletContactCallbackData cbdata(mp, node0, node1, id0, id1, index0, index1);
88 
89  bullet_contact_added_callback->do_callback(&cbdata);
90  }
91  }
92 
93  return true;
94 }
95 
96 /**
97  *
98  */
99 static bool
100 contact_processed_callback(btManifoldPoint &cp,
101  void *body0,
102  void *body1) {
103 
104 /*
105  btCollisionObject *obj0 = (btCollisionObject *)body0;
106  btCollisionObject *obj1 = (btCollisionObject *)body1;
107 
108  int flags0 = obj0->getCollisionFlags();
109  int flags1 = obj1->getCollisionFlags();
110 
111  if ((flags0 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
112  || (flags1 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)) {
113 
114  // do something...
115  }
116 */
117 
118  return false;
119 }
120 
121 /**
122  *
123  */
124 static bool
125 contact_destroyed_callback(void *userPersistentData) {
126 
127  bullet_cat.debug() << "contact removed: " << userPersistentData << std::endl;
128 
129  UserPersistentData *data = (UserPersistentData *)userPersistentData;
130 
131  // Send event
132  if (bullet_enable_contact_events) {
133 
134  Event *event = new Event("bullet-contact-destroyed");
135  event->add_parameter(EventParameter(data->node0));
136  event->add_parameter(EventParameter(data->node1));
137 
138  EventQueue::get_global_event_queue()->queue_event(event);
139  }
140 
141  // Delete persitent data
142  delete data;
143 
144  return false;
145 }
146 
147 #endif // __BULLET_CONTACT_CALLBACKS_H__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
An optional parameter associated with an event.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static EventQueue * get_global_event_queue()
Returns a pointer to the one global EventQueue object.
Definition: eventQueue.I:19
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.
A named event, possibly with parameters.
Definition: event.h:33
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.