aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs282
1 files changed, 141 insertions, 141 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs
index 02d678e..d5c2fbd 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/ConvexShape.cs
@@ -1,141 +1,141 @@
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 /// ConvexShape is an abstract shape interface. 30 /// ConvexShape is an abstract shape interface.
31 /// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface. 31 /// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface.
32 /// used in combination with GJK or btConvexCast 32 /// used in combination with GJK or btConvexCast
33 /// </summary> 33 /// </summary>
34 public abstract class ConvexShape : CollisionShape 34 public abstract class ConvexShape : CollisionShape
35 { 35 {
36 private const int _maxPreferredPenetrationDirections = 10; 36 private const int _maxPreferredPenetrationDirections = 10;
37 private const float _convexDistanceMargin = 0.04f; 37 private const float _convexDistanceMargin = 0.04f;
38 38
39 private Vector3 _localScaling; 39 private Vector3 _localScaling;
40 private Vector3 _implicitShapeDimensions; 40 private Vector3 _implicitShapeDimensions;
41 private float _collisionMargin; 41 private float _collisionMargin;
42 42
43 public ConvexShape() 43 public ConvexShape()
44 : base() 44 : base()
45 { 45 {
46 _localScaling = Vector3.One; 46 _localScaling = Vector3.One;
47 _collisionMargin = ConvexDistanceMargin; 47 _collisionMargin = ConvexDistanceMargin;
48 } 48 }
49 49
50 public static int MaxPreferredPenetrationDirections { get { return _maxPreferredPenetrationDirections; } } 50 public static int MaxPreferredPenetrationDirections { get { return _maxPreferredPenetrationDirections; } }
51 public static float ConvexDistanceMargin { get { return _convexDistanceMargin; } } 51 public static float ConvexDistanceMargin { get { return _convexDistanceMargin; } }
52 52
53 public Vector3 ImplicitShapeDimensions { get { return _implicitShapeDimensions; } protected set { _implicitShapeDimensions = value; } } 53 public Vector3 ImplicitShapeDimensions { get { return _implicitShapeDimensions; } protected set { _implicitShapeDimensions = value; } }
54 public virtual int PreferredPenetrationDirectionsCount { get { return 0; } } 54 public virtual int PreferredPenetrationDirectionsCount { get { return 0; } }
55 55
56 protected float CollisionMargin { get { return _collisionMargin; } set { _collisionMargin = value; } } 56 protected float CollisionMargin { get { return _collisionMargin; } set { _collisionMargin = value; } }
57 57
58 public virtual void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector) 58 public virtual void GetPreferredPenetrationDirection(int index, out Vector3 penetrationVector)
59 { 59 {
60 penetrationVector = new Vector3(); 60 penetrationVector = new Vector3();
61 BulletDebug.Assert(false); 61 BulletDebug.Assert(false);
62 } 62 }
63 63
64 public abstract Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec); 64 public abstract Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec);
65 //notice that the vectors should be unit length 65 //notice that the vectors should be unit length
66 public abstract void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut); 66 public abstract void BatchedUnitVectorGetSupportingVertexWithoutMargin(Vector3[] vectors, Vector3[] supportVerticesOut);
67 67
68 /// <summary> 68 /// <summary>
69 /// getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version 69 /// getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
70 /// </summary> 70 /// </summary>
71 /// <param name="t"></param> 71 /// <param name="t"></param>
72 /// <param name="aabbMin"></param> 72 /// <param name="aabbMin"></param>
73 /// <param name="aabbMax"></param> 73 /// <param name="aabbMax"></param>
74 public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) 74 public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax)
75 { 75 {
76 GetAabbSlow(t, out aabbMin, out aabbMax); 76 GetAabbSlow(t, out aabbMin, out aabbMax);
77 } 77 }
78 78
79 public override Vector3 LocalScaling 79 public override Vector3 LocalScaling
80 { 80 {
81 get 81 get
82 { 82 {
83 return _localScaling; 83 return _localScaling;
84 } 84 }
85 set 85 set
86 { 86 {
87 _localScaling = value; 87 _localScaling = value;
88 } 88 }
89 } 89 }
90 90
91 public override float Margin 91 public override float Margin
92 { 92 {
93 get 93 get
94 { 94 {
95 return _collisionMargin; 95 return _collisionMargin;
96 } 96 }
97 set 97 set
98 { 98 {
99 _collisionMargin = value; 99 _collisionMargin = value;
100 } 100 }
101 } 101 }
102 102
103 public virtual Vector3 LocalGetSupportingVertex(Vector3 vec) 103 public virtual Vector3 LocalGetSupportingVertex(Vector3 vec)
104 { 104 {
105 Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec); 105 Vector3 supVertex = LocalGetSupportingVertexWithoutMargin(vec);
106 106
107 if (Margin != 0f) 107 if (Margin != 0f)
108 { 108 {
109 Vector3 vecnorm = vec; 109 Vector3 vecnorm = vec;
110 if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon)) 110 if (vecnorm.LengthSquared() < (MathHelper.Epsilon * MathHelper.Epsilon))
111 { 111 {
112 vecnorm = new Vector3(-1f, -1f, -1f); 112 vecnorm = new Vector3(-1f, -1f, -1f);
113 } 113 }
114 vecnorm.Normalize(); 114 vecnorm.Normalize();
115 supVertex += Margin * vecnorm; 115 supVertex += Margin * vecnorm;
116 } 116 }
117 return supVertex; 117 return supVertex;
118 } 118 }
119 119
120 public virtual void GetAabbSlow(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax) 120 public virtual void GetAabbSlow(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax)
121 { 121 {
122 float margin = Margin; 122 float margin = Margin;
123 aabbMax = new Vector3(); 123 aabbMax = new Vector3();
124 aabbMin = new Vector3(); 124 aabbMin = new Vector3();
125 125
126 for (int i = 0; i < 3; i++) 126 for (int i = 0; i < 3; i++)
127 { 127 {
128 Vector3 vec = new Vector3(0f, 0f, 0f); 128 Vector3 vec = new Vector3(0f, 0f, 0f);
129 MathHelper.SetElement(ref vec, i, 1); 129 MathHelper.SetElement(ref vec, i, 1);
130 130
131 Vector3 sv = LocalGetSupportingVertex(Vector3.TransformNormal(vec, t)); 131 Vector3 sv = LocalGetSupportingVertex(Vector3.TransformNormal(vec, t));
132 132
133 Vector3 tmp = MathHelper.MatrixToVector(t, sv); 133 Vector3 tmp = MathHelper.MatrixToVector(t, sv);
134 MathHelper.SetElement(ref aabbMax, i, MathHelper.GetElement(tmp, i) + margin); 134 MathHelper.SetElement(ref aabbMax, i, MathHelper.GetElement(tmp, i) + margin);
135 MathHelper.SetElement(ref vec, i, -1f); 135 MathHelper.SetElement(ref vec, i, -1f);
136 tmp = MathHelper.MatrixToVector(t, LocalGetSupportingVertex(Vector3.TransformNormal(vec, t))); 136 tmp = MathHelper.MatrixToVector(t, LocalGetSupportingVertex(Vector3.TransformNormal(vec, t)));
137 MathHelper.SetElement(ref aabbMin, i, MathHelper.GetElement(tmp, i) - margin); 137 MathHelper.SetElement(ref aabbMin, i, MathHelper.GetElement(tmp, i) - margin);
138 } 138 }
139 } 139 }
140 } 140 }
141} 141}