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