aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StaticPlaneShape.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StaticPlaneShape.cs124
1 files changed, 124 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StaticPlaneShape.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StaticPlaneShape.cs
new file mode 100644
index 0000000..49604a0
--- /dev/null
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionShapes/StaticPlaneShape.cs
@@ -0,0 +1,124 @@
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 class StaticPlaneShape : ConcaveShape
30 {
31 private Vector3 _localAabbMin;
32 private Vector3 _localAabbMax;
33
34 private Vector3 _planeNormal;
35 private float _planeConstant;
36 private Vector3 _localScaling;
37
38 public StaticPlaneShape(Vector3 planeNormal, float planeConstant)
39 {
40 _planeNormal = planeNormal;
41 _planeConstant = planeConstant;
42 _localScaling = new Vector3();
43 }
44
45 protected Vector3 LocalAabbMin { get { return _localAabbMin; } set { _localAabbMin = value; } }
46 protected Vector3 LocalAabbMax { get { return _localAabbMax; } set { _localAabbMax = value; } }
47
48 protected Vector3 PlaneNormal { get { return _planeNormal; } set { _planeNormal = value; } }
49 protected float PlaneConstant { get { return _planeConstant; } set { _planeConstant = value; } }
50
51 public override BroadphaseNativeTypes ShapeType
52 {
53 get
54 {
55 return BroadphaseNativeTypes.StaticPlane;
56 }
57 }
58
59 public override Vector3 LocalScaling
60 {
61 get
62 {
63 return _localScaling;
64 }
65 set
66 {
67 _localScaling = value;
68 }
69 }
70
71 public override string Name
72 {
73 get
74 {
75 return "StaticPlane";
76 }
77 }
78
79 public override void GetAabb(Matrix t, out Vector3 aabbMin, out Vector3 aabbMax)
80 {
81 Vector3 infvec = new Vector3(1e30f, 1e30f, 1e30f);
82
83 Vector3 center = _planeNormal * _planeConstant;
84 aabbMin = center + infvec * _planeNormal;
85 aabbMax = aabbMin;
86 MathHelper.SetMin(ref aabbMin, center - infvec * _planeNormal);
87 MathHelper.SetMax(ref aabbMax, center - infvec * _planeNormal);
88
89 aabbMin = new Vector3(-1e30f, -1e30f, -1e30f);
90 aabbMax = new Vector3(1e30f, 1e30f, 1e30f);
91 }
92
93 public override void CalculateLocalInertia(float mass, out Vector3 inertia)
94 {
95 //moving concave objects not supported
96 inertia = new Vector3();
97 }
98
99 public override void ProcessAllTriangles(ITriangleCallback callback, Vector3 aabbMin, Vector3 aabbMax) {
100 Vector3 halfExtents = (aabbMax - aabbMin) * 0.5f;
101 float radius = halfExtents.Length();
102 Vector3 center = (aabbMax + aabbMin) * 0.5f;
103
104 //this is where the triangles are generated, given AABB and plane equation (normal/constant)
105 Vector3 tangentDir0 = new Vector3(), tangentDir1 = new Vector3();
106
107 //tangentDir0/tangentDir1 can be precalculated
108 MathHelper.PlaneSpace1(_planeNormal, ref tangentDir0, ref tangentDir1);
109
110 Vector3 projectedCenter = center - (Vector3.Dot(_planeNormal, center) - _planeConstant) * _planeNormal;
111
112 Vector3[] triangle = new Vector3[3];
113 triangle[0] = projectedCenter + tangentDir0 * radius + tangentDir1 * radius;
114 triangle[1] = projectedCenter + tangentDir0 * radius - tangentDir1 * radius;
115 triangle[2] = projectedCenter - tangentDir0 * radius - tangentDir1 * radius;
116 callback.ProcessTriangle(triangle, 0, 0);
117
118 triangle[0] = projectedCenter - tangentDir0 * radius - tangentDir1 * radius;
119 triangle[1] = projectedCenter - tangentDir0 * radius + tangentDir1 * radius;
120 triangle[2] = projectedCenter + tangentDir0 * radius + tangentDir1 * radius;
121 callback.ProcessTriangle(triangle, 0, 1);
122 }
123 }
124}