diff options
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeZ.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeZ.cs | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeZ.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeZ.cs index 1913e9c..10a1995 100644 --- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeZ.cs +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeZ.cs | |||
@@ -1,100 +1,100 @@ | |||
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 | public class CylinderShapeZ : CylinderShape | 29 | public class CylinderShapeZ : CylinderShape |
30 | { | 30 | { |
31 | public CylinderShapeZ(Vector3 halfExtents) | 31 | public CylinderShapeZ(Vector3 halfExtents) |
32 | : base(halfExtents) { } | 32 | : base(halfExtents) { } |
33 | 33 | ||
34 | public override int UpAxis | 34 | public override int UpAxis |
35 | { | 35 | { |
36 | get | 36 | get |
37 | { | 37 | { |
38 | return 2; | 38 | return 2; |
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | public override float Radius | 42 | public override float Radius |
43 | { | 43 | { |
44 | get | 44 | get |
45 | { | 45 | { |
46 | return HalfExtents.X; | 46 | return HalfExtents.X; |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | //debugging | 50 | //debugging |
51 | public override string Name | 51 | public override string Name |
52 | { | 52 | { |
53 | get | 53 | get |
54 | { | 54 | { |
55 | return "CylinderZ"; | 55 | return "CylinderZ"; |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) | 59 | public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) |
60 | { | 60 | { |
61 | return CylinderLocalSupportZ(HalfExtents, vec); | 61 | return CylinderLocalSupportZ(HalfExtents, vec); |
62 | } | 62 | } |
63 | 63 | ||
64 | public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) | 64 | public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) |
65 | { | 65 | { |
66 | for (int i = 0; i < vectors.Length; i++) | 66 | for (int i = 0; i < vectors.Length; i++) |
67 | { | 67 | { |
68 | supportVerticesOut[i] = CylinderLocalSupportZ(HalfExtents, vectors[i]); | 68 | supportVerticesOut[i] = CylinderLocalSupportZ(HalfExtents, vectors[i]); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | Vector3 CylinderLocalSupportZ(Vector3 halfExtents, Vector3 v) | 72 | Vector3 CylinderLocalSupportZ(Vector3 halfExtents, Vector3 v) |
73 | { | 73 | { |
74 | //mapping depends on how cylinder local orientation is | 74 | //mapping depends on how cylinder local orientation is |
75 | // extents of the cylinder is: X,Y is for radius, and Z for height | 75 | // extents of the cylinder is: X,Y is for radius, and Z for height |
76 | float radius = halfExtents.X; | 76 | float radius = halfExtents.X; |
77 | float halfHeight = halfExtents.Z; | 77 | float halfHeight = halfExtents.Z; |
78 | 78 | ||
79 | Vector3 tmp = new Vector3(); | 79 | Vector3 tmp = new Vector3(); |
80 | float d; | 80 | float d; |
81 | 81 | ||
82 | float s = (float)Math.Sqrt(v.X * v.X + v.Y * v.Y); | 82 | float s = (float)Math.Sqrt(v.X * v.X + v.Y * v.Y); |
83 | if (s != 0) | 83 | if (s != 0) |
84 | { | 84 | { |
85 | d = radius / s; | 85 | d = radius / s; |
86 | tmp.X = v.X * d; | 86 | tmp.X = v.X * d; |
87 | tmp.Z = v.Z < 0 ? -halfHeight : halfHeight; | 87 | tmp.Z = v.Z < 0 ? -halfHeight : halfHeight; |
88 | tmp.Y = v.Y * d; | 88 | tmp.Y = v.Y * d; |
89 | return tmp; | 89 | return tmp; |
90 | } | 90 | } |
91 | else | 91 | else |
92 | { | 92 | { |
93 | tmp.X = radius; | 93 | tmp.X = radius; |
94 | tmp.Z = v.Z < 0 ? -halfHeight : halfHeight; | 94 | tmp.Z = v.Z < 0 ? -halfHeight : halfHeight; |
95 | tmp.Y = 0; | 95 | tmp.Y = 0; |
96 | return tmp; | 96 | return tmp; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | } | 99 | } |
100 | } | 100 | } |