Panda3D
bulletContactResult.cxx
1 // Filename: bulletContactResult.cxx
2 // Created by: enn0x (08Mar10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "bulletContactResult.h"
16 
17 btManifoldPoint BulletContact::_empty;
18 BulletContact BulletContactResult::_empty;
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: BulletContact::Constructor
22 // Access: Published
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 BulletContact::
26 BulletContact() : _mp(_empty) {
27 
28  _node0 = NULL;
29  _node1 = NULL;
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: BulletContact::Copy Constructor
34 // Access: Published
35 // Description:
36 ////////////////////////////////////////////////////////////////////
37 BulletContact::
38 BulletContact(const BulletContact &other) : _mp(other._mp) {
39 
40  _node0 = other._node0;
41  _node1 = other._node1;
42  _part_id0 = other._part_id0;
43  _part_id1 = other._part_id1;
44  _idx0 = other._idx0;
45  _idx1 = other._idx1;
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: BulletContactResult::Constructor
50 // Access: Protected
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 BulletContactResult::
54 BulletContactResult() : btCollisionWorld::ContactResultCallback() {
55 
56 #if BT_BULLET_VERSION >= 281
57  _filter_cb = NULL;
58  _filter_proxy = NULL;
59  _filter_set = false;
60 #endif
61 }
62 
63 #if BT_BULLET_VERSION >= 281
64 ////////////////////////////////////////////////////////////////////
65 // Function: BulletContactResult::use_filter
66 // Access: Published
67 // Description:
68 ////////////////////////////////////////////////////////////////////
69 void BulletContactResult::
70 use_filter(btOverlapFilterCallback *cb, btBroadphaseProxy *proxy) {
71 
72  nassertv(cb);
73  nassertv(proxy);
74 
75  _filter_cb = cb;
76  _filter_proxy = proxy;
77  _filter_set = true;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: BulletContactResult::needsCollision
82 // Access: Published
83 // Description:
84 ////////////////////////////////////////////////////////////////////
85 bool BulletContactResult::
86 needsCollision(btBroadphaseProxy *proxy0) const {
87 
88  if (_filter_set) {
89  return _filter_cb->needBroadphaseCollision(proxy0, _filter_proxy);
90  }
91  else {
92  return true;
93  }
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: BulletContactResult::addSingleResult
98 // Access: Published
99 // Description:
100 ////////////////////////////////////////////////////////////////////
101 btScalar BulletContactResult::
102 addSingleResult(btManifoldPoint &mp,
103  const btCollisionObjectWrapper *wrap0, int part_id0, int idx0,
104  const btCollisionObjectWrapper *wrap1, int part_id1, int idx1) {
105 
106  const btCollisionObject *obj0 = wrap0->getCollisionObject();
107  const btCollisionObject *obj1 = wrap1->getCollisionObject();
108 
109  BulletContact contact;
110 
111  contact._mp = BulletManifoldPoint(mp);
112  contact._node0 = obj0 ? (PandaNode *)obj0->getUserPointer() : NULL;
113  contact._node1 = obj1 ? (PandaNode *)obj1->getUserPointer() : NULL;
114  contact._part_id0 = part_id0;
115  contact._part_id1 = part_id1;
116  contact._idx0 = idx0;
117  contact._idx1 = idx1;
118 
119  _contacts.push_back(contact);
120 
121  return 1.0f;
122 }
123 #else
124 ////////////////////////////////////////////////////////////////////
125 // Function: BulletContactResult::addSingleResult
126 // Access: Published
127 // Description:
128 ////////////////////////////////////////////////////////////////////
129 btScalar BulletContactResult::
130 addSingleResult(btManifoldPoint &mp,
131  const btCollisionObject *obj0, int part_id0, int idx0,
132  const btCollisionObject *obj1, int part_id1, int idx1) {
133 
134  BulletContact contact;
135 
136  contact._mp = BulletManifoldPoint(mp);
137  contact._node0 = obj0 ? (PandaNode *)obj0->getUserPointer() : NULL;
138  contact._node1 = obj1 ? (PandaNode *)obj1->getUserPointer() : NULL;
139  contact._part_id0 = part_id0;
140  contact._part_id1 = part_id1;
141  contact._idx0 = idx0;
142  contact._idx1 = idx1;
143 
144  _contacts.push_back(contact);
145 
146  return 1.0f;
147 }
148 #endif
149 
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72