diff options
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/BroadphasePair.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/BroadphasePair.cs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/BroadphasePair.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/BroadphasePair.cs new file mode 100644 index 0000000..2b9e114 --- /dev/null +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/BroadphaseCollision/BroadphasePair.cs | |||
@@ -0,0 +1,113 @@ | |||
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 | |||
26 | namespace XnaDevRu.BulletX | ||
27 | { | ||
28 | public class BroadphasePair | ||
29 | { | ||
30 | private BroadphaseProxy _proxyA; | ||
31 | private BroadphaseProxy _proxyB; | ||
32 | |||
33 | private CollisionAlgorithm _algorithm; | ||
34 | private object _userInfo; | ||
35 | |||
36 | public BroadphasePair() | ||
37 | { | ||
38 | } | ||
39 | |||
40 | public BroadphasePair(BroadphasePair other) | ||
41 | { | ||
42 | _proxyA = other._proxyA; | ||
43 | _proxyB = other._proxyB; | ||
44 | |||
45 | _algorithm = other._algorithm; | ||
46 | _userInfo = null; | ||
47 | } | ||
48 | |||
49 | public BroadphasePair(BroadphaseProxy proxyA, BroadphaseProxy proxyB) | ||
50 | { | ||
51 | _proxyA = proxyA; | ||
52 | _proxyB = proxyB; | ||
53 | |||
54 | _algorithm = null; | ||
55 | _userInfo = null; | ||
56 | } | ||
57 | |||
58 | public BroadphaseProxy ProxyA { get { return _proxyA; } set { _proxyA = value; } } | ||
59 | public BroadphaseProxy ProxyB { get { return _proxyB; } set { _proxyB = value; } } | ||
60 | |||
61 | public CollisionAlgorithm CollisionAlgorithm { get { return _algorithm; } set { _algorithm = value; } } | ||
62 | public object UserInfo { get { return _userInfo; } set { _userInfo = value; } } | ||
63 | |||
64 | public override int GetHashCode() | ||
65 | { | ||
66 | return _proxyA.GetHashCode() ^ _proxyB.GetHashCode(); | ||
67 | } | ||
68 | |||
69 | public override bool Equals(object obj) | ||
70 | { | ||
71 | if (obj is BroadphasePair) | ||
72 | return this == (BroadphasePair)obj; | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | public static int ComparisonSort(BroadphasePair a, BroadphasePair b) | ||
77 | { | ||
78 | int aAId = a.ProxyA != null ? a.ProxyA.ComparisonID : -1; | ||
79 | int aBId = a.ProxyB != null ? a.ProxyB.ComparisonID : -1; | ||
80 | int aCId = a.CollisionAlgorithm != null ? a.CollisionAlgorithm.ComparisonID : -1; | ||
81 | int bAId = b.ProxyA != null ? b.ProxyA.ComparisonID : -1; | ||
82 | int bBId = b.ProxyB != null ? b.ProxyB.ComparisonID : -1; | ||
83 | int bCId = b.CollisionAlgorithm != null ? b.CollisionAlgorithm.ComparisonID : -1; | ||
84 | |||
85 | if (aAId > bAId || | ||
86 | (a.ProxyA == b.ProxyA && aBId > bBId) || | ||
87 | (a.ProxyA == b.ProxyA && a.ProxyB == b.ProxyB && aCId > bCId)) | ||
88 | return -1; | ||
89 | else | ||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | public static bool operator ==(BroadphasePair a, BroadphasePair b) | ||
94 | { | ||
95 | if (object.Equals(a, null) && object.Equals(b, null)) | ||
96 | return true; | ||
97 | if (object.Equals(a, null) || object.Equals(b, null)) | ||
98 | return false; | ||
99 | |||
100 | return (a.ProxyA == b.ProxyA) && (a.ProxyB == b.ProxyB); | ||
101 | } | ||
102 | |||
103 | public static bool operator !=(BroadphasePair a, BroadphasePair b) | ||
104 | { | ||
105 | if (object.Equals(a, null) && object.Equals(b, null)) | ||
106 | return true; | ||
107 | if (object.Equals(a, null) || object.Equals(b, null)) | ||
108 | return false; | ||
109 | |||
110 | return (a.ProxyA != b.ProxyA) || (a.ProxyB != b.ProxyB); | ||
111 | } | ||
112 | } | ||
113 | } | ||