diff options
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShape.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShape.cs | 272 |
1 files changed, 136 insertions, 136 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShape.cs index 9a86eaf..85bf769 100644 --- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShape.cs +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShape.cs | |||
@@ -1,136 +1,136 @@ | |||
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 | /// <summary> | 29 | /// <summary> |
30 | /// implements cylinder shape interface | 30 | /// implements cylinder shape interface |
31 | /// </summary> | 31 | /// </summary> |
32 | public class CylinderShape : BoxShape | 32 | public class CylinderShape : BoxShape |
33 | { | 33 | { |
34 | public CylinderShape(Vector3 halfExtents) | 34 | public CylinderShape(Vector3 halfExtents) |
35 | : base(halfExtents) | 35 | : base(halfExtents) |
36 | { | 36 | { |
37 | } | 37 | } |
38 | 38 | ||
39 | public override BroadphaseNativeTypes ShapeType | 39 | public override BroadphaseNativeTypes ShapeType |
40 | { | 40 | { |
41 | get | 41 | get |
42 | { | 42 | { |
43 | return BroadphaseNativeTypes.Cylinder; | 43 | return BroadphaseNativeTypes.Cylinder; |
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | public virtual int UpAxis | 47 | public virtual int UpAxis |
48 | { | 48 | { |
49 | get | 49 | get |
50 | { | 50 | { |
51 | return 1; | 51 | return 1; |
52 | } | 52 | } |
53 | } | 53 | } |
54 | 54 | ||
55 | public virtual float Radius | 55 | public virtual float Radius |
56 | { | 56 | { |
57 | get | 57 | get |
58 | { | 58 | { |
59 | return HalfExtents.Z; | 59 | return HalfExtents.Z; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | //debugging | 63 | //debugging |
64 | public override string Name | 64 | public override string Name |
65 | { | 65 | { |
66 | get | 66 | get |
67 | { | 67 | { |
68 | return "CylinderY"; | 68 | return "CylinderY"; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | //getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version | 72 | //getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version |
73 | public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) | 73 | public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) |
74 | { | 74 | { |
75 | GetAabbSlow(t, out aabbMin, out aabbMax); | 75 | GetAabbSlow(t, out aabbMin, out aabbMax); |
76 | } | 76 | } |
77 | 77 | ||
78 | public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) | 78 | public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) |
79 | { | 79 | { |
80 | return CylinderLocalSupportY(HalfExtents, vec); | 80 | return CylinderLocalSupportY(HalfExtents, vec); |
81 | } | 81 | } |
82 | 82 | ||
83 | public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) | 83 | public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) |
84 | { | 84 | { |
85 | for (int i = 0; i < vectors.Length; i++) | 85 | for (int i = 0; i < vectors.Length; i++) |
86 | { | 86 | { |
87 | supportVerticesOut[i] = CylinderLocalSupportY(HalfExtents, vectors[i]); | 87 | supportVerticesOut[i] = CylinderLocalSupportY(HalfExtents, vectors[i]); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | public override Vector3 LocalGetSupportingVertex(Vector3 vec) | 91 | public override Vector3 LocalGetSupportingVertex(Vector3 vec) |
92 | { | 92 | { |
93 | 93 | ||
94 | Vector3 supVertex; | 94 | Vector3 supVertex; |
95 | supVertex = LocalGetSupportingVertexWithoutMargin(vec); | 95 | supVertex = LocalGetSupportingVertexWithoutMargin(vec); |
96 | 96 | ||
97 | if (Margin != 0) | 97 | if (Margin != 0) |
98 | { | 98 | { |
99 | Vector3 vecnorm = vec; | 99 | Vector3 vecnorm = vec; |
100 | if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) | 100 | if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) |
101 | { | 101 | { |
102 | vecnorm=new Vector3(-1, -1, -1); | 102 | vecnorm=new Vector3(-1, -1, -1); |
103 | } | 103 | } |
104 | vecnorm = Vector3.Normalize(vecnorm); | 104 | vecnorm = Vector3.Normalize(vecnorm); |
105 | supVertex += Margin * vecnorm; | 105 | supVertex += Margin * vecnorm; |
106 | } | 106 | } |
107 | return supVertex; | 107 | return supVertex; |
108 | } | 108 | } |
109 | 109 | ||
110 | private Vector3 CylinderLocalSupportY(Vector3 halfExtents, Vector3 v) | 110 | private Vector3 CylinderLocalSupportY(Vector3 halfExtents, Vector3 v) |
111 | { | 111 | { |
112 | float radius = halfExtents.X; | 112 | float radius = halfExtents.X; |
113 | float halfHeight = halfExtents.Y; | 113 | float halfHeight = halfExtents.Y; |
114 | 114 | ||
115 | Vector3 tmp = new Vector3(); | 115 | Vector3 tmp = new Vector3(); |
116 | float d; | 116 | float d; |
117 | 117 | ||
118 | float s = (float)Math.Sqrt(v.X * v.X + v.Z * v.Z); | 118 | float s = (float)Math.Sqrt(v.X * v.X + v.Z * v.Z); |
119 | if (s != 0) | 119 | if (s != 0) |
120 | { | 120 | { |
121 | d = radius / s; | 121 | d = radius / s; |
122 | tmp.X = v.X * d; | 122 | tmp.X = v.X * d; |
123 | tmp.Y = v.Y < 0 ? -halfHeight : halfHeight; | 123 | tmp.Y = v.Y < 0 ? -halfHeight : halfHeight; |
124 | tmp.Z = v.Z * d; | 124 | tmp.Z = v.Z * d; |
125 | return tmp; | 125 | return tmp; |
126 | } | 126 | } |
127 | else | 127 | else |
128 | { | 128 | { |
129 | tmp.X = radius; | 129 | tmp.X = radius; |
130 | tmp.Y = v.Y < 0 ? -halfHeight : halfHeight; | 130 | tmp.Y = v.Y < 0 ? -halfHeight : halfHeight; |
131 | tmp.Z = 0; | 131 | tmp.Z = 0; |
132 | return tmp; | 132 | return tmp; |
133 | } | 133 | } |
134 | } | 134 | } |
135 | } | 135 | } |
136 | } | 136 | } |