Panda3D
Loading...
Searching...
No Matches
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 */
37static bool
38contact_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
89 BulletContactCallbackData cbdata(mp, node0, node1, id0, id1, index0, index1);
90
91 // Release the world mutex object so that bullet methods can be called from the callback.
92 LightMutex &mutex = BulletWorld::get_global_lock();
93
94 mutex.release();
95 bullet_contact_added_callback->do_callback(&cbdata);
96 mutex.acquire();
97 }
98 }
99
100 return true;
101}
102
103/**
104 *
105 */
106static bool
107contact_processed_callback(btManifoldPoint &cp,
108 void *body0,
109 void *body1) {
110
111/*
112 btCollisionObject *obj0 = (btCollisionObject *)body0;
113 btCollisionObject *obj1 = (btCollisionObject *)body1;
114
115 int flags0 = obj0->getCollisionFlags();
116 int flags1 = obj1->getCollisionFlags();
117
118 if ((flags0 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)
119 || (flags1 & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)) {
120
121 // do something...
122 }
123*/
124
125 return false;
126}
127
128/**
129 *
130 */
131static bool
132contact_destroyed_callback(void *userPersistentData) {
133 if (bullet_cat.is_debug()) {
134 bullet_cat.debug() << "contact removed: " << userPersistentData << std::endl;
135 }
136
137 UserPersistentData *data = (UserPersistentData *)userPersistentData;
138
139 // Send event
140 if (bullet_enable_contact_events) {
141
142 Event *event = new Event("bullet-contact-destroyed");
143 event->add_parameter(EventParameter(data->node0));
144 event->add_parameter(EventParameter(data->node1));
145
146 EventQueue::get_global_event_queue()->queue_event(event);
147 }
148
149 // Delete persitent data
150 delete data;
151
152 return false;
153}
154
155#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
void release() const
Releases the lightMutex.
void acquire() const
Grabs the lightMutex if it is available.
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition lightMutex.h:41
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.