aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs')
-rw-r--r--libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs422
1 files changed, 211 insertions, 211 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs
index aa91a03..3430a73 100644
--- a/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs
+++ b/libraries/ModifiedBulletX/ModifiedBulletX/Dynamics/SimpleDynamicsWorld.cs
@@ -1,211 +1,211 @@
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.Dynamics 27namespace XnaDevRu.BulletX.Dynamics
28{ 28{
29 public class SimpleDynamicsWorld : DynamicsWorld 29 public class SimpleDynamicsWorld : DynamicsWorld
30 { 30 {
31 private IConstraintSolver _constraintSolver; 31 private IConstraintSolver _constraintSolver;
32 private bool _ownsConstraintSolver; 32 private bool _ownsConstraintSolver;
33 private Vector3 _gravity; 33 private Vector3 _gravity;
34 private IDebugDraw _debugDrawer; 34 private IDebugDraw _debugDrawer;
35 35
36 /// <summary> 36 /// <summary>
37 /// this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver 37 /// this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver
38 /// </summary> 38 /// </summary>
39 /// <param name="dispatcher"></param> 39 /// <param name="dispatcher"></param>
40 /// <param name="pairCache"></param> 40 /// <param name="pairCache"></param>
41 /// <param name="constraintSolver"></param> 41 /// <param name="constraintSolver"></param>
42 public SimpleDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver) 42 public SimpleDynamicsWorld(IDispatcher dispatcher, OverlappingPairCache pairCache, IConstraintSolver constraintSolver)
43 : base(dispatcher, pairCache) 43 : base(dispatcher, pairCache)
44 { 44 {
45 _constraintSolver = constraintSolver; 45 _constraintSolver = constraintSolver;
46 _ownsConstraintSolver = false; 46 _ownsConstraintSolver = false;
47 _gravity = new Vector3(0, 0, -10); 47 _gravity = new Vector3(0, 0, -10);
48 } 48 }
49 49
50 public override Vector3 Gravity 50 public override Vector3 Gravity
51 { 51 {
52 set 52 set
53 { 53 {
54 _gravity = value; 54 _gravity = value;
55 for (int i = 0; i < CollisionObjects.Count; i++) 55 for (int i = 0; i < CollisionObjects.Count; i++)
56 { 56 {
57 CollisionObject colObj = CollisionObjects[i]; 57 CollisionObject colObj = CollisionObjects[i];
58 RigidBody body = RigidBody.Upcast(colObj); 58 RigidBody body = RigidBody.Upcast(colObj);
59 if (body != null) 59 if (body != null)
60 { 60 {
61 body.Gravity = value; 61 body.Gravity = value;
62 } 62 }
63 } 63 }
64 } 64 }
65 } 65 }
66 66
67 public override IConstraintSolver ConstraintSolver 67 public override IConstraintSolver ConstraintSolver
68 { 68 {
69 set 69 set
70 { 70 {
71 _ownsConstraintSolver = false; 71 _ownsConstraintSolver = false;
72 _constraintSolver = value; 72 _constraintSolver = value;
73 } 73 }
74 } 74 }
75 75
76 public override IDebugDraw DebugDrawer 76 public override IDebugDraw DebugDrawer
77 { 77 {
78 get 78 get
79 { 79 {
80 return _debugDrawer; 80 return _debugDrawer;
81 } 81 }
82 set 82 set
83 { 83 {
84 _debugDrawer = value; 84 _debugDrawer = value;
85 } 85 }
86 } 86 }
87 87
88 public override void StepSimulation(float timeStep, int numSubsteps, float fixedTimeStep) 88 public override void StepSimulation(float timeStep, int numSubsteps, float fixedTimeStep)
89 { 89 {
90 //apply gravity, predict motion 90 //apply gravity, predict motion
91 PredictUnconstraintMotion(timeStep); 91 PredictUnconstraintMotion(timeStep);
92 92
93 DispatcherInfo dispatchInfo = new DispatcherInfo(); 93 DispatcherInfo dispatchInfo = new DispatcherInfo();
94 dispatchInfo.TimeStep = timeStep; 94 dispatchInfo.TimeStep = timeStep;
95 dispatchInfo.StepCount = 0; 95 dispatchInfo.StepCount = 0;
96 dispatchInfo.DebugDraw = DebugDrawer; 96 dispatchInfo.DebugDraw = DebugDrawer;
97 //perform collision detection 97 //perform collision detection
98 PerformDiscreteCollisionDetection(); 98 PerformDiscreteCollisionDetection();
99 99
100 //solve contact constraints 100 //solve contact constraints
101 int numManifolds = Dispatcher.ManifoldCount; 101 int numManifolds = Dispatcher.ManifoldCount;
102 if (numManifolds != 0) 102 if (numManifolds != 0)
103 { 103 {
104 104
105 List<PersistentManifold> manifolds = (Dispatcher as CollisionDispatcher).Manifolds; 105 List<PersistentManifold> manifolds = (Dispatcher as CollisionDispatcher).Manifolds;
106 //int numManifolds = m_dispatcher1.GetNumManifolds(); 106 //int numManifolds = m_dispatcher1.GetNumManifolds();
107 ContactSolverInfo infoGlobal = new ContactSolverInfo(); 107 ContactSolverInfo infoGlobal = new ContactSolverInfo();
108 infoGlobal.TimeStep = timeStep; 108 infoGlobal.TimeStep = timeStep;
109 109
110 _constraintSolver.SolveGroup(new List<CollisionObject>(), manifolds, manifolds.Count, new List<TypedConstraint>(), infoGlobal, _debugDrawer); 110 _constraintSolver.SolveGroup(new List<CollisionObject>(), manifolds, manifolds.Count, new List<TypedConstraint>(), infoGlobal, _debugDrawer);
111 } 111 }
112 //integrate transforms 112 //integrate transforms
113 IntegrateTransforms(timeStep); 113 IntegrateTransforms(timeStep);
114 114
115 UpdateAabbs(); 115 UpdateAabbs();
116 116
117 SynchronizeMotionStates(); 117 SynchronizeMotionStates();
118 } 118 }
119 119
120 public override void UpdateAabbs() 120 public override void UpdateAabbs()
121 { 121 {
122 for (int i = 0; i < CollisionObjects.Count; i++) 122 for (int i = 0; i < CollisionObjects.Count; i++)
123 { 123 {
124 CollisionObject colObj = CollisionObjects[i]; 124 CollisionObject colObj = CollisionObjects[i];
125 RigidBody body = RigidBody.Upcast(colObj); 125 RigidBody body = RigidBody.Upcast(colObj);
126 if (body != null) 126 if (body != null)
127 { 127 {
128 if (body.IsActive && (!body.IsStaticObject)) 128 if (body.IsActive && (!body.IsStaticObject))
129 { 129 {
130 Vector3 minAabb, maxAabb; 130 Vector3 minAabb, maxAabb;
131 colObj.CollisionShape.GetAabb(colObj.WorldTransform, out minAabb, out maxAabb); 131 colObj.CollisionShape.GetAabb(colObj.WorldTransform, out minAabb, out maxAabb);
132 IBroadphase bp = Broadphase; 132 IBroadphase bp = Broadphase;
133 bp.SetAabb(body.Broadphase, minAabb, maxAabb); 133 bp.SetAabb(body.Broadphase, minAabb, maxAabb);
134 } 134 }
135 } 135 }
136 } 136 }
137 } 137 }
138 138
139 public override void AddRigidBody(RigidBody body) 139 public override void AddRigidBody(RigidBody body)
140 { 140 {
141 body.Gravity = _gravity; 141 body.Gravity = _gravity;
142 142
143 if (body.CollisionShape != null) 143 if (body.CollisionShape != null)
144 { 144 {
145 AddCollisionObject(body); 145 AddCollisionObject(body);
146 } 146 }
147 } 147 }
148 148
149 public override void RemoveRigidBody(RigidBody body) 149 public override void RemoveRigidBody(RigidBody body)
150 { 150 {
151 RemoveCollisionObject(body); 151 RemoveCollisionObject(body);
152 } 152 }
153 153
154 public void SynchronizeMotionStates() 154 public void SynchronizeMotionStates()
155 { 155 {
156 for (int i = 0; i < CollisionObjects.Count; i++) 156 for (int i = 0; i < CollisionObjects.Count; i++)
157 { 157 {
158 CollisionObject colObj = CollisionObjects[i]; 158 CollisionObject colObj = CollisionObjects[i];
159 RigidBody body = RigidBody.Upcast(colObj); 159 RigidBody body = RigidBody.Upcast(colObj);
160 if (body != null && body.MotionState != null) 160 if (body != null && body.MotionState != null)
161 { 161 {
162 if (body.ActivationState != ActivationState.IslandSleeping) 162 if (body.ActivationState != ActivationState.IslandSleeping)
163 { 163 {
164 body.MotionState.SetWorldTransform(body.WorldTransform); 164 body.MotionState.SetWorldTransform(body.WorldTransform);
165 } 165 }
166 } 166 }
167 } 167 }
168 } 168 }
169 169
170 protected void PredictUnconstraintMotion(float timeStep) 170 protected void PredictUnconstraintMotion(float timeStep)
171 { 171 {
172 for (int i = 0; i < CollisionObjects.Count; i++) 172 for (int i = 0; i < CollisionObjects.Count; i++)
173 { 173 {
174 CollisionObject colObj = CollisionObjects[i]; 174 CollisionObject colObj = CollisionObjects[i];
175 RigidBody body = RigidBody.Upcast(colObj); 175 RigidBody body = RigidBody.Upcast(colObj);
176 if (body != null) 176 if (body != null)
177 { 177 {
178 if (!body.IsStaticObject) 178 if (!body.IsStaticObject)
179 { 179 {
180 if (body.IsActive) 180 if (body.IsActive)
181 { 181 {
182 body.ApplyForces(timeStep); 182 body.ApplyForces(timeStep);
183 body.IntegrateVelocities(timeStep); 183 body.IntegrateVelocities(timeStep);
184 Matrix temp = body.InterpolationWorldTransform; 184 Matrix temp = body.InterpolationWorldTransform;
185 body.PredictIntegratedTransform(timeStep, ref temp); 185 body.PredictIntegratedTransform(timeStep, ref temp);
186 body.InterpolationWorldTransform = temp; 186 body.InterpolationWorldTransform = temp;
187 } 187 }
188 } 188 }
189 } 189 }
190 } 190 }
191 } 191 }
192 192
193 protected void IntegrateTransforms(float timeStep) 193 protected void IntegrateTransforms(float timeStep)
194 { 194 {
195 Matrix predictedTrans = Matrix.Identity; 195 Matrix predictedTrans = Matrix.Identity;
196 for (int i = 0; i < CollisionObjects.Count; i++) 196 for (int i = 0; i < CollisionObjects.Count; i++)
197 { 197 {
198 CollisionObject colObj = CollisionObjects[i]; 198 CollisionObject colObj = CollisionObjects[i];
199 RigidBody body = RigidBody.Upcast(colObj); 199 RigidBody body = RigidBody.Upcast(colObj);
200 if (body != null) 200 if (body != null)
201 { 201 {
202 if (body.IsActive && (!body.IsStaticObject)) 202 if (body.IsActive && (!body.IsStaticObject))
203 { 203 {
204 body.PredictIntegratedTransform(timeStep, ref predictedTrans); 204 body.PredictIntegratedTransform(timeStep, ref predictedTrans);
205 body.ProceedToTransform(predictedTrans); 205 body.ProceedToTransform(predictedTrans);
206 } 206 }
207 } 207 }
208 } 208 }
209 } 209 }
210 } 210 }
211} 211}