aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.cs200
1 files changed, 100 insertions, 100 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.cs
index 9dc8e2d..da84462 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/CylinderShapeX.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
22using System; 22using System;
23using System.Collections.Generic; 23using System.Collections.Generic;
24using System.Text; 24using System.Text;
25using MonoXnaCompactMaths; 25using MonoXnaCompactMaths;
26 26
27namespace XnaDevRu.BulletX 27namespace XnaDevRu.BulletX
28{ 28{
29 public class CylinderShapeX : CylinderShape 29 public class CylinderShapeX : CylinderShape
30 { 30 {
31 public CylinderShapeX(Vector3 halfExtents) 31 public CylinderShapeX(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 0; 38 return 0;
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.Y; 46 return HalfExtents.Y;
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 "CylinderX"; 55 return "CylinderX";
56 } 56 }
57 } 57 }
58 58
59 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) 59 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec)
60 { 60 {
61 return CylinderLocalSupportX(HalfExtents, vec); 61 return CylinderLocalSupportX(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] = CylinderLocalSupportX(HalfExtents, vectors[i]); 68 supportVerticesOut[i] = CylinderLocalSupportX(HalfExtents, vectors[i]);
69 } 69 }
70 } 70 }
71 71
72 private Vector3 CylinderLocalSupportX(Vector3 halfExtents, Vector3 v) 72 private Vector3 CylinderLocalSupportX(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.Y; 76 float radius = halfExtents.Y;
77 float halfHeight = halfExtents.X; 77 float halfHeight = halfExtents.X;
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.Y * v.Y + v.Z * v.Z); 82 float s = (float)Math.Sqrt(v.Y * v.Y + v.Z * v.Z);
83 if (s != 0) 83 if (s != 0)
84 { 84 {
85 d = radius / s; 85 d = radius / s;
86 tmp.Y = v.Y * d; 86 tmp.Y = v.Y * d;
87 tmp.X = v.X < 0 ? -halfHeight : halfHeight; 87 tmp.X = v.X < 0 ? -halfHeight : halfHeight;
88 tmp.Z = v.Z * d; 88 tmp.Z = v.Z * d;
89 return tmp; 89 return tmp;
90 } 90 }
91 else 91 else
92 { 92 {
93 tmp.Y = radius; 93 tmp.Y = radius;
94 tmp.X = v.X < 0 ? -halfHeight : halfHeight; 94 tmp.X = v.X < 0 ? -halfHeight : halfHeight;
95 tmp.Z = 0; 95 tmp.Z = 0;
96 return tmp; 96 return tmp;
97 } 97 }
98 } 98 }
99 } 99 }
100} 100}