aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexHullShape.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexHullShape.cs368
1 files changed, 184 insertions, 184 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexHullShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexHullShape.cs
index eb78533..8d06c90 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexHullShape.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexHullShape.cs
@@ -1,184 +1,184 @@
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 /// <summary> 29 /// <summary>
30 /// ConvexHullShape implements an implicit (getSupportingVertex) Convex Hull of a Point Cloud (vertices) 30 /// ConvexHullShape implements an implicit (getSupportingVertex) Convex Hull of a Point Cloud (vertices)
31 /// No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices. 31 /// No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices.
32 /// on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash. 32 /// on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash.
33 /// (memory is much slower then the cpu) 33 /// (memory is much slower then the cpu)
34 /// </summary> 34 /// </summary>
35 public class ConvexHullShape : PolyhedralConvexShape 35 public class ConvexHullShape : PolyhedralConvexShape
36 { 36 {
37 private List<Vector3> _points = new List<Vector3>(); 37 private List<Vector3> _points = new List<Vector3>();
38 38
39 public ConvexHullShape() { } 39 public ConvexHullShape() { }
40 40
41 public override int VertexCount 41 public override int VertexCount
42 { 42 {
43 get 43 get
44 { 44 {
45 return _points.Count; 45 return _points.Count;
46 } 46 }
47 } 47 }
48 48
49 public override int EdgeCount 49 public override int EdgeCount
50 { 50 {
51 get 51 get
52 { 52 {
53 return _points.Count; 53 return _points.Count;
54 } 54 }
55 } 55 }
56 56
57 public override int PlaneCount 57 public override int PlaneCount
58 { 58 {
59 get 59 get
60 { 60 {
61 return 0; 61 return 0;
62 } 62 }
63 } 63 }
64 64
65 public override BroadphaseNativeTypes ShapeType 65 public override BroadphaseNativeTypes ShapeType
66 { 66 {
67 get 67 get
68 { 68 {
69 return BroadphaseNativeTypes.ConvexHull; 69 return BroadphaseNativeTypes.ConvexHull;
70 } 70 }
71 } 71 }
72 72
73 public override string Name 73 public override string Name
74 { 74 {
75 get 75 get
76 { 76 {
77 return "Convex"; 77 return "Convex";
78 } 78 }
79 } 79 }
80 80
81 public override Vector3 LocalGetSupportingVertex(Vector3 vec) 81 public override Vector3 LocalGetSupportingVertex(Vector3 vec)
82 { 82 {
83 Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); 83 Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
84 84
85 if (Margin != 0) 85 if (Margin != 0)
86 { 86 {
87 Vector3 vecnorm = vec; 87 Vector3 vecnorm = vec;
88 if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) 88 if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon))
89 { 89 {
90 vecnorm=new Vector3(-1, -1, -1); 90 vecnorm=new Vector3(-1, -1, -1);
91 } 91 }
92 vecnorm = Vector3.Normalize(vecnorm); 92 vecnorm = Vector3.Normalize(vecnorm);
93 supVertex += Margin * vecnorm; 93 supVertex += Margin * vecnorm;
94 } 94 }
95 return supVertex; 95 return supVertex;
96 } 96 }
97 97
98 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec0) 98 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec0)
99 { 99 {
100 Vector3 supVec = new Vector3(); 100 Vector3 supVec = new Vector3();
101 float newDot, maxDot = -1e30f; 101 float newDot, maxDot = -1e30f;
102 102
103 Vector3 vec = vec0; 103 Vector3 vec = vec0;
104 float lenSqr = vec.LengthSquared(); 104 float lenSqr = vec.LengthSquared();
105 if (lenSqr < 0.0001f) 105 if (lenSqr < 0.0001f)
106 { 106 {
107 vec = new Vector3(1, 0, 0); 107 vec = new Vector3(1, 0, 0);
108 } 108 }
109 else 109 else
110 { 110 {
111 float rlen = 1f / (float)Math.Sqrt(lenSqr); 111 float rlen = 1f / (float)Math.Sqrt(lenSqr);
112 vec *= rlen; 112 vec *= rlen;
113 } 113 }
114 114
115 for (int i = 0; i < _points.Count; i++) 115 for (int i = 0; i < _points.Count; i++)
116 { 116 {
117 Vector3 vtx = _points[i] * LocalScaling; 117 Vector3 vtx = _points[i] * LocalScaling;
118 118
119 newDot = Vector3.Dot(vec, vtx); 119 newDot = Vector3.Dot(vec, vtx);
120 if (newDot > maxDot) 120 if (newDot > maxDot)
121 { 121 {
122 maxDot = newDot; 122 maxDot = newDot;
123 supVec = vtx; 123 supVec = vtx;
124 } 124 }
125 } 125 }
126 return supVec; 126 return supVec;
127 } 127 }
128 128
129 public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) 129 public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut)
130 { 130 {
131 float newDot; 131 float newDot;
132 //use 'w' component of supportVerticesOut? 132 //use 'w' component of supportVerticesOut?
133 /*{ 133 /*{
134 for (int i = 0; i < numVectors; i++) 134 for (int i = 0; i < numVectors; i++)
135 { 135 {
136 supportVerticesOut[i][3] = -1e30f; 136 supportVerticesOut[i][3] = -1e30f;
137 } 137 }
138 }*/ 138 }*/
139 #warning Warning! 139 #warning Warning!
140 for (int i = 0; i < _points.Count; i++) 140 for (int i = 0; i < _points.Count; i++)
141 { 141 {
142 Vector3 vtx = _points[i] * LocalScaling; 142 Vector3 vtx = _points[i] * LocalScaling;
143 143
144 for (int j = 0; j < vectors.Length; j++) 144 for (int j = 0; j < vectors.Length; j++)
145 { 145 {
146 newDot = Vector3.Dot(vectors[j], vtx); 146 newDot = Vector3.Dot(vectors[j], vtx);
147 if (newDot > -1e30f) 147 if (newDot > -1e30f)
148 { 148 {
149 //WARNING: don't swap next lines, the w component would get overwritten! 149 //WARNING: don't swap next lines, the w component would get overwritten!
150 supportVerticesOut[j] = vtx; 150 supportVerticesOut[j] = vtx;
151 //supportVerticesOut[j][3] = newDot; 151 //supportVerticesOut[j][3] = newDot;
152 #warning Warning! 152 #warning Warning!
153 } 153 }
154 } 154 }
155 } 155 }
156 } 156 }
157 157
158 public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) 158 public override void GetEdge(int i, out Vector3 pa, out Vector3 pb)
159 { 159 {
160 int index0 = i % _points.Count; 160 int index0 = i % _points.Count;
161 int index1 = (i + 1) % _points.Count; 161 int index1 = (i + 1) % _points.Count;
162 pa = _points[index0] * LocalScaling; 162 pa = _points[index0] * LocalScaling;
163 pb = _points[index1] * LocalScaling; 163 pb = _points[index1] * LocalScaling;
164 } 164 }
165 165
166 public override void GetVertex(int i, out Vector3 vtx) 166 public override void GetVertex(int i, out Vector3 vtx)
167 { 167 {
168 vtx = _points[i] * LocalScaling; 168 vtx = _points[i] * LocalScaling;
169 } 169 }
170 170
171 public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) 171 public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i)
172 { 172 {
173 planeNormal = new Vector3(); 173 planeNormal = new Vector3();
174 planeSupport = new Vector3(); 174 planeSupport = new Vector3();
175 BulletDebug.Assert(false); 175 BulletDebug.Assert(false);
176 } 176 }
177 177
178 public override bool IsInside(Vector3 pt, float tolerance) 178 public override bool IsInside(Vector3 pt, float tolerance)
179 { 179 {
180 BulletDebug.Assert(false); 180 BulletDebug.Assert(false);
181 return false; 181 return false;
182 } 182 }
183 } 183 }
184} 184}