aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs266
1 files changed, 133 insertions, 133 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs
index f61371a..1a911b3 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/PolyhedralConvexShape.cs
@@ -1,133 +1,133 @@
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 abstract class PolyhedralConvexShape : ConvexShape 29 public abstract class PolyhedralConvexShape : ConvexShape
30 { 30 {
31 public PolyhedralConvexShape() 31 public PolyhedralConvexShape()
32 { 32 {
33 //m_optionalHull = null; 33 //m_optionalHull = null;
34 } 34 }
35 35
36 public abstract int VertexCount { get; } 36 public abstract int VertexCount { get; }
37 public abstract int EdgeCount { get; } 37 public abstract int EdgeCount { get; }
38 public abstract int PlaneCount { get; } 38 public abstract int PlaneCount { get; }
39 39
40 public abstract void GetEdge(int i, out Vector3 pointA, out Vector3 pointB); 40 public abstract void GetEdge(int i, out Vector3 pointA, out Vector3 pointB);
41 public abstract void GetVertex(int i, out Vector3 vertex); 41 public abstract void GetVertex(int i, out Vector3 vertex);
42 public abstract void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i); 42 public abstract void GetPlane(out Vector3 planeNormal, out Vector3 planeSupport, int i);
43 // abstract int getIndex(int i); 43 // abstract int getIndex(int i);
44 44
45 public abstract bool IsInside(Vector3 point, float tolerance); 45 public abstract bool IsInside(Vector3 point, float tolerance);
46 46
47 // optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp 47 // optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
48 //public class Hull m_optionalHull; 48 //public class Hull m_optionalHull;
49 49
50 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec) 50 public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec)
51 { 51 {
52 Vector3 supVec = new Vector3(); 52 Vector3 supVec = new Vector3();
53 53
54 float maxDot = -1e30f; 54 float maxDot = -1e30f;
55 55
56 float lenSqr = vec.LengthSquared(); 56 float lenSqr = vec.LengthSquared();
57 if (lenSqr < 0.0001f) 57 if (lenSqr < 0.0001f)
58 { 58 {
59 vec = new Vector3(1, 0, 0); 59 vec = new Vector3(1, 0, 0);
60 } 60 }
61 else 61 else
62 { 62 {
63 float rlen = 1f / (float)Math.Sqrt(lenSqr); 63 float rlen = 1f / (float)Math.Sqrt(lenSqr);
64 vec *= rlen; 64 vec *= rlen;
65 } 65 }
66 66
67 Vector3 vtx; 67 Vector3 vtx;
68 float newDot; 68 float newDot;
69 69
70 for (int i = 0; i < VertexCount; i++) 70 for (int i = 0; i < VertexCount; i++)
71 { 71 {
72 GetVertex(i, out vtx); 72 GetVertex(i, out vtx);
73 newDot = Vector3.Dot(vec, vtx); 73 newDot = Vector3.Dot(vec, vtx);
74 if (newDot > maxDot) 74 if (newDot > maxDot)
75 { 75 {
76 maxDot = newDot; 76 maxDot = newDot;
77 supVec = vtx; 77 supVec = vtx;
78 } 78 }
79 } 79 }
80 return supVec; 80 return supVec;
81 } 81 }
82 82
83 public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut) 83 public override void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut)
84 { 84 {
85 #warning Think about this 85 #warning Think about this
86 /*Vector3 vtx; 86 /*Vector3 vtx;
87 float newDot; 87 float newDot;
88 88
89 for (int i = 0; i < vectors.Length; i++) 89 for (int i = 0; i < vectors.Length; i++)
90 { 90 {
91 supportVerticesOut[i][3] = -1e30f; 91 supportVerticesOut[i][3] = -1e30f;
92 } 92 }
93 93
94 for (int j = 0; j < vectors.Length; j++) 94 for (int j = 0; j < vectors.Length; j++)
95 { 95 {
96 Vector3 vec = vectors[j]; 96 Vector3 vec = vectors[j];
97 97
98 for (int i = 0; i < getNumVertices(); i++) 98 for (int i = 0; i < getNumVertices(); i++)
99 { 99 {
100 getVertex(i, out vtx); 100 getVertex(i, out vtx);
101 newDot = Vector3.Dot(vec,vtx); 101 newDot = Vector3.Dot(vec,vtx);
102 if (newDot > supportVerticesOut[j][3]) 102 if (newDot > supportVerticesOut[j][3])
103 { 103 {
104 //WARNING: don't swap next lines, the w component would get overwritten! 104 //WARNING: don't swap next lines, the w component would get overwritten!
105 supportVerticesOut[j] = vtx; 105 supportVerticesOut[j] = vtx;
106 supportVerticesOut[j][3] = newDot; 106 supportVerticesOut[j][3] = newDot;
107 } 107 }
108 } 108 }
109 }*/ 109 }*/
110 } 110 }
111 111
112 public override void CalculateLocalInertia(float mass, out Vector3 inertia) 112 public override void CalculateLocalInertia(float mass, out Vector3 inertia)
113 { 113 {
114 //not yet, return box inertia 114 //not yet, return box inertia
115 float margin = Margin; 115 float margin = Margin;
116 116
117 Matrix ident = Matrix.Identity; 117 Matrix ident = Matrix.Identity;
118 Vector3 aabbMin, aabbMax; 118 Vector3 aabbMin, aabbMax;
119 GetAabb(ident, out aabbMin, out aabbMax); 119 GetAabb(ident, out aabbMin, out aabbMax);
120 Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f; 120 Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f;
121 121
122 float lx = 2f * (halfExtents.X + margin); 122 float lx = 2f * (halfExtents.X + margin);
123 float ly = 2f * (halfExtents.Y + margin); 123 float ly = 2f * (halfExtents.Y + margin);
124 float lz = 2f * (halfExtents.Z + margin); 124 float lz = 2f * (halfExtents.Z + margin);
125 float x2 = lx * lx; 125 float x2 = lx * lx;
126 float y2 = ly * ly; 126 float y2 = ly * ly;
127 float z2 = lz * lz; 127 float z2 = lz * lz;
128 float scaledmass = mass * 0.08333333f; 128 float scaledmass = mass * 0.08333333f;
129 129
130 inertia = scaledmass * (new Vector3(y2 + z2, x2 + z2, x2 + y2)); 130 inertia = scaledmass * (new Vector3(y2 + z2, x2 + z2, x2 + y2));
131 } 131 }
132 } 132 }
133} 133}