diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs deleted file mode 100644 index f37b3f5..0000000 --- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/SimpleBroadphase.cs +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | /* | ||
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 | ||
4 | |||
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 | ||
7 | arising from the use of this software. | ||
8 | |||
9 | Permission is granted to anyone to use this software for any purpose, | ||
10 | including commercial applications, and to alter it and redistribute it | ||
11 | freely, subject to the following restrictions: | ||
12 | |||
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 | ||
15 | in a product, an acknowledgment in the product documentation would be | ||
16 | appreciated but is not required. | ||
17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
18 | misrepresented as being the original software. | ||
19 | 3. This notice may not be removed or altered from any source distribution. | ||
20 | */ | ||
21 | |||
22 | using System; | ||
23 | using System.Collections.Generic; | ||
24 | using System.Text; | ||
25 | using MonoXnaCompactMaths; | ||
26 | |||
27 | namespace XnaDevRu.BulletX | ||
28 | { | ||
29 | public class SimpleBroadphase : OverlappingPairCache | ||
30 | { | ||
31 | private int _maxProxies; | ||
32 | private List<SimpleBroadphaseProxy> _proxies = new List<SimpleBroadphaseProxy>(); | ||
33 | |||
34 | public SimpleBroadphase() | ||
35 | : this(16384) { } | ||
36 | |||
37 | public SimpleBroadphase(int maxProxies) | ||
38 | : base() | ||
39 | { | ||
40 | _maxProxies = maxProxies; | ||
41 | } | ||
42 | |||
43 | public override BroadphaseProxy CreateProxy(Vector3 min, Vector3 max, BroadphaseNativeTypes shapeType, object userData, BroadphaseProxy.CollisionFilterGroups collisionFilterGroup, BroadphaseProxy.CollisionFilterGroups collisionFilterMask) | ||
44 | { | ||
45 | if (_proxies.Count >= _maxProxies) | ||
46 | { | ||
47 | BulletDebug.Assert(false); | ||
48 | return null; //should never happen, but don't let the game crash ;-) | ||
49 | } | ||
50 | BulletDebug.Assert(min.X <= max.X && min.Y <= max.Y && min.Z <= max.Z); | ||
51 | |||
52 | SimpleBroadphaseProxy proxy = new SimpleBroadphaseProxy(min, max, shapeType, userData, collisionFilterGroup, collisionFilterMask); | ||
53 | _proxies.Add(proxy); | ||
54 | |||
55 | return proxy; | ||
56 | } | ||
57 | |||
58 | |||
59 | public override void DestroyProxy(BroadphaseProxy proxy) | ||
60 | { | ||
61 | RemoveOverlappingPairsContainingProxy(proxy); | ||
62 | _proxies.Remove(proxy as SimpleBroadphaseProxy); | ||
63 | } | ||
64 | |||
65 | public override void SetAabb(BroadphaseProxy proxy, Vector3 aabbMin, Vector3 aabbMax) | ||
66 | { | ||
67 | SimpleBroadphaseProxy simpleProxy = GetSimpleProxyFromProxy(proxy); | ||
68 | simpleProxy.Minimum = aabbMin; | ||
69 | simpleProxy.Maximum = aabbMax; | ||
70 | } | ||
71 | |||
72 | private SimpleBroadphaseProxy GetSimpleProxyFromProxy(BroadphaseProxy proxy) | ||
73 | { | ||
74 | return proxy as SimpleBroadphaseProxy; | ||
75 | } | ||
76 | |||
77 | public override void RefreshOverlappingPairs() | ||
78 | { | ||
79 | for (int i = 0; i < _proxies.Count; i++) | ||
80 | { | ||
81 | SimpleBroadphaseProxy proxyA = _proxies[i]; | ||
82 | |||
83 | for (int j = i + 1; j < _proxies.Count; j++) | ||
84 | { | ||
85 | SimpleBroadphaseProxy proxyB = _proxies[j]; | ||
86 | |||
87 | if (AabbOverlap(proxyA, proxyB)) | ||
88 | { | ||
89 | if (FindPair(proxyA, proxyB) == null) | ||
90 | { | ||
91 | AddOverlappingPair(proxyA, proxyB); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | CheckOverlapCallback check = new CheckOverlapCallback(); | ||
98 | ProcessAllOverlappingPairs(check); | ||
99 | } | ||
100 | |||
101 | public static bool AabbOverlap(SimpleBroadphaseProxy proxyA, SimpleBroadphaseProxy proxyB) | ||
102 | { | ||
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 && | ||
105 | proxyA.Minimum.Z <= proxyB.Maximum.Z && proxyB.Minimum.Z <= proxyA.Maximum.Z; | ||
106 | } | ||
107 | |||
108 | private void Validate() | ||
109 | { | ||
110 | for (int i = 0; i < _proxies.Count; i++) | ||
111 | { | ||
112 | for (int j = i + 1; j < _proxies.Count; j++) | ||
113 | { | ||
114 | if (_proxies[i] == _proxies[j]) | ||
115 | throw new BulletException(); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | |||
121 | public class CheckOverlapCallback : IOverlapCallback | ||
122 | { | ||
123 | public bool ProcessOverlap(ref BroadphasePair pair) | ||
124 | { | ||
125 | return (!SimpleBroadphase.AabbOverlap(pair.ProxyA as SimpleBroadphaseProxy, pair.ProxyB as SimpleBroadphaseProxy)); | ||
126 | } | ||
127 | } | ||
128 | } | ||