aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/TriangleShape.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/TriangleShape.cs374
1 files changed, 187 insertions, 187 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/TriangleShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/TriangleShape.cs
index 59ffad0..d5a17f3 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/TriangleShape.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/TriangleShape.cs
@@ -1,187 +1,187 @@
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 TriangleShape : PolyhedralConvexShape 29 public class TriangleShape : PolyhedralConvexShape
30 { 30 {
31 private Vector3[] _vertices = new Vector3[3]; 31 private Vector3[] _vertices = new Vector3[3];
32 32
33 public TriangleShape(Vector3 pointA, Vector3 pointB, Vector3 pointC) 33 public TriangleShape(Vector3 pointA, Vector3 pointB, Vector3 pointC)
34 { 34 {
35 _vertices[0] = pointA; 35 _vertices[0] = pointA;
36 _vertices[1] = pointB; 36 _vertices[1] = pointB;
37 _vertices[2] = pointC; 37 _vertices[2] = pointC;
38 } 38 }
39 39
40 public override int PreferredPenetrationDirectionsCount 40 public override int PreferredPenetrationDirectionsCount
41 { 41 {
42 get 42 get
43 { 43 {
44 return 2; 44 return 2;
45 } 45 }
46 } 46 }
47 47
48 public Vector3[] Vertices 48 public Vector3[] Vertices
49 { 49 {
50 get 50 get
51 { 51 {
52 return _vertices; 52 return _vertices;
53 } 53 }
54 } 54 }
55 55
56 public override int VertexCount 56 public override int VertexCount
57 { 57 {
58 get 58 get
59 { 59 {
60 return 3; 60 return 3;
61 } 61 }
62 } 62 }
63 63
64 public override int EdgeCount 64 public override int EdgeCount
65 { 65 {
66 get 66 get
67 { 67 {
68 return 3; 68 return 3;
69 } 69 }
70 } 70 }
71 71
72 public override int PlaneCount 72 public override int PlaneCount
73 { 73 {
74 get 74 get
75 { 75 {
76 return 1; 76 return 1;
77 } 77 }
78 } 78 }
79 79
80 public override BroadphaseNativeTypes ShapeType 80 public override BroadphaseNativeTypes ShapeType
81 { 81 {
82 get 82 get
83 { 83 {
84 return BroadphaseNativeTypes.Triangle; 84 return BroadphaseNativeTypes.Triangle;
85 } 85 }
86 } 86 }
87 87
88 public override string Name 88 public override string Name
89 { 89 {
90 get 90 get
91 { 91 {
92 return "Triangle"; 92 return "Triangle";
93 } 93 }
94 } 94 }
95 95
96 public override void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector) 96 public override void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector)
97 { 97 {
98 CalculateNormal(out penetrationVector); 98 CalculateNormal(out penetrationVector);
99 if (index != 0) 99 if (index != 0)
100 penetrationVector *= -1f; 100 penetrationVector *= -1f;
101 } 101 }
102 102
103 public virtual void GetPlaneEquation(int i, out Vector3 planeNormal, out Vector3 planeSupport) 103 public virtual void GetPlaneEquation(int i, out Vector3 planeNormal, out Vector3 planeSupport)
104 { 104 {
105 CalculateNormal(out planeNormal); 105 CalculateNormal(out planeNormal);
106 planeSupport = _vertices[0]; 106 planeSupport = _vertices[0];
107 } 107 }
108 108
109 public void CalculateNormal(out Vector3 normal) 109 public void CalculateNormal(out Vector3 normal)
110 { 110 {
111 normal = Vector3.Normalize(Vector3.Cross(_vertices[1] - _vertices[0], _vertices[2] - _vertices[0])); 111 normal = Vector3.Normalize(Vector3.Cross(_vertices[1] - _vertices[0], _vertices[2] - _vertices[0]));
112 } 112 }
113 113
114 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) 114 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec)
115 { 115 {
116 Vector3 dots = new Vector3(Vector3.Dot(vec, _vertices[0]), Vector3.Dot(vec, _vertices[1]), Vector3.Dot(vec, _vertices[2])); 116 Vector3 dots = new Vector3(Vector3.Dot(vec, _vertices[0]), Vector3.Dot(vec, _vertices[1]), Vector3.Dot(vec, _vertices[2]));
117 return _vertices[MathHelper.MaxAxis(dots)]; 117 return _vertices[MathHelper.MaxAxis(dots)];
118 } 118 }
119 119
120 public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) 120 public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut)
121 { 121 {
122 for (int i = 0; i < vectors.Length; i++) 122 for (int i = 0; i < vectors.Length; i++)
123 { 123 {
124 Vector3 dir = vectors[i]; 124 Vector3 dir = vectors[i];
125 Vector3 dots = new Vector3(Vector3.Dot(dir, _vertices[0]), Vector3.Dot(dir, _vertices[1]), Vector3.Dot(dir, _vertices[2])); 125 Vector3 dots = new Vector3(Vector3.Dot(dir, _vertices[0]), Vector3.Dot(dir, _vertices[1]), Vector3.Dot(dir, _vertices[2]));
126 supportVerticesOut[i] = _vertices[MathHelper.MaxAxis(dots)]; 126 supportVerticesOut[i] = _vertices[MathHelper.MaxAxis(dots)];
127 } 127 }
128 } 128 }
129 129
130 public override void CalculateLocalInertia(float mass, out Vector3 inertia) 130 public override void CalculateLocalInertia(float mass, out Vector3 inertia)
131 { 131 {
132 inertia = new Vector3(); 132 inertia = new Vector3();
133 BulletDebug.Assert(false); 133 BulletDebug.Assert(false);
134 } 134 }
135 135
136 public override void GetEdge(int i, out Vector3 pa, out Vector3 pb) 136 public override void GetEdge(int i, out Vector3 pa, out Vector3 pb)
137 { 137 {
138 GetVertex(i, out pa); 138 GetVertex(i, out pa);
139 GetVertex((i + 1) % 3, out pb); 139 GetVertex((i + 1) % 3, out pb);
140 } 140 }
141 141
142 public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) 142 public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax)
143 { 143 {
144 GetAabbSlow(t, out aabbMin, out aabbMax); 144 GetAabbSlow(t, out aabbMin, out aabbMax);
145 } 145 }
146 146
147 public override void GetVertex(int i, out Vector3 vtx) 147 public override void GetVertex(int i, out Vector3 vtx)
148 { 148 {
149 vtx = _vertices[i]; 149 vtx = _vertices[i];
150 } 150 }
151 151
152 public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i) 152 public override void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i)
153 { 153 {
154 GetPlaneEquation(i, out planeNormal, out planeSupport); 154 GetPlaneEquation(i, out planeNormal, out planeSupport);
155 } 155 }
156 156
157 public override bool IsInside(Vector3 pt, float tolerance) 157 public override bool IsInside(Vector3 pt, float tolerance)
158 { 158 {
159 Vector3 normal; 159 Vector3 normal;
160 CalculateNormal(out normal); 160 CalculateNormal(out normal);
161 //distance to plane 161 //distance to plane
162 float dist = Vector3.Dot(pt, normal); 162 float dist = Vector3.Dot(pt, normal);
163 float planeconst = Vector3.Dot(_vertices[0], normal); 163 float planeconst = Vector3.Dot(_vertices[0], normal);
164 dist -= planeconst; 164 dist -= planeconst;
165 if (dist >= -tolerance && dist <= tolerance) 165 if (dist >= -tolerance && dist <= tolerance)
166 { 166 {
167 //inside check on edge-planes 167 //inside check on edge-planes
168 int i; 168 int i;
169 for (i = 0; i < 3; i++) 169 for (i = 0; i < 3; i++)
170 { 170 {
171 Vector3 pa, pb; 171 Vector3 pa, pb;
172 GetEdge(i, out pa, out pb); 172 GetEdge(i, out pa, out pb);
173 Vector3 edge = pb - pa; 173 Vector3 edge = pb - pa;
174 Vector3 edgeNormal = Vector3.Cross(edge, normal); 174 Vector3 edgeNormal = Vector3.Cross(edge, normal);
175 edgeNormal = Vector3.Normalize(edgeNormal); 175 edgeNormal = Vector3.Normalize(edgeNormal);
176 float distance = Vector3.Dot(pt, edgeNormal); 176 float distance = Vector3.Dot(pt, edgeNormal);
177 float edgeConst = Vector3.Dot(pa, edgeNormal); 177 float edgeConst = Vector3.Dot(pa, edgeNormal);
178 distance -= edgeConst; 178 distance -= edgeConst;
179 if (distance < -tolerance) 179 if (distance < -tolerance)
180 return false; 180 return false;
181 } 181 }
182 return true; 182 return true;
183 } 183 }
184 return false; 184 return false;
185 } 185 }
186 } 186 }
187} 187}