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