aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs256
1 files changed, 128 insertions, 128 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs
index 1dc3f34..f37b3f5 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs
@@ -1,128 +1,128 @@
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
22using System; 22using System;
23using System.Collections.Generic; 23using System.Collections.Generic;
24using System.Text; 24using System.Text;
25using MonoXnaCompactMaths; 25using MonoXnaCompactMaths;
26 26
27namespace XnaDevRu.BulletX 27namespace XnaDevRu.BulletX
28{ 28{
29 public class SimpleBroadphase : OverlappingPairCache 29 public class SimpleBroadphase : OverlappingPairCache
30 { 30 {
31 private int _maxProxies; 31 private int _maxProxies;
32 private List<SimpleBroadphaseProxy> _proxies = new List<SimpleBroadphaseProxy>(); 32 private List<SimpleBroadphaseProxy> _proxies = new List<SimpleBroadphaseProxy>();
33 33
34 public SimpleBroadphase() 34 public SimpleBroadphase()
35 : this(16384) { } 35 : this(16384) { }
36 36
37 public SimpleBroadphase(int maxProxies) 37 public SimpleBroadphase(int maxProxies)
38 : base() 38 : base()
39 { 39 {
40 _maxProxies = maxProxies; 40 _maxProxies = maxProxies;
41 } 41 }
42 42
43 public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask) 43 public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask)
44 { 44 {
45 if (_proxies.Count >= _maxProxies) 45 if (_proxies.Count >= _maxProxies)
46 { 46 {
47 BulletDebug.Assert(false); 47 BulletDebug.Assert(false);
48 return null; //should never happen, but don't let the game crash ;-) 48 return null; //should never happen, but don't let the game crash ;-)
49 } 49 }
50 BulletDebug.Assert(min.X <= max.X && min.Y <= max.Y && min.Z <= max.Z); 50 BulletDebug.Assert(min.X <= max.X && min.Y <= max.Y && min.Z <= max.Z);
51 51
52 SimpleBroadphaseProxy proxy = new SimpleBroadphaseProxy(min, max, shapeType, userData, collisionFilterGroup, collisionFilterMask); 52 SimpleBroadphaseProxy proxy = new SimpleBroadphaseProxy(min, max, shapeType, userData, collisionFilterGroup, collisionFilterMask);
53 _proxies.Add(proxy); 53 _proxies.Add(proxy);
54 54
55 return proxy; 55 return proxy;
56 } 56 }
57 57
58 58
59 public override void DestroyProxy(BroadphaseProxy proxy) 59 public override void DestroyProxy(BroadphaseProxy proxy)
60 { 60 {
61 RemoveOverlappingPairsContainingProxy(proxy); 61 RemoveOverlappingPairsContainingProxy(proxy);
62 _proxies.Remove(proxy as SimpleBroadphaseProxy); 62 _proxies.Remove(proxy as SimpleBroadphaseProxy);
63 } 63 }
64 64
65 public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax) 65 public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax)
66 { 66 {
67 SimpleBroadphaseProxy simpleProxy = GetSimpleProxyFromProxy(proxy); 67 SimpleBroadphaseProxy simpleProxy = GetSimpleProxyFromProxy(proxy);
68 simpleProxy.Minimum = aabbMin; 68 simpleProxy.Minimum = aabbMin;
69 simpleProxy.Maximum = aabbMax; 69 simpleProxy.Maximum = aabbMax;
70 } 70 }
71 71
72 private SimpleBroadphaseProxy GetSimpleProxyFromProxy(BroadphaseProxy proxy) 72 private SimpleBroadphaseProxy GetSimpleProxyFromProxy(BroadphaseProxy proxy)
73 { 73 {
74 return proxy as SimpleBroadphaseProxy; 74 return proxy as SimpleBroadphaseProxy;
75 } 75 }
76 76
77 public override void RefreshOverlappingPairs() 77 public override void RefreshOverlappingPairs()
78 { 78 {
79 for (int i = 0; i < _proxies.Count; i++) 79 for (int i = 0; i < _proxies.Count; i++)
80 { 80 {
81 SimpleBroadphaseProxy proxyA = _proxies[i]; 81 SimpleBroadphaseProxy proxyA = _proxies[i];
82 82
83 for (int j = i + 1; j < _proxies.Count; j++) 83 for (int j = i + 1; j < _proxies.Count; j++)
84 { 84 {
85 SimpleBroadphaseProxy proxyB = _proxies[j]; 85 SimpleBroadphaseProxy proxyB = _proxies[j];
86 86
87 if (AabbOverlap(proxyA, proxyB)) 87 if (AabbOverlap(proxyA, proxyB))
88 { 88 {
89 if (FindPair(proxyA, proxyB) == null) 89 if (FindPair(proxyA, proxyB) == null)
90 { 90 {
91 AddOverlappingPair(proxyA, proxyB); 91 AddOverlappingPair(proxyA, proxyB);
92 } 92 }
93 } 93 }
94 } 94 }
95 } 95 }
96 96
97 CheckOverlapCallback check = new CheckOverlapCallback(); 97 CheckOverlapCallback check = new CheckOverlapCallback();
98 ProcessAllOverlappingPairs(check); 98 ProcessAllOverlappingPairs(check);
99 } 99 }
100 100
101 public static bool AabbOverlap(SimpleBroadphaseProxy proxyA, SimpleBroadphaseProxy proxyB) 101 public static bool AabbOverlap(SimpleBroadphaseProxy proxyA, SimpleBroadphaseProxy proxyB)
102 { 102 {
103 return proxyA.Minimum.X <= proxyB.Maximum.X && proxyB.Minimum.X <= proxyA.Maximum.X && 103 return proxyA.Minimum.X <= proxyB.Maximum.X && proxyB.Minimum.X <= proxyA.Maximum.X &&
104 proxyA.Minimum.Y <= proxyB.Maximum.Y && proxyB.Minimum.Y <= proxyA.Maximum.Y && 104 proxyA.Minimum.Y <= proxyB.Maximum.Y && proxyB.Minimum.Y <= proxyA.Maximum.Y &&
105 proxyA.Minimum.Z <= proxyB.Maximum.Z && proxyB.Minimum.Z <= proxyA.Maximum.Z; 105 proxyA.Minimum.Z <= proxyB.Maximum.Z && proxyB.Minimum.Z <= proxyA.Maximum.Z;
106 } 106 }
107 107
108 private void Validate() 108 private void Validate()
109 { 109 {
110 for (int i = 0; i < _proxies.Count; i++) 110 for (int i = 0; i < _proxies.Count; i++)
111 { 111 {
112 for (int j = i + 1; j < _proxies.Count; j++) 112 for (int j = i + 1; j < _proxies.Count; j++)
113 { 113 {
114 if (_proxies[i] == _proxies[j]) 114 if (_proxies[i] == _proxies[j])
115 throw new BulletException(); 115 throw new BulletException();
116 } 116 }
117 } 117 }
118 } 118 }
119 } 119 }
120 120
121 public class CheckOverlapCallback : IOverlapCallback 121 public class CheckOverlapCallback : IOverlapCallback
122 { 122 {
123 public bool ProcessOverlap(ref BroadphasePair pair) 123 public bool ProcessOverlap(ref BroadphasePair pair)
124 { 124 {
125 return (!SimpleBroadphase.AabbOverlap(pair.ProxyA as SimpleBroadphaseProxy, pair.ProxyB as SimpleBroadphaseProxy)); 125 return (!SimpleBroadphase.AabbOverlap(pair.ProxyA as SimpleBroadphaseProxy, pair.ProxyB as SimpleBroadphaseProxy));
126 } 126 }
127 } 127 }
128} 128}