diff options
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionDispatcher.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionDispatcher.cs | 560 |
1 files changed, 280 insertions, 280 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionDispatcher.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionDispatcher.cs index 75d35b0..336defd 100644 --- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionDispatcher.cs +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionDispatcher.cs | |||
@@ -1,280 +1,280 @@ | |||
1 | /* | 1 | /* |
2 | Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru | 2 | Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru |
3 | Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com | 3 | Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com |
4 | 4 | ||
5 | This software is provided 'as-is', without any express or implied | 5 | This software is provided 'as-is', without any express or implied |
6 | warranty. In no event will the authors be held liable for any damages | 6 | warranty. In no event will the authors be held liable for any damages |
7 | arising from the use of this software. | 7 | arising from the use of this software. |
8 | 8 | ||
9 | Permission is granted to anyone to use this software for any purpose, | 9 | Permission is granted to anyone to use this software for any purpose, |
10 | including commercial applications, and to alter it and redistribute it | 10 | including commercial applications, and to alter it and redistribute it |
11 | freely, subject to the following restrictions: | 11 | freely, subject to the following restrictions: |
12 | 12 | ||
13 | 1. The origin of this software must not be misrepresented; you must not | 13 | 1. The origin of this software must not be misrepresented; you must not |
14 | claim that you wrote the original software. If you use this software | 14 | claim that you wrote the original software. If you use this software |
15 | in a product, an acknowledgment in the product documentation would be | 15 | in a product, an acknowledgment in the product documentation would be |
16 | appreciated but is not required. | 16 | appreciated but is not required. |
17 | 2. Altered source versions must be plainly marked as such, and must not be | 17 | 2. Altered source versions must be plainly marked as such, and must not be |
18 | misrepresented as being the original software. | 18 | misrepresented as being the original software. |
19 | 3. This notice may not be removed or altered from any source distribution. | 19 | 3. This notice may not be removed or altered from any source distribution. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | using System; | 22 | using System; |
23 | using System.Collections.Generic; | 23 | using System.Collections.Generic; |
24 | using System.Text; | 24 | using System.Text; |
25 | using MonoXnaCompactMaths; | 25 | using MonoXnaCompactMaths; |
26 | 26 | ||
27 | namespace XnaDevRu.BulletX | 27 | namespace XnaDevRu.BulletX |
28 | { | 28 | { |
29 | public delegate void NearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo); | 29 | public delegate void NearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo); |
30 | 30 | ||
31 | public class CollisionDispatcher : IDispatcher | 31 | public class CollisionDispatcher : IDispatcher |
32 | { | 32 | { |
33 | private List<PersistentManifold> _manifolds = new List<PersistentManifold>(); | 33 | private List<PersistentManifold> _manifolds = new List<PersistentManifold>(); |
34 | 34 | ||
35 | //private bool _useIslands; | 35 | //private bool _useIslands; |
36 | private NearCallback _nearCallback; | 36 | private NearCallback _nearCallback; |
37 | 37 | ||
38 | //private ManifoldResult _defaultManifoldResult; | 38 | //private ManifoldResult _defaultManifoldResult; |
39 | 39 | ||
40 | private CollisionAlgorithmCreateFunction[,] _doubleDispatch = new CollisionAlgorithmCreateFunction[(int)BroadphaseNativeTypes.MaxBroadphaseCollisionTypes, (int)BroadphaseNativeTypes.MaxBroadphaseCollisionTypes]; | 40 | private CollisionAlgorithmCreateFunction[,] _doubleDispatch = new CollisionAlgorithmCreateFunction[(int)BroadphaseNativeTypes.MaxBroadphaseCollisionTypes, (int)BroadphaseNativeTypes.MaxBroadphaseCollisionTypes]; |
41 | 41 | ||
42 | //default CreationFunctions, filling the m_doubleDispatch table | 42 | //default CreationFunctions, filling the m_doubleDispatch table |
43 | private CollisionAlgorithmCreateFunction _convexConvexCreateFunc; | 43 | private CollisionAlgorithmCreateFunction _convexConvexCreateFunc; |
44 | private CollisionAlgorithmCreateFunction _convexConcaveCreateFunc; | 44 | private CollisionAlgorithmCreateFunction _convexConcaveCreateFunc; |
45 | private CollisionAlgorithmCreateFunction _swappedConvexConcaveCreateFunc; | 45 | private CollisionAlgorithmCreateFunction _swappedConvexConcaveCreateFunc; |
46 | private CollisionAlgorithmCreateFunction _compoundCreateFunc; | 46 | private CollisionAlgorithmCreateFunction _compoundCreateFunc; |
47 | private CollisionAlgorithmCreateFunction _swappedCompoundCreateFunc; | 47 | private CollisionAlgorithmCreateFunction _swappedCompoundCreateFunc; |
48 | private CollisionAlgorithmCreateFunction _emptyCreateFunc; | 48 | private CollisionAlgorithmCreateFunction _emptyCreateFunc; |
49 | 49 | ||
50 | private int _count; | 50 | private int _count; |
51 | private static int _manifoldCount = 0; | 51 | private static int _manifoldCount = 0; |
52 | 52 | ||
53 | public CollisionDispatcher() | 53 | public CollisionDispatcher() |
54 | { | 54 | { |
55 | NearCallback = DefaultNearCallback; | 55 | NearCallback = DefaultNearCallback; |
56 | //_useIslands = true; | 56 | //_useIslands = true; |
57 | //default CreationFunctions, filling the m_doubleDispatch table | 57 | //default CreationFunctions, filling the m_doubleDispatch table |
58 | _convexConvexCreateFunc = new ConvexConvexAlgorithm.CreateFunc(); | 58 | _convexConvexCreateFunc = new ConvexConvexAlgorithm.CreateFunc(); |
59 | _convexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.CreateFunc(); | 59 | _convexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.CreateFunc(); |
60 | _swappedConvexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.SwappedCreateFunc(); | 60 | _swappedConvexConcaveCreateFunc = new ConvexConcaveCollisionAlgorithm.SwappedCreateFunc(); |
61 | _compoundCreateFunc = new CompoundCollisionAlgorithm.CreateFunc(); | 61 | _compoundCreateFunc = new CompoundCollisionAlgorithm.CreateFunc(); |
62 | _swappedCompoundCreateFunc = new CompoundCollisionAlgorithm.SwappedCreateFunc(); | 62 | _swappedCompoundCreateFunc = new CompoundCollisionAlgorithm.SwappedCreateFunc(); |
63 | _emptyCreateFunc = new EmptyAlgorithm.CreateFunc(); | 63 | _emptyCreateFunc = new EmptyAlgorithm.CreateFunc(); |
64 | 64 | ||
65 | for (BroadphaseNativeTypes i = BroadphaseNativeTypes.Box; i < BroadphaseNativeTypes.MaxBroadphaseCollisionTypes; i++) | 65 | for (BroadphaseNativeTypes i = BroadphaseNativeTypes.Box; i < BroadphaseNativeTypes.MaxBroadphaseCollisionTypes; i++) |
66 | { | 66 | { |
67 | for (BroadphaseNativeTypes j = BroadphaseNativeTypes.Box; j < BroadphaseNativeTypes.MaxBroadphaseCollisionTypes; j++) | 67 | for (BroadphaseNativeTypes j = BroadphaseNativeTypes.Box; j < BroadphaseNativeTypes.MaxBroadphaseCollisionTypes; j++) |
68 | { | 68 | { |
69 | _doubleDispatch[(int)i, (int)j] = FindCreateFunction(i, j); | 69 | _doubleDispatch[(int)i, (int)j] = FindCreateFunction(i, j); |
70 | if (_doubleDispatch[(int)i, (int)j] == null) | 70 | if (_doubleDispatch[(int)i, (int)j] == null) |
71 | throw new BulletException(); | 71 | throw new BulletException(); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | } | 74 | } |
75 | 75 | ||
76 | public int Count { get { return _count; } set { _count = value; } } | 76 | public int Count { get { return _count; } set { _count = value; } } |
77 | public int ManifoldCount { get { return _manifolds.Count; } } | 77 | public int ManifoldCount { get { return _manifolds.Count; } } |
78 | public List<PersistentManifold> Manifolds { get { return _manifolds; } } | 78 | public List<PersistentManifold> Manifolds { get { return _manifolds; } } |
79 | 79 | ||
80 | public static int GlobalManifoldCount { get { return _manifoldCount; } set { _manifoldCount = value; } } | 80 | public static int GlobalManifoldCount { get { return _manifoldCount; } set { _manifoldCount = value; } } |
81 | 81 | ||
82 | public PersistentManifold GetManifoldByIndex(int index) | 82 | public PersistentManifold GetManifoldByIndex(int index) |
83 | { | 83 | { |
84 | return _manifolds[index]; | 84 | return _manifolds[index]; |
85 | } | 85 | } |
86 | 86 | ||
87 | //registerCollisionCreateFunc allows registration of custom/alternative collision create functions | 87 | //registerCollisionCreateFunc allows registration of custom/alternative collision create functions |
88 | public void RegisterCollisionCreateFunc(BroadphaseNativeTypes proxyTypeA, BroadphaseNativeTypes proxyTypeB, CollisionAlgorithmCreateFunction createFunc) | 88 | public void RegisterCollisionCreateFunc(BroadphaseNativeTypes proxyTypeA, BroadphaseNativeTypes proxyTypeB, CollisionAlgorithmCreateFunction createFunc) |
89 | { | 89 | { |
90 | _doubleDispatch[(int)proxyTypeA, (int)proxyTypeB] = createFunc; | 90 | _doubleDispatch[(int)proxyTypeA, (int)proxyTypeB] = createFunc; |
91 | } | 91 | } |
92 | 92 | ||
93 | public virtual PersistentManifold GetNewManifold(object bodyA, object bodyB) | 93 | public virtual PersistentManifold GetNewManifold(object bodyA, object bodyB) |
94 | { | 94 | { |
95 | _manifoldCount++; | 95 | _manifoldCount++; |
96 | 96 | ||
97 | CollisionObject body0 = bodyA as CollisionObject; | 97 | CollisionObject body0 = bodyA as CollisionObject; |
98 | CollisionObject body1 = bodyB as CollisionObject; | 98 | CollisionObject body1 = bodyB as CollisionObject; |
99 | 99 | ||
100 | PersistentManifold manifold = new PersistentManifold(body0, body1); | 100 | PersistentManifold manifold = new PersistentManifold(body0, body1); |
101 | _manifolds.Add(manifold); | 101 | _manifolds.Add(manifold); |
102 | 102 | ||
103 | return manifold; | 103 | return manifold; |
104 | } | 104 | } |
105 | 105 | ||
106 | public virtual void ReleaseManifold(PersistentManifold manifold) | 106 | public virtual void ReleaseManifold(PersistentManifold manifold) |
107 | { | 107 | { |
108 | _manifoldCount--; | 108 | _manifoldCount--; |
109 | 109 | ||
110 | ClearManifold(manifold); | 110 | ClearManifold(manifold); |
111 | _manifolds.Remove(manifold); | 111 | _manifolds.Remove(manifold); |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
115 | public virtual void ClearManifold(PersistentManifold manifold) | 115 | public virtual void ClearManifold(PersistentManifold manifold) |
116 | { | 116 | { |
117 | manifold.ClearManifold(); | 117 | manifold.ClearManifold(); |
118 | } | 118 | } |
119 | 119 | ||
120 | public CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB) | 120 | public CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB) |
121 | { | 121 | { |
122 | return FindAlgorithm(bodyA, bodyB, null); | 122 | return FindAlgorithm(bodyA, bodyB, null); |
123 | } | 123 | } |
124 | 124 | ||
125 | public CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB, PersistentManifold sharedManifold) | 125 | public CollisionAlgorithm FindAlgorithm(CollisionObject bodyA, CollisionObject bodyB, PersistentManifold sharedManifold) |
126 | { | 126 | { |
127 | CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo = new CollisionAlgorithmConstructionInfo(); | 127 | CollisionAlgorithmConstructionInfo collisionAlgorithmConstructionInfo = new CollisionAlgorithmConstructionInfo(); |
128 | collisionAlgorithmConstructionInfo.Dispatcher = this; | 128 | collisionAlgorithmConstructionInfo.Dispatcher = this; |
129 | collisionAlgorithmConstructionInfo.Manifold = sharedManifold; | 129 | collisionAlgorithmConstructionInfo.Manifold = sharedManifold; |
130 | CollisionAlgorithm collisionAlgorithm = _doubleDispatch[(int)bodyA.CollisionShape.ShapeType, (int)bodyB.CollisionShape.ShapeType].CreateCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB); | 130 | CollisionAlgorithm collisionAlgorithm = _doubleDispatch[(int)bodyA.CollisionShape.ShapeType, (int)bodyB.CollisionShape.ShapeType].CreateCollisionAlgorithm(collisionAlgorithmConstructionInfo, bodyA, bodyB); |
131 | return collisionAlgorithm; | 131 | return collisionAlgorithm; |
132 | } | 132 | } |
133 | 133 | ||
134 | /*public CollisionAlgorithm internalFindAlgorithm(CollisionObject body0, CollisionObject body1) | 134 | /*public CollisionAlgorithm internalFindAlgorithm(CollisionObject body0, CollisionObject body1) |
135 | { | 135 | { |
136 | return internalFindAlgorithm(body0, body1, null); | 136 | return internalFindAlgorithm(body0, body1, null); |
137 | } | 137 | } |
138 | 138 | ||
139 | public CollisionAlgorithm internalFindAlgorithm(CollisionObject body0, CollisionObject body1, PersistentManifold sharedManifold) | 139 | public CollisionAlgorithm internalFindAlgorithm(CollisionObject body0, CollisionObject body1, PersistentManifold sharedManifold) |
140 | { | 140 | { |
141 | m_count++; | 141 | m_count++; |
142 | 142 | ||
143 | CollisionAlgorithmConstructionInfo ci = new CollisionAlgorithmConstructionInfo(); | 143 | CollisionAlgorithmConstructionInfo ci = new CollisionAlgorithmConstructionInfo(); |
144 | ci.m_dispatcher = this; | 144 | ci.m_dispatcher = this; |
145 | 145 | ||
146 | if (body0.getCollisionShape().isConvex() && body1.getCollisionShape().isConvex()) | 146 | if (body0.getCollisionShape().isConvex() && body1.getCollisionShape().isConvex()) |
147 | { | 147 | { |
148 | return new ConvexConvexAlgorithm(sharedManifold, ci, body0, body1); | 148 | return new ConvexConvexAlgorithm(sharedManifold, ci, body0, body1); |
149 | } | 149 | } |
150 | 150 | ||
151 | if (body0.getCollisionShape().isConvex() && body1.getCollisionShape().isConcave()) | 151 | if (body0.getCollisionShape().isConvex() && body1.getCollisionShape().isConcave()) |
152 | { | 152 | { |
153 | return new ConvexConcaveCollisionAlgorithm(ci, body0, body1, false); | 153 | return new ConvexConcaveCollisionAlgorithm(ci, body0, body1, false); |
154 | } | 154 | } |
155 | 155 | ||
156 | if (body1.getCollisionShape().isConvex() && body0.getCollisionShape().isConcave()) | 156 | if (body1.getCollisionShape().isConvex() && body0.getCollisionShape().isConcave()) |
157 | { | 157 | { |
158 | return new ConvexConcaveCollisionAlgorithm(ci, body0, body1, true); | 158 | return new ConvexConcaveCollisionAlgorithm(ci, body0, body1, true); |
159 | } | 159 | } |
160 | 160 | ||
161 | if (body0.getCollisionShape().isCompound()) | 161 | if (body0.getCollisionShape().isCompound()) |
162 | { | 162 | { |
163 | return new CompoundCollisionAlgorithm(ci, body0, body1, false); | 163 | return new CompoundCollisionAlgorithm(ci, body0, body1, false); |
164 | } | 164 | } |
165 | else | 165 | else |
166 | { | 166 | { |
167 | if (body1.getCollisionShape().isCompound()) | 167 | if (body1.getCollisionShape().isCompound()) |
168 | { | 168 | { |
169 | return new CompoundCollisionAlgorithm(ci, body0, body1, true); | 169 | return new CompoundCollisionAlgorithm(ci, body0, body1, true); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | //failed to find an algorithm | 173 | //failed to find an algorithm |
174 | return new EmptyAlgorithm(ci); | 174 | return new EmptyAlgorithm(ci); |
175 | }*/ | 175 | }*/ |
176 | 176 | ||
177 | public virtual bool NeedsCollision(CollisionObject bodyA, CollisionObject bodyB) | 177 | public virtual bool NeedsCollision(CollisionObject bodyA, CollisionObject bodyB) |
178 | { | 178 | { |
179 | if (bodyA == null || bodyB == null) | 179 | if (bodyA == null || bodyB == null) |
180 | throw new BulletException(); | 180 | throw new BulletException(); |
181 | 181 | ||
182 | bool needsCollision = true; | 182 | bool needsCollision = true; |
183 | 183 | ||
184 | //broadphase filtering already deals with this | 184 | //broadphase filtering already deals with this |
185 | /*if ((body0.isStaticObject() || body0.isKinematicObject()) && | 185 | /*if ((body0.isStaticObject() || body0.isKinematicObject()) && |
186 | (body1.isStaticObject() || body1.isKinematicObject())) | 186 | (body1.isStaticObject() || body1.isKinematicObject())) |
187 | { | 187 | { |
188 | printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); | 188 | printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); |
189 | }*/ | 189 | }*/ |
190 | 190 | ||
191 | if ((!bodyA.IsActive) && (!bodyB.IsActive)) | 191 | if ((!bodyA.IsActive) && (!bodyB.IsActive)) |
192 | needsCollision = false; | 192 | needsCollision = false; |
193 | 193 | ||
194 | return needsCollision; | 194 | return needsCollision; |
195 | } | 195 | } |
196 | 196 | ||
197 | public virtual bool NeedsResponse(CollisionObject bodyA, CollisionObject bodyB) | 197 | public virtual bool NeedsResponse(CollisionObject bodyA, CollisionObject bodyB) |
198 | { | 198 | { |
199 | //here you can do filtering | 199 | //here you can do filtering |
200 | bool hasResponse = bodyA.HasContactResponse && bodyB.HasContactResponse; | 200 | bool hasResponse = bodyA.HasContactResponse && bodyB.HasContactResponse; |
201 | hasResponse = hasResponse && (!bodyA.IsStaticOrKinematicObject || !bodyB.IsStaticOrKinematicObject); | 201 | hasResponse = hasResponse && (!bodyA.IsStaticOrKinematicObject || !bodyB.IsStaticOrKinematicObject); |
202 | return hasResponse; | 202 | return hasResponse; |
203 | } | 203 | } |
204 | 204 | ||
205 | public virtual void DispatchAllCollisionPairs(OverlappingPairCache pairCache, DispatcherInfo dispatchInfo) | 205 | public virtual void DispatchAllCollisionPairs(OverlappingPairCache pairCache, DispatcherInfo dispatchInfo) |
206 | { | 206 | { |
207 | CollisionPairCallback collisionCallback = new CollisionPairCallback(dispatchInfo, this); | 207 | CollisionPairCallback collisionCallback = new CollisionPairCallback(dispatchInfo, this); |
208 | pairCache.ProcessAllOverlappingPairs(collisionCallback); | 208 | pairCache.ProcessAllOverlappingPairs(collisionCallback); |
209 | } | 209 | } |
210 | 210 | ||
211 | private CollisionAlgorithmCreateFunction FindCreateFunction(BroadphaseNativeTypes proxyTypeA, BroadphaseNativeTypes proxyTypeB) | 211 | private CollisionAlgorithmCreateFunction FindCreateFunction(BroadphaseNativeTypes proxyTypeA, BroadphaseNativeTypes proxyTypeB) |
212 | { | 212 | { |
213 | if (BroadphaseProxy.IsConvex(proxyTypeA) && BroadphaseProxy.IsConvex(proxyTypeB)) | 213 | if (BroadphaseProxy.IsConvex(proxyTypeA) && BroadphaseProxy.IsConvex(proxyTypeB)) |
214 | { | 214 | { |
215 | return _convexConvexCreateFunc; | 215 | return _convexConvexCreateFunc; |
216 | } | 216 | } |
217 | 217 | ||
218 | if (BroadphaseProxy.IsConvex(proxyTypeA) && BroadphaseProxy.IsConcave(proxyTypeB)) | 218 | if (BroadphaseProxy.IsConvex(proxyTypeA) && BroadphaseProxy.IsConcave(proxyTypeB)) |
219 | { | 219 | { |
220 | return _convexConcaveCreateFunc; | 220 | return _convexConcaveCreateFunc; |
221 | } | 221 | } |
222 | 222 | ||
223 | if (BroadphaseProxy.IsConvex(proxyTypeB) && BroadphaseProxy.IsConcave(proxyTypeA)) | 223 | if (BroadphaseProxy.IsConvex(proxyTypeB) && BroadphaseProxy.IsConcave(proxyTypeA)) |
224 | { | 224 | { |
225 | return _swappedConvexConcaveCreateFunc; | 225 | return _swappedConvexConcaveCreateFunc; |
226 | } | 226 | } |
227 | 227 | ||
228 | if (BroadphaseProxy.IsCompound(proxyTypeA)) | 228 | if (BroadphaseProxy.IsCompound(proxyTypeA)) |
229 | { | 229 | { |
230 | return _compoundCreateFunc; | 230 | return _compoundCreateFunc; |
231 | } | 231 | } |
232 | else | 232 | else |
233 | { | 233 | { |
234 | if (BroadphaseProxy.IsCompound(proxyTypeB)) | 234 | if (BroadphaseProxy.IsCompound(proxyTypeB)) |
235 | { | 235 | { |
236 | return _swappedCompoundCreateFunc; | 236 | return _swappedCompoundCreateFunc; |
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | //failed to find an algorithm | 240 | //failed to find an algorithm |
241 | return _emptyCreateFunc; | 241 | return _emptyCreateFunc; |
242 | } | 242 | } |
243 | 243 | ||
244 | public NearCallback NearCallback { get { return _nearCallback; } set { _nearCallback = value; } } | 244 | public NearCallback NearCallback { get { return _nearCallback; } set { _nearCallback = value; } } |
245 | 245 | ||
246 | //by default, Bullet will use this near callback | 246 | //by default, Bullet will use this near callback |
247 | public static void DefaultNearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo) | 247 | public static void DefaultNearCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo) |
248 | { | 248 | { |
249 | CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject; | 249 | CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject; |
250 | CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject; | 250 | CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject; |
251 | 251 | ||
252 | if (dispatcher.NeedsCollision(collisionObjectA, collisionObjectB)) | 252 | if (dispatcher.NeedsCollision(collisionObjectA, collisionObjectB)) |
253 | { | 253 | { |
254 | //dispatcher will keep algorithms persistent in the collision pair | 254 | //dispatcher will keep algorithms persistent in the collision pair |
255 | if (collisionPair.CollisionAlgorithm == null) | 255 | if (collisionPair.CollisionAlgorithm == null) |
256 | { | 256 | { |
257 | collisionPair.CollisionAlgorithm = dispatcher.FindAlgorithm(collisionObjectA, collisionObjectB); | 257 | collisionPair.CollisionAlgorithm = dispatcher.FindAlgorithm(collisionObjectA, collisionObjectB); |
258 | } | 258 | } |
259 | 259 | ||
260 | if (collisionPair.CollisionAlgorithm != null) | 260 | if (collisionPair.CollisionAlgorithm != null) |
261 | { | 261 | { |
262 | ManifoldResult contactPointResult = new ManifoldResult(collisionObjectA, collisionObjectB); | 262 | ManifoldResult contactPointResult = new ManifoldResult(collisionObjectA, collisionObjectB); |
263 | 263 | ||
264 | if (dispatchInfo.DispatchFunction == DispatchFunction.Discrete) | 264 | if (dispatchInfo.DispatchFunction == DispatchFunction.Discrete) |
265 | { | 265 | { |
266 | //discrete collision detection query | 266 | //discrete collision detection query |
267 | collisionPair.CollisionAlgorithm.ProcessCollision(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult); | 267 | collisionPair.CollisionAlgorithm.ProcessCollision(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult); |
268 | } | 268 | } |
269 | else | 269 | else |
270 | { | 270 | { |
271 | //continuous collision detection query, time of impact (toi) | 271 | //continuous collision detection query, time of impact (toi) |
272 | float timeOfImpact = collisionPair.CollisionAlgorithm.CalculateTimeOfImpact(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult); | 272 | float timeOfImpact = collisionPair.CollisionAlgorithm.CalculateTimeOfImpact(collisionObjectA, collisionObjectB, dispatchInfo, contactPointResult); |
273 | if (dispatchInfo.TimeOfImpact > timeOfImpact) | 273 | if (dispatchInfo.TimeOfImpact > timeOfImpact) |
274 | dispatchInfo.TimeOfImpact = timeOfImpact; | 274 | dispatchInfo.TimeOfImpact = timeOfImpact; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | } | 278 | } |
279 | } | 279 | } |
280 | } | 280 | } |