diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/SphereShape.cs | 232 |
1 files changed, 116 insertions, 116 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/SphereShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/SphereShape.cs index c660a6f..cc3cea9 100644 --- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/SphereShape.cs +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/SphereShape.cs | |||
@@ -1,116 +1,116 @@ | |||
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 | /// btSphereShape implements an implicit (getSupportingVertex) Sphere | 30 | /// btSphereShape implements an implicit (getSupportingVertex) Sphere |
31 | /// </summary> | 31 | /// </summary> |
32 | public class SphereShape : ConvexShape | 32 | public class SphereShape : ConvexShape |
33 | { | 33 | { |
34 | public SphereShape(float radius) | 34 | public SphereShape(float radius) |
35 | : base() | 35 | : base() |
36 | { | 36 | { |
37 | Vector3 temp = ImplicitShapeDimensions; | 37 | Vector3 temp = ImplicitShapeDimensions; |
38 | temp.X = radius; | 38 | temp.X = radius; |
39 | ImplicitShapeDimensions = temp; | 39 | ImplicitShapeDimensions = temp; |
40 | } | 40 | } |
41 | 41 | ||
42 | public float Radius { get { return ImplicitShapeDimensions.X; } } | 42 | public float Radius { get { return ImplicitShapeDimensions.X; } } |
43 | 43 | ||
44 | public override BroadphaseNativeTypes ShapeType | 44 | public override BroadphaseNativeTypes ShapeType |
45 | { | 45 | { |
46 | get | 46 | get |
47 | { | 47 | { |
48 | return BroadphaseNativeTypes.Sphere; | 48 | return BroadphaseNativeTypes.Sphere; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | public override string Name | 52 | public override string Name |
53 | { | 53 | { |
54 | get | 54 | get |
55 | { | 55 | { |
56 | return "Sphere"; | 56 | return "Sphere"; |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) | 60 | public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) |
61 | { | 61 | { |
62 | return new Vector3(); | 62 | return new Vector3(); |
63 | } | 63 | } |
64 | 64 | ||
65 | /// <summary> | 65 | /// <summary> |
66 | /// to improve gjk behaviour, use radius+margin as the full margin, so never get into the penetration case | 66 | /// to improve gjk behaviour, use radius+margin as the full margin, so never get into the penetration case |
67 | /// this means, non-uniform scaling is not supported anymore | 67 | /// this means, non-uniform scaling is not supported anymore |
68 | /// </summary> | 68 | /// </summary> |
69 | public override float Margin | 69 | public override float Margin |
70 | { | 70 | { |
71 | get | 71 | get |
72 | { | 72 | { |
73 | return LocalScaling.X * Radius + base.Margin; | 73 | return LocalScaling.X * Radius + base.Margin; |
74 | } | 74 | } |
75 | set | 75 | set |
76 | { | 76 | { |
77 | base.Margin = value; | 77 | base.Margin = value; |
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) | 81 | public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) |
82 | { | 82 | { |
83 | if (supportVerticesOut != null) | 83 | if (supportVerticesOut != null) |
84 | for (int i = 0; i < supportVerticesOut.Length; i++) | 84 | for (int i = 0; i < supportVerticesOut.Length; i++) |
85 | supportVerticesOut[i] = new Vector3(); | 85 | supportVerticesOut[i] = new Vector3(); |
86 | } | 86 | } |
87 | 87 | ||
88 | public override void CalculateLocalInertia(float mass, out Vector3 inertia) | 88 | public override void CalculateLocalInertia(float mass, out Vector3 inertia) |
89 | { | 89 | { |
90 | float elem = 0.4f * mass * Margin * Margin; | 90 | float elem = 0.4f * mass * Margin * Margin; |
91 | inertia = new Vector3(elem, elem, elem); | 91 | inertia = new Vector3(elem, elem, elem); |
92 | } | 92 | } |
93 | 93 | ||
94 | public override Vector3 LocalGetSupportingVertex(Vector3 vec) | 94 | public override Vector3 LocalGetSupportingVertex(Vector3 vec) |
95 | { | 95 | { |
96 | Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); | 96 | Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); |
97 | 97 | ||
98 | Vector3 vecnorm = vec; | 98 | Vector3 vecnorm = vec; |
99 | if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) | 99 | if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) |
100 | { | 100 | { |
101 | vecnorm = new Vector3(-1f, -1f, -1f); | 101 | vecnorm = new Vector3(-1f, -1f, -1f); |
102 | } | 102 | } |
103 | vecnorm.Normalize(); | 103 | vecnorm.Normalize(); |
104 | supVertex += Margin * vecnorm; | 104 | supVertex += Margin * vecnorm; |
105 | return supVertex; | 105 | return supVertex; |
106 | } | 106 | } |
107 | 107 | ||
108 | public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) | 108 | public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) |
109 | { | 109 | { |
110 | Vector3 center = t.Translation; | 110 | Vector3 center = t.Translation; |
111 | Vector3 extent = new Vector3(Margin, Margin, Margin); | 111 | Vector3 extent = new Vector3(Margin, Margin, Margin); |
112 | aabbMin = center - extent; | 112 | aabbMin = center - extent; |
113 | aabbMax = center + extent; | 113 | aabbMax = center + extent; |
114 | } | 114 | } |
115 | } | 115 | } |
116 | } | 116 | } |