diff options
author | teravus | 2013-01-20 08:18:16 -0500 |
---|---|---|
committer | teravus | 2013-01-20 08:18:16 -0500 |
commit | 2c517d792f0440c2705458e01a5067628b6b2c7c (patch) | |
tree | e15a2fb08f80223138f19926c3d0f0cf20aff5c2 /OpenSim/Region/Physics | |
parent | * Dumping BulletSimNPlugin in favor of combining the API (diff) | |
download | opensim-SC_OLD-2c517d792f0440c2705458e01a5067628b6b2c7c.zip opensim-SC_OLD-2c517d792f0440c2705458e01a5067628b6b2c7c.tar.gz opensim-SC_OLD-2c517d792f0440c2705458e01a5067628b6b2c7c.tar.bz2 opensim-SC_OLD-2c517d792f0440c2705458e01a5067628b6b2c7c.tar.xz |
This updates prebuild to remove BulletSimN, implements the BulletSim API in BulletSPlugin using the BulletXNA Bullet physics engine. It also updates the BulletXNA library to be compatible with the changes. OpenSimDefaults has been updated to describe how to switch engines and terrain implementations.
Diffstat (limited to 'OpenSim/Region/Physics')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 885 |
1 files changed, 623 insertions, 262 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index b6ff52b..49b1730 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | |||
@@ -129,7 +129,12 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
129 | get { return "XNAConstraint"; } | 129 | get { return "XNAConstraint"; } |
130 | } | 130 | } |
131 | } | 131 | } |
132 | internal int m_maxCollisions; | ||
133 | internal CollisionDesc[] m_collisionArray; | ||
132 | 134 | ||
135 | internal int m_maxUpdatesPerFrame; | ||
136 | internal EntityProperties[] m_updateArray; | ||
137 | |||
133 | private static int m_collisionsThisFrame; | 138 | private static int m_collisionsThisFrame; |
134 | private BSScene PhysicsScene { get; set; } | 139 | private BSScene PhysicsScene { get; set; } |
135 | 140 | ||
@@ -148,92 +153,98 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
148 | /// <param name="p_2"></param> | 153 | /// <param name="p_2"></param> |
149 | public override bool RemoveObjectFromWorld(BulletWorld pWorld, BulletBody pBody) | 154 | public override bool RemoveObjectFromWorld(BulletWorld pWorld, BulletBody pBody) |
150 | { | 155 | { |
151 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 156 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
152 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 157 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; |
153 | world.RemoveRigidBody(body); | 158 | world.RemoveRigidBody(body); |
154 | return true; | 159 | return true; |
155 | } | 160 | } |
156 | 161 | ||
157 | public override bool AddConstraintToWorld(BulletWorld world, BulletConstraint constrain, bool disableCollisionsBetweenLinkedObjects) | 162 | public override bool AddConstraintToWorld(BulletWorld pWorld, BulletConstraint pConstraint, bool pDisableCollisionsBetweenLinkedObjects) |
158 | { | 163 | { |
159 | /* TODO */ | 164 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
160 | return false; | 165 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; |
166 | world.AddConstraint(constraint, pDisableCollisionsBetweenLinkedObjects); | ||
167 | |||
168 | return true; | ||
169 | |||
161 | } | 170 | } |
162 | 171 | ||
163 | public override bool RemoveConstraintFromWorld(BulletWorld world, BulletConstraint constrain) | 172 | public override bool RemoveConstraintFromWorld(BulletWorld pWorld, BulletConstraint pConstraint) |
164 | { | 173 | { |
165 | /* TODO */ | 174 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
166 | return false; | 175 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; |
176 | world.RemoveConstraint(constraint); | ||
177 | return true; | ||
167 | } | 178 | } |
168 | 179 | ||
169 | public override void SetRestitution(BulletBody pBody, float pRestitution) | 180 | public override void SetRestitution(BulletBody pCollisionObject, float pRestitution) |
170 | { | 181 | { |
171 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 182 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
172 | body.SetRestitution(pRestitution); | 183 | collisionObject.SetRestitution(pRestitution); |
173 | } | 184 | } |
174 | 185 | ||
175 | public override int GetShapeType(BulletShape pShape) | 186 | public override int GetShapeType(BulletShape pShape) |
176 | { | 187 | { |
177 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 188 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
178 | return (int)shape.GetShapeType(); | 189 | return (int)shape.GetShapeType(); |
179 | } | 190 | } |
180 | public override void SetMargin(BulletShape pShape, float pMargin) | 191 | public override void SetMargin(BulletShape pShape, float pMargin) |
181 | { | 192 | { |
182 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 193 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
183 | shape.SetMargin(pMargin); | 194 | shape.SetMargin(pMargin); |
184 | } | 195 | } |
185 | 196 | ||
186 | public override float GetMargin(BulletShape pShape) | 197 | public override float GetMargin(BulletShape pShape) |
187 | { | 198 | { |
188 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 199 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
189 | return shape.GetMargin(); | 200 | return shape.GetMargin(); |
190 | } | 201 | } |
191 | 202 | ||
192 | public override void SetLocalScaling(BulletShape pShape, Vector3 pScale) | 203 | public override void SetLocalScaling(BulletShape pShape, Vector3 pScale) |
193 | { | 204 | { |
194 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 205 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
195 | IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); | 206 | IndexedVector3 vec = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); |
196 | shape.SetLocalScaling(ref vec); | 207 | shape.SetLocalScaling(ref vec); |
197 | 208 | ||
198 | } | 209 | } |
199 | 210 | ||
200 | public override void SetContactProcessingThreshold(BulletBody pBody, float contactprocessingthreshold) | 211 | public override void SetContactProcessingThreshold(BulletBody pCollisionObject, float contactprocessingthreshold) |
201 | { | 212 | { |
202 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 213 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
203 | body.SetContactProcessingThreshold(contactprocessingthreshold); | 214 | collisionObject.SetContactProcessingThreshold(contactprocessingthreshold); |
204 | } | 215 | } |
205 | 216 | ||
206 | public override void SetCcdMotionThreshold(BulletBody pBody, float pccdMotionThreashold) | 217 | public override void SetCcdMotionThreshold(BulletBody pCollisionObject, float pccdMotionThreashold) |
207 | { | 218 | { |
208 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 219 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
209 | body.SetCcdMotionThreshold(pccdMotionThreashold); | 220 | collisionObject.SetCcdMotionThreshold(pccdMotionThreashold); |
210 | } | 221 | } |
211 | 222 | ||
212 | public override void SetCcdSweptSphereRadius(BulletBody pBody, float pCcdSweptSphereRadius) | 223 | public override void SetCcdSweptSphereRadius(BulletBody pCollisionObject, float pCcdSweptSphereRadius) |
213 | { | 224 | { |
214 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 225 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
215 | body.SetCcdSweptSphereRadius(pCcdSweptSphereRadius); | 226 | collisionObject.SetCcdSweptSphereRadius(pCcdSweptSphereRadius); |
216 | } | 227 | } |
217 | 228 | ||
218 | public override void SetAngularFactorV(BulletBody pBody, Vector3 pAngularFactor) | 229 | public override void SetAngularFactorV(BulletBody pBody, Vector3 pAngularFactor) |
219 | { | 230 | { |
220 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 231 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
221 | body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z)); | 232 | body.SetAngularFactor(new IndexedVector3(pAngularFactor.X, pAngularFactor.Y, pAngularFactor.Z)); |
222 | } | 233 | } |
223 | 234 | ||
224 | public override CollisionFlags AddToCollisionFlags(BulletBody pBody, CollisionFlags pcollisionFlags) | 235 | public override CollisionFlags AddToCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags) |
225 | { | 236 | { |
226 | CollisionObject body = ((BulletBodyXNA)pBody).body; | 237 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
227 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags(); | 238 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags(); |
228 | existingcollisionFlags |= pcollisionFlags; | 239 | existingcollisionFlags |= pcollisionFlags; |
229 | body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | 240 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); |
230 | return (CollisionFlags) (uint) existingcollisionFlags; | 241 | return (CollisionFlags) (uint) existingcollisionFlags; |
231 | } | 242 | } |
232 | 243 | ||
233 | public override bool AddObjectToWorld(BulletWorld pWorld, BulletBody pBody) | 244 | public override bool AddObjectToWorld(BulletWorld pWorld, BulletBody pBody) |
234 | { | 245 | { |
235 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 246 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
236 | CollisionObject cbody = ((BulletBodyXNA)pBody).body; | 247 | CollisionObject cbody = (pBody as BulletBodyXNA).body; |
237 | RigidBody rbody = cbody as RigidBody; | 248 | RigidBody rbody = cbody as RigidBody; |
238 | 249 | ||
239 | // Bullet resets several variables when an object is added to the world. In particular, | 250 | // Bullet resets several variables when an object is added to the world. In particular, |
@@ -259,99 +270,110 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
259 | return true; | 270 | return true; |
260 | } | 271 | } |
261 | 272 | ||
262 | public override void ForceActivationState(BulletBody pBody, ActivationState pActivationState) | 273 | public override void ForceActivationState(BulletBody pCollisionObject, ActivationState pActivationState) |
263 | { | 274 | { |
264 | CollisionObject body = ((BulletBodyXNA)pBody).body; | 275 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
265 | body.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState); | 276 | collisionObject.ForceActivationState((BulletXNA.BulletCollision.ActivationState)(uint)pActivationState); |
266 | } | 277 | } |
267 | 278 | ||
268 | public override void UpdateSingleAabb(BulletWorld pWorld, BulletBody pBody) | 279 | public override void UpdateSingleAabb(BulletWorld pWorld, BulletBody pCollisionObject) |
269 | { | 280 | { |
270 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 281 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
271 | CollisionObject body = ((BulletBodyXNA)pBody).body; | 282 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
272 | world.UpdateSingleAabb(body); | 283 | world.UpdateSingleAabb(collisionObject); |
273 | } | 284 | } |
274 | 285 | ||
275 | public override void UpdateAabbs(BulletWorld world) { /* TODO */ } | 286 | public override void UpdateAabbs(BulletWorld pWorld) { |
276 | public override bool GetForceUpdateAllAabbs(BulletWorld world) { /* TODO */ return false; } | 287 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
277 | public override void SetForceUpdateAllAabbs(BulletWorld world, bool force) { /* TODO */ } | 288 | world.UpdateAabbs(); |
289 | } | ||
290 | public override bool GetForceUpdateAllAabbs(BulletWorld pWorld) { | ||
291 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
292 | return world.GetForceUpdateAllAabbs(); | ||
293 | |||
294 | } | ||
295 | public override void SetForceUpdateAllAabbs(BulletWorld pWorld, bool pForce) | ||
296 | { | ||
297 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; | ||
298 | world.SetForceUpdateAllAabbs(pForce); | ||
299 | } | ||
278 | 300 | ||
279 | public override bool SetCollisionGroupMask(BulletBody pBody, uint pGroup, uint pMask) | 301 | public override bool SetCollisionGroupMask(BulletBody pCollisionObject, uint pGroup, uint pMask) |
280 | { | 302 | { |
281 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 303 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
282 | body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | 304 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; |
283 | body.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; | 305 | collisionObject.GetBroadphaseHandle().m_collisionFilterGroup = (BulletXNA.BulletCollision.CollisionFilterGroups) pGroup; |
284 | if ((uint) body.GetBroadphaseHandle().m_collisionFilterGroup == 0) | 306 | if ((uint) collisionObject.GetBroadphaseHandle().m_collisionFilterGroup == 0) |
285 | return false; | 307 | return false; |
286 | return true; | 308 | return true; |
287 | } | 309 | } |
288 | 310 | ||
289 | public override void ClearAllForces(BulletBody pBody) | 311 | public override void ClearAllForces(BulletBody pCollisionObject) |
290 | { | 312 | { |
291 | CollisionObject body = ((BulletBodyXNA)pBody).body; | 313 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
292 | IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0); | 314 | IndexedVector3 zeroVector = new IndexedVector3(0, 0, 0); |
293 | body.SetInterpolationLinearVelocity(ref zeroVector); | 315 | collisionObject.SetInterpolationLinearVelocity(ref zeroVector); |
294 | body.SetInterpolationAngularVelocity(ref zeroVector); | 316 | collisionObject.SetInterpolationAngularVelocity(ref zeroVector); |
295 | IndexedMatrix bodytransform = body.GetWorldTransform(); | 317 | IndexedMatrix bodytransform = collisionObject.GetWorldTransform(); |
296 | 318 | ||
297 | body.SetInterpolationWorldTransform(ref bodytransform); | 319 | collisionObject.SetInterpolationWorldTransform(ref bodytransform); |
298 | 320 | ||
299 | if (body is RigidBody) | 321 | if (collisionObject is RigidBody) |
300 | { | 322 | { |
301 | RigidBody rigidbody = body as RigidBody; | 323 | RigidBody rigidbody = collisionObject as RigidBody; |
302 | rigidbody.SetLinearVelocity(zeroVector); | 324 | rigidbody.SetLinearVelocity(zeroVector); |
303 | rigidbody.SetAngularVelocity(zeroVector); | 325 | rigidbody.SetAngularVelocity(zeroVector); |
304 | rigidbody.ClearForces(); | 326 | rigidbody.ClearForces(); |
305 | } | 327 | } |
306 | } | 328 | } |
307 | 329 | ||
308 | public override void SetInterpolationAngularVelocity(BulletBody pBody, Vector3 pVector3) | 330 | public override void SetInterpolationAngularVelocity(BulletBody pCollisionObject, Vector3 pVector3) |
309 | { | 331 | { |
310 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 332 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
311 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); | 333 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); |
312 | body.SetInterpolationAngularVelocity(ref vec); | 334 | collisionObject.SetInterpolationAngularVelocity(ref vec); |
313 | } | 335 | } |
314 | 336 | ||
315 | public override void SetAngularVelocity(BulletBody pBody, Vector3 pVector3) | 337 | public override void SetAngularVelocity(BulletBody pBody, Vector3 pVector3) |
316 | { | 338 | { |
317 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 339 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
318 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); | 340 | IndexedVector3 vec = new IndexedVector3(pVector3.X, pVector3.Y, pVector3.Z); |
319 | body.SetAngularVelocity(ref vec); | 341 | body.SetAngularVelocity(ref vec); |
320 | } | 342 | } |
321 | public override Vector3 GetTotalForce(BulletBody pBody) | 343 | public override Vector3 GetTotalForce(BulletBody pBody) |
322 | { | 344 | { |
323 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 345 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
324 | IndexedVector3 iv3 = body.GetTotalForce(); | 346 | IndexedVector3 iv3 = body.GetTotalForce(); |
325 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 347 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
326 | } | 348 | } |
327 | public override Vector3 GetTotalTorque(BulletBody pBody) | 349 | public override Vector3 GetTotalTorque(BulletBody pBody) |
328 | { | 350 | { |
329 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 351 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
330 | IndexedVector3 iv3 = body.GetTotalTorque(); | 352 | IndexedVector3 iv3 = body.GetTotalTorque(); |
331 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 353 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
332 | } | 354 | } |
333 | public override Vector3 GetInvInertiaDiagLocal(BulletBody pBody) | 355 | public override Vector3 GetInvInertiaDiagLocal(BulletBody pBody) |
334 | { | 356 | { |
335 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 357 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
336 | IndexedVector3 iv3 = body.GetInvInertiaDiagLocal(); | 358 | IndexedVector3 iv3 = body.GetInvInertiaDiagLocal(); |
337 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 359 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
338 | } | 360 | } |
339 | public override void SetInvInertiaDiagLocal(BulletBody pBody, Vector3 inert) | 361 | public override void SetInvInertiaDiagLocal(BulletBody pBody, Vector3 inert) |
340 | { | 362 | { |
341 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 363 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
342 | IndexedVector3 iv3 = new IndexedVector3(inert.X, inert.Y, inert.Z); | 364 | IndexedVector3 iv3 = new IndexedVector3(inert.X, inert.Y, inert.Z); |
343 | body.SetInvInertiaDiagLocal(ref iv3); | 365 | body.SetInvInertiaDiagLocal(ref iv3); |
344 | } | 366 | } |
345 | public override void ApplyForce(BulletBody pBody, Vector3 force, Vector3 pos) | 367 | public override void ApplyForce(BulletBody pBody, Vector3 force, Vector3 pos) |
346 | { | 368 | { |
347 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 369 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
348 | IndexedVector3 forceiv3 = new IndexedVector3(force.X, force.Y, force.Z); | 370 | IndexedVector3 forceiv3 = new IndexedVector3(force.X, force.Y, force.Z); |
349 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); | 371 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); |
350 | body.ApplyForce(ref forceiv3, ref posiv3); | 372 | body.ApplyForce(ref forceiv3, ref posiv3); |
351 | } | 373 | } |
352 | public override void ApplyImpulse(BulletBody pBody, Vector3 imp, Vector3 pos) | 374 | public override void ApplyImpulse(BulletBody pBody, Vector3 imp, Vector3 pos) |
353 | { | 375 | { |
354 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 376 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
355 | IndexedVector3 impiv3 = new IndexedVector3(imp.X, imp.Y, imp.Z); | 377 | IndexedVector3 impiv3 = new IndexedVector3(imp.X, imp.Y, imp.Z); |
356 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); | 378 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); |
357 | body.ApplyImpulse(ref impiv3, ref posiv3); | 379 | body.ApplyImpulse(ref impiv3, ref posiv3); |
@@ -359,32 +381,32 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
359 | 381 | ||
360 | public override void ClearForces(BulletBody pBody) | 382 | public override void ClearForces(BulletBody pBody) |
361 | { | 383 | { |
362 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 384 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
363 | body.ClearForces(); | 385 | body.ClearForces(); |
364 | } | 386 | } |
365 | 387 | ||
366 | public override void SetTranslation(BulletBody pBody, Vector3 _position, Quaternion _orientation) | 388 | public override void SetTranslation(BulletBody pCollisionObject, Vector3 _position, Quaternion _orientation) |
367 | { | 389 | { |
368 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 390 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
369 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); | 391 | IndexedVector3 vposition = new IndexedVector3(_position.X, _position.Y, _position.Z); |
370 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, | 392 | IndexedQuaternion vquaternion = new IndexedQuaternion(_orientation.X, _orientation.Y, _orientation.Z, |
371 | _orientation.W); | 393 | _orientation.W); |
372 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); | 394 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(vquaternion); |
373 | mat._origin = vposition; | 395 | mat._origin = vposition; |
374 | body.SetWorldTransform(mat); | 396 | collisionObject.SetWorldTransform(mat); |
375 | 397 | ||
376 | } | 398 | } |
377 | 399 | ||
378 | public override Vector3 GetPosition(BulletBody pBody) | 400 | public override Vector3 GetPosition(BulletBody pCollisionObject) |
379 | { | 401 | { |
380 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 402 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
381 | IndexedVector3 pos = body.GetInterpolationWorldTransform()._origin; | 403 | IndexedVector3 pos = collisionObject.GetInterpolationWorldTransform()._origin; |
382 | return new Vector3(pos.X, pos.Y, pos.Z); | 404 | return new Vector3(pos.X, pos.Y, pos.Z); |
383 | } | 405 | } |
384 | 406 | ||
385 | public override Vector3 CalculateLocalInertia(BulletShape pShape, float pphysMass) | 407 | public override Vector3 CalculateLocalInertia(BulletShape pShape, float pphysMass) |
386 | { | 408 | { |
387 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 409 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
388 | IndexedVector3 inertia = IndexedVector3.Zero; | 410 | IndexedVector3 inertia = IndexedVector3.Zero; |
389 | shape.CalculateLocalInertia(pphysMass, out inertia); | 411 | shape.CalculateLocalInertia(pphysMass, out inertia); |
390 | return new Vector3(inertia.X, inertia.Y, inertia.Z); | 412 | return new Vector3(inertia.X, inertia.Y, inertia.Z); |
@@ -392,7 +414,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
392 | 414 | ||
393 | public override void SetMassProps(BulletBody pBody, float pphysMass, Vector3 plocalInertia) | 415 | public override void SetMassProps(BulletBody pBody, float pphysMass, Vector3 plocalInertia) |
394 | { | 416 | { |
395 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 417 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
396 | IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z); | 418 | IndexedVector3 inertia = new IndexedVector3(plocalInertia.X, plocalInertia.Y, plocalInertia.Z); |
397 | body.SetMassProps(pphysMass, inertia); | 419 | body.SetMassProps(pphysMass, inertia); |
398 | } | 420 | } |
@@ -400,73 +422,90 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
400 | 422 | ||
401 | public override void SetObjectForce(BulletBody pBody, Vector3 _force) | 423 | public override void SetObjectForce(BulletBody pBody, Vector3 _force) |
402 | { | 424 | { |
403 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 425 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
404 | IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z); | 426 | IndexedVector3 force = new IndexedVector3(_force.X, _force.Y, _force.Z); |
405 | body.SetTotalForce(ref force); | 427 | body.SetTotalForce(ref force); |
406 | } | 428 | } |
407 | 429 | ||
408 | public override void SetFriction(BulletBody pBody, float _currentFriction) | 430 | public override void SetFriction(BulletBody pCollisionObject, float _currentFriction) |
409 | { | 431 | { |
410 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 432 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
411 | body.SetFriction(_currentFriction); | 433 | collisionObject.SetFriction(_currentFriction); |
412 | } | 434 | } |
413 | 435 | ||
414 | public override void SetLinearVelocity(BulletBody pBody, Vector3 _velocity) | 436 | public override void SetLinearVelocity(BulletBody pBody, Vector3 _velocity) |
415 | { | 437 | { |
416 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 438 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
417 | IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z); | 439 | IndexedVector3 velocity = new IndexedVector3(_velocity.X, _velocity.Y, _velocity.Z); |
418 | body.SetLinearVelocity(velocity); | 440 | body.SetLinearVelocity(velocity); |
419 | } | 441 | } |
420 | 442 | ||
421 | public override void Activate(BulletBody pBody, bool pforceactivation) | 443 | public override void Activate(BulletBody pCollisionObject, bool pforceactivation) |
422 | { | 444 | { |
423 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 445 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
424 | body.Activate(pforceactivation); | 446 | collisionObject.Activate(pforceactivation); |
425 | 447 | ||
426 | } | 448 | } |
427 | 449 | ||
428 | public override Quaternion GetOrientation(BulletBody pBody) | 450 | public override Quaternion GetOrientation(BulletBody pCollisionObject) |
429 | { | 451 | { |
430 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 452 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
431 | IndexedQuaternion mat = body.GetInterpolationWorldTransform().GetRotation(); | 453 | IndexedQuaternion mat = collisionObject.GetInterpolationWorldTransform().GetRotation(); |
432 | return new Quaternion(mat.X, mat.Y, mat.Z, mat.W); | 454 | return new Quaternion(mat.X, mat.Y, mat.Z, mat.W); |
433 | } | 455 | } |
434 | 456 | ||
435 | public override CollisionFlags RemoveFromCollisionFlags(BulletBody pBody, CollisionFlags pcollisionFlags) | 457 | public override CollisionFlags RemoveFromCollisionFlags(BulletBody pCollisionObject, CollisionFlags pcollisionFlags) |
436 | { | 458 | { |
437 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 459 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
438 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)body.GetCollisionFlags(); | 460 | CollisionFlags existingcollisionFlags = (CollisionFlags)(uint)collisionObject.GetCollisionFlags(); |
439 | existingcollisionFlags &= ~pcollisionFlags; | 461 | existingcollisionFlags &= ~pcollisionFlags; |
440 | body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); | 462 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags)(uint)existingcollisionFlags); |
441 | return (CollisionFlags)(uint)existingcollisionFlags; | 463 | return (CollisionFlags)(uint)existingcollisionFlags; |
442 | } | 464 | } |
443 | 465 | ||
444 | public override float GetCcdMotionThreshold(BulletBody obj) { /* TODO */ return 0f; } | 466 | public override float GetCcdMotionThreshold(BulletBody pCollisionObject) |
467 | { | ||
468 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
469 | return collisionObject.GetCcdSquareMotionThreshold(); | ||
470 | } | ||
445 | 471 | ||
446 | public override float GetCcdSweptSphereRadius(BulletBody obj) { /* TODO */ return 0f; } | 472 | public override float GetCcdSweptSphereRadius(BulletBody pCollisionObject) |
473 | { | ||
474 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
475 | return collisionObject.GetCcdSweptSphereRadius(); | ||
476 | |||
477 | } | ||
447 | 478 | ||
448 | public override IntPtr GetUserPointer(BulletBody obj) { /* TODO */ return IntPtr.Zero; } | 479 | public override IntPtr GetUserPointer(BulletBody pCollisionObject) |
480 | { | ||
481 | CollisionObject shape = (pCollisionObject as BulletBodyXNA).body; | ||
482 | return (IntPtr)shape.GetUserPointer(); | ||
483 | } | ||
449 | 484 | ||
450 | public override void SetUserPointer(BulletBody obj, IntPtr val) { /* TODO */ } | 485 | public override void SetUserPointer(BulletBody pCollisionObject, IntPtr val) |
486 | { | ||
487 | CollisionObject shape = (pCollisionObject as BulletBodyXNA).body; | ||
488 | shape.SetUserPointer(val); | ||
489 | } | ||
451 | 490 | ||
452 | public override void SetGravity(BulletBody pBody, Vector3 pGravity) | 491 | public override void SetGravity(BulletBody pBody, Vector3 pGravity) |
453 | { | 492 | { |
454 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 493 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
455 | IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z); | 494 | IndexedVector3 gravity = new IndexedVector3(pGravity.X, pGravity.Y, pGravity.Z); |
456 | body.SetGravity(gravity); | 495 | body.SetGravity(gravity); |
457 | } | 496 | } |
458 | 497 | ||
459 | public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint) | 498 | public override bool DestroyConstraint(BulletWorld pWorld, BulletConstraint pConstraint) |
460 | { | 499 | { |
461 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 500 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
462 | TypedConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain; | 501 | TypedConstraint constraint = (pConstraint as BulletConstraintXNA).constrain; |
463 | world.RemoveConstraint(constraint); | 502 | world.RemoveConstraint(constraint); |
464 | return true; | 503 | return true; |
465 | } | 504 | } |
466 | 505 | ||
467 | public override bool SetLinearLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high) | 506 | public override bool SetLinearLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high) |
468 | { | 507 | { |
469 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 508 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
470 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); | 509 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); |
471 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); | 510 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); |
472 | constraint.SetLinearLowerLimit(lowlimit); | 511 | constraint.SetLinearLowerLimit(lowlimit); |
@@ -476,7 +515,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
476 | 515 | ||
477 | public override bool SetAngularLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high) | 516 | public override bool SetAngularLimits(BulletConstraint pConstraint, Vector3 low, Vector3 high) |
478 | { | 517 | { |
479 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 518 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
480 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); | 519 | IndexedVector3 lowlimit = new IndexedVector3(low.X, low.Y, low.Z); |
481 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); | 520 | IndexedVector3 highlimit = new IndexedVector3(high.X, high.Y, high.Z); |
482 | constraint.SetAngularLowerLimit(lowlimit); | 521 | constraint.SetAngularLowerLimit(lowlimit); |
@@ -486,20 +525,20 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
486 | 525 | ||
487 | public override void SetConstraintNumSolverIterations(BulletConstraint pConstraint, float cnt) | 526 | public override void SetConstraintNumSolverIterations(BulletConstraint pConstraint, float cnt) |
488 | { | 527 | { |
489 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 528 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
490 | constraint.SetOverrideNumSolverIterations((int)cnt); | 529 | constraint.SetOverrideNumSolverIterations((int)cnt); |
491 | } | 530 | } |
492 | 531 | ||
493 | public override bool CalculateTransforms(BulletConstraint pConstraint) | 532 | public override bool CalculateTransforms(BulletConstraint pConstraint) |
494 | { | 533 | { |
495 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 534 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
496 | constraint.CalculateTransforms(); | 535 | constraint.CalculateTransforms(); |
497 | return true; | 536 | return true; |
498 | } | 537 | } |
499 | 538 | ||
500 | public override void SetConstraintEnable(BulletConstraint pConstraint, float p_2) | 539 | public override void SetConstraintEnable(BulletConstraint pConstraint, float p_2) |
501 | { | 540 | { |
502 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 541 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
503 | constraint.SetEnabled((p_2 == 0) ? false : true); | 542 | constraint.SetEnabled((p_2 == 0) ? false : true); |
504 | } | 543 | } |
505 | 544 | ||
@@ -508,9 +547,9 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
508 | public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | 547 | public override BulletConstraint Create6DofConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) |
509 | 548 | ||
510 | { | 549 | { |
511 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 550 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
512 | RigidBody body1 = ((BulletBodyXNA)pBody1).rigidBody; | 551 | RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody; |
513 | RigidBody body2 = ((BulletBodyXNA)pBody2).rigidBody; | 552 | RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody; |
514 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); | 553 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); |
515 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); | 554 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); |
516 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); | 555 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); |
@@ -542,9 +581,9 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
542 | /// <returns></returns> | 581 | /// <returns></returns> |
543 | public override BulletConstraint Create6DofConstraintToPoint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | 582 | public override BulletConstraint Create6DofConstraintToPoint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 pjoinPoint, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) |
544 | { | 583 | { |
545 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 584 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
546 | RigidBody body1 = ((BulletBodyXNA)pBody1).rigidBody; | 585 | RigidBody body1 = (pBody1 as BulletBodyXNA).rigidBody; |
547 | RigidBody body2 = ((BulletBodyXNA)pBody2).rigidBody; | 586 | RigidBody body2 = (pBody2 as BulletBodyXNA).rigidBody; |
548 | IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); | 587 | IndexedMatrix frame1 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); |
549 | IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); | 588 | IndexedMatrix frame2 = new IndexedMatrix(IndexedBasisMatrix.Identity, new IndexedVector3(0, 0, 0)); |
550 | 589 | ||
@@ -563,7 +602,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
563 | //SetFrames(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); | 602 | //SetFrames(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); |
564 | public override bool SetFrames(BulletConstraint pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot) | 603 | public override bool SetFrames(BulletConstraint pConstraint, Vector3 pframe1, Quaternion pframe1rot, Vector3 pframe2, Quaternion pframe2rot) |
565 | { | 604 | { |
566 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 605 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
567 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); | 606 | IndexedVector3 frame1v = new IndexedVector3(pframe1.X, pframe1.Y, pframe1.Z); |
568 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); | 607 | IndexedQuaternion frame1rot = new IndexedQuaternion(pframe1rot.X, pframe1rot.Y, pframe1rot.Z, pframe1rot.W); |
569 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); | 608 | IndexedMatrix frame1 = IndexedMatrix.CreateFromQuaternion(frame1rot); |
@@ -579,109 +618,110 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
579 | 618 | ||
580 | public override Vector3 GetLinearVelocity(BulletBody pBody) | 619 | public override Vector3 GetLinearVelocity(BulletBody pBody) |
581 | { | 620 | { |
582 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 621 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
583 | IndexedVector3 iv3 = body.GetLinearVelocity(); | 622 | IndexedVector3 iv3 = body.GetLinearVelocity(); |
584 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 623 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
585 | } | 624 | } |
586 | public override Vector3 GetAngularVelocity(BulletBody pBody) | 625 | public override Vector3 GetAngularVelocity(BulletBody pBody) |
587 | { | 626 | { |
588 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 627 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
589 | IndexedVector3 iv3 = body.GetAngularVelocity(); | 628 | IndexedVector3 iv3 = body.GetAngularVelocity(); |
590 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 629 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
591 | } | 630 | } |
592 | public override Vector3 GetVelocityInLocalPoint(BulletBody pBody, Vector3 pos) | 631 | public override Vector3 GetVelocityInLocalPoint(BulletBody pBody, Vector3 pos) |
593 | { | 632 | { |
594 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 633 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
595 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); | 634 | IndexedVector3 posiv3 = new IndexedVector3(pos.X, pos.Y, pos.Z); |
596 | IndexedVector3 iv3 = body.GetVelocityInLocalPoint(ref posiv3); | 635 | IndexedVector3 iv3 = body.GetVelocityInLocalPoint(ref posiv3); |
597 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 636 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
598 | } | 637 | } |
599 | public override void Translate(BulletBody pBody, Vector3 trans) | 638 | public override void Translate(BulletBody pCollisionObject, Vector3 trans) |
600 | { | 639 | { |
601 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 640 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
641 | collisionObject.Translate(new IndexedVector3(trans.X,trans.Y,trans.Z)); | ||
602 | } | 642 | } |
603 | public override void UpdateDeactivation(BulletBody pBody, float timeStep) | 643 | public override void UpdateDeactivation(BulletBody pBody, float timeStep) |
604 | { | 644 | { |
605 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 645 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
606 | body.UpdateDeactivation(timeStep); | 646 | body.UpdateDeactivation(timeStep); |
607 | } | 647 | } |
608 | 648 | ||
609 | public override bool WantsSleeping(BulletBody pBody) | 649 | public override bool WantsSleeping(BulletBody pBody) |
610 | { | 650 | { |
611 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 651 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
612 | return body.WantsSleeping(); | 652 | return body.WantsSleeping(); |
613 | } | 653 | } |
614 | 654 | ||
615 | public override void SetAngularFactor(BulletBody pBody, float factor) | 655 | public override void SetAngularFactor(BulletBody pBody, float factor) |
616 | { | 656 | { |
617 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 657 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
618 | body.SetAngularFactor(factor); | 658 | body.SetAngularFactor(factor); |
619 | } | 659 | } |
620 | 660 | ||
621 | public override Vector3 GetAngularFactor(BulletBody pBody) | 661 | public override Vector3 GetAngularFactor(BulletBody pBody) |
622 | { | 662 | { |
623 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 663 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
624 | IndexedVector3 iv3 = body.GetAngularFactor(); | 664 | IndexedVector3 iv3 = body.GetAngularFactor(); |
625 | return new Vector3(iv3.X, iv3.Y, iv3.Z); | 665 | return new Vector3(iv3.X, iv3.Y, iv3.Z); |
626 | } | 666 | } |
627 | 667 | ||
628 | public override bool IsInWorld(BulletWorld pWorld, BulletBody pBody) | 668 | public override bool IsInWorld(BulletWorld pWorld, BulletBody pCollisionObject) |
629 | { | 669 | { |
630 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 670 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
631 | CollisionObject body = ((BulletBodyXNA)pBody).body; | 671 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
632 | return world.IsInWorld(body); | 672 | return world.IsInWorld(collisionObject); |
633 | } | 673 | } |
634 | 674 | ||
635 | public override void AddConstraintRef(BulletBody pBody, BulletConstraint pConstrain) | 675 | public override void AddConstraintRef(BulletBody pBody, BulletConstraint pConstraint) |
636 | { | 676 | { |
637 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 677 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
638 | TypedConstraint constrain = ((BulletConstraintXNA)pConstrain).constrain; | 678 | TypedConstraint constrain = (pConstraint as BulletConstraintXNA).constrain; |
639 | body.AddConstraintRef(constrain); | 679 | body.AddConstraintRef(constrain); |
640 | } | 680 | } |
641 | 681 | ||
642 | public override void RemoveConstraintRef(BulletBody pBody, BulletConstraint pConstrain) | 682 | public override void RemoveConstraintRef(BulletBody pBody, BulletConstraint pConstraint) |
643 | { | 683 | { |
644 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 684 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
645 | TypedConstraint constrain = ((BulletConstraintXNA)pConstrain).constrain; | 685 | TypedConstraint constrain = (pConstraint as BulletConstraintXNA).constrain; |
646 | body.RemoveConstraintRef(constrain); | 686 | body.RemoveConstraintRef(constrain); |
647 | } | 687 | } |
648 | 688 | ||
649 | public override BulletConstraint GetConstraintRef(BulletBody pBody, int index) | 689 | public override BulletConstraint GetConstraintRef(BulletBody pBody, int index) |
650 | { | 690 | { |
651 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 691 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
652 | return new BulletConstraintXNA(body.GetConstraintRef(index)); | 692 | return new BulletConstraintXNA(body.GetConstraintRef(index)); |
653 | } | 693 | } |
654 | 694 | ||
655 | public override int GetNumConstraintRefs(BulletBody pBody) | 695 | public override int GetNumConstraintRefs(BulletBody pBody) |
656 | { | 696 | { |
657 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 697 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
658 | return body.GetNumConstraintRefs(); | 698 | return body.GetNumConstraintRefs(); |
659 | } | 699 | } |
660 | 700 | ||
661 | public override void SetInterpolationLinearVelocity(BulletBody pBody, Vector3 VehicleVelocity) | 701 | public override void SetInterpolationLinearVelocity(BulletBody pCollisionObject, Vector3 VehicleVelocity) |
662 | { | 702 | { |
663 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 703 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
664 | IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z); | 704 | IndexedVector3 velocity = new IndexedVector3(VehicleVelocity.X, VehicleVelocity.Y, VehicleVelocity.Z); |
665 | body.SetInterpolationLinearVelocity(ref velocity); | 705 | collisionObject.SetInterpolationLinearVelocity(ref velocity); |
666 | } | 706 | } |
667 | 707 | ||
668 | public override bool UseFrameOffset(BulletConstraint pConstraint, float onOff) | 708 | public override bool UseFrameOffset(BulletConstraint pConstraint, float onOff) |
669 | { | 709 | { |
670 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 710 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
671 | constraint.SetUseFrameOffset((onOff == 0) ? false : true); | 711 | constraint.SetUseFrameOffset((onOff == 0) ? false : true); |
672 | return true; | 712 | return true; |
673 | } | 713 | } |
674 | //SetBreakingImpulseThreshold(m_constraint.ptr, threshold); | 714 | //SetBreakingImpulseThreshold(m_constraint.ptr, threshold); |
675 | public override bool SetBreakingImpulseThreshold(BulletConstraint pConstraint, float threshold) | 715 | public override bool SetBreakingImpulseThreshold(BulletConstraint pConstraint, float threshold) |
676 | { | 716 | { |
677 | Generic6DofConstraint constraint = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 717 | Generic6DofConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
678 | constraint.SetBreakingImpulseThreshold(threshold); | 718 | constraint.SetBreakingImpulseThreshold(threshold); |
679 | return true; | 719 | return true; |
680 | } | 720 | } |
681 | //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping); | 721 | //BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping); |
682 | public override void SetAngularDamping(BulletBody pBody, float angularDamping) | 722 | public override void SetAngularDamping(BulletBody pBody, float angularDamping) |
683 | { | 723 | { |
684 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 724 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
685 | float lineardamping = body.GetLinearDamping(); | 725 | float lineardamping = body.GetLinearDamping(); |
686 | body.SetDamping(lineardamping, angularDamping); | 726 | body.SetDamping(lineardamping, angularDamping); |
687 | 727 | ||
@@ -689,111 +729,183 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
689 | 729 | ||
690 | public override void UpdateInertiaTensor(BulletBody pBody) | 730 | public override void UpdateInertiaTensor(BulletBody pBody) |
691 | { | 731 | { |
692 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 732 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
693 | body.UpdateInertiaTensor(); | 733 | body.UpdateInertiaTensor(); |
694 | } | 734 | } |
695 | 735 | ||
696 | public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape) | 736 | public override void RecalculateCompoundShapeLocalAabb(BulletShape pCompoundShape) |
697 | { | 737 | { |
698 | CompoundShape shape = ((BulletShapeXNA)pCompoundShape).shape as CompoundShape; | 738 | CompoundShape shape = (pCompoundShape as BulletShapeXNA).shape as CompoundShape; |
699 | shape.RecalculateLocalAabb(); | 739 | shape.RecalculateLocalAabb(); |
700 | } | 740 | } |
701 | 741 | ||
702 | //BulletSimAPI.GetCollisionFlags(PhysBody.ptr) | 742 | //BulletSimAPI.GetCollisionFlags(PhysBody.ptr) |
703 | public override CollisionFlags GetCollisionFlags(BulletBody pBody) | 743 | public override CollisionFlags GetCollisionFlags(BulletBody pCollisionObject) |
704 | { | 744 | { |
705 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 745 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
706 | uint flags = (uint)body.GetCollisionFlags(); | 746 | uint flags = (uint)collisionObject.GetCollisionFlags(); |
707 | return (CollisionFlags) flags; | 747 | return (CollisionFlags) flags; |
708 | } | 748 | } |
709 | 749 | ||
710 | public override void SetDamping(BulletBody pBody, float pLinear, float pAngular) | 750 | public override void SetDamping(BulletBody pBody, float pLinear, float pAngular) |
711 | { | 751 | { |
712 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 752 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
713 | body.SetDamping(pLinear, pAngular); | 753 | body.SetDamping(pLinear, pAngular); |
714 | } | 754 | } |
715 | //PhysBody.ptr, PhysicsScene.Params.deactivationTime); | 755 | //PhysBody.ptr, PhysicsScene.Params.deactivationTime); |
716 | public override void SetDeactivationTime(BulletBody pBody, float pDeactivationTime) | 756 | public override void SetDeactivationTime(BulletBody pCollisionObject, float pDeactivationTime) |
717 | { | 757 | { |
718 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 758 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
719 | body.SetDeactivationTime(pDeactivationTime); | 759 | collisionObject.SetDeactivationTime(pDeactivationTime); |
720 | } | 760 | } |
721 | //SetSleepingThresholds(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | 761 | //SetSleepingThresholds(PhysBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); |
722 | public override void SetSleepingThresholds(BulletBody pBody, float plinearSleepingThreshold, float pangularSleepingThreshold) | 762 | public override void SetSleepingThresholds(BulletBody pBody, float plinearSleepingThreshold, float pangularSleepingThreshold) |
723 | { | 763 | { |
724 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 764 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
725 | body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold); | 765 | body.SetSleepingThresholds(plinearSleepingThreshold, pangularSleepingThreshold); |
726 | } | 766 | } |
727 | 767 | ||
728 | public override CollisionObjectTypes GetBodyType(BulletBody pBody) | 768 | public override CollisionObjectTypes GetBodyType(BulletBody pCollisionObject) |
729 | { | 769 | { |
730 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 770 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
731 | return (CollisionObjectTypes)(int) body.GetInternalType(); | 771 | return (CollisionObjectTypes)(int) collisionObject.GetInternalType(); |
732 | } | 772 | } |
733 | 773 | ||
734 | public override void ApplyGravity(BulletBody obj) { /* TODO */ } | 774 | public override void ApplyGravity(BulletBody pBody) |
775 | { | ||
735 | 776 | ||
736 | public override Vector3 GetGravity(BulletBody obj) { /* TODO */ return Vector3.Zero; } | 777 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
778 | body.ApplyGravity(); | ||
779 | } | ||
737 | 780 | ||
738 | public override void SetLinearDamping(BulletBody obj, float lin_damping) { /* TODO */ } | 781 | public override Vector3 GetGravity(BulletBody pBody) |
782 | { | ||
783 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
784 | IndexedVector3 gravity = body.GetGravity(); | ||
785 | return new Vector3(gravity.X, gravity.Y, gravity.Z); | ||
786 | } | ||
739 | 787 | ||
740 | public override float GetLinearDamping(BulletBody obj) { /* TODO */ return 0f; } | 788 | public override void SetLinearDamping(BulletBody pBody, float lin_damping) |
789 | { | ||
790 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
791 | float angularDamping = body.GetAngularDamping(); | ||
792 | body.SetDamping(lin_damping, angularDamping); | ||
793 | } | ||
741 | 794 | ||
742 | public override float GetAngularDamping(BulletBody obj) { /* TODO */ return 0f; } | 795 | public override float GetLinearDamping(BulletBody pBody) |
796 | { | ||
797 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
798 | return body.GetLinearDamping(); | ||
799 | } | ||
800 | |||
801 | public override float GetAngularDamping(BulletBody pBody) | ||
802 | { | ||
803 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
804 | return body.GetAngularDamping(); | ||
805 | } | ||
743 | 806 | ||
744 | public override float GetLinearSleepingThreshold(BulletBody obj) { /* TODO */ return 0f; } | 807 | public override float GetLinearSleepingThreshold(BulletBody pBody) |
808 | { | ||
809 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
810 | return body.GetLinearSleepingThreshold(); | ||
811 | } | ||
745 | 812 | ||
746 | public override void ApplyDamping(BulletBody obj, float timeStep) { /* TODO */ } | 813 | public override void ApplyDamping(BulletBody pBody, float timeStep) |
814 | { | ||
815 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
816 | body.ApplyDamping(timeStep); | ||
817 | } | ||
747 | 818 | ||
748 | public override Vector3 GetLinearFactor(BulletBody obj) { /* TODO */ return Vector3.Zero; } | 819 | public override Vector3 GetLinearFactor(BulletBody pBody) |
820 | { | ||
821 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
822 | IndexedVector3 linearFactor = body.GetLinearFactor(); | ||
823 | return new Vector3(linearFactor.X, linearFactor.Y, linearFactor.Z); | ||
824 | } | ||
749 | 825 | ||
750 | public override void SetLinearFactor(BulletBody obj, Vector3 factor) { /* TODO */ } | 826 | public override void SetLinearFactor(BulletBody pBody, Vector3 factor) |
827 | { | ||
828 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
829 | body.SetLinearFactor(new IndexedVector3(factor.X, factor.Y, factor.Z)); | ||
830 | } | ||
751 | 831 | ||
752 | public override void SetCenterOfMassByPosRot(BulletBody obj, Vector3 pos, Quaternion rot) { /* TODO */ } | 832 | public override void SetCenterOfMassByPosRot(BulletBody pBody, Vector3 pos, Quaternion rot) |
833 | { | ||
834 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; | ||
835 | IndexedQuaternion quat = new IndexedQuaternion(rot.X, rot.Y, rot.Z,rot.W); | ||
836 | IndexedMatrix mat = IndexedMatrix.CreateFromQuaternion(quat); | ||
837 | mat._origin = new IndexedVector3(pos.X, pos.Y, pos.Z); | ||
838 | body.SetCenterOfMassTransform( ref mat); | ||
839 | /* TODO: double check this */ | ||
840 | } | ||
753 | 841 | ||
754 | //BulletSimAPI.ApplyCentralForce(PhysBody.ptr, fSum); | 842 | //BulletSimAPI.ApplyCentralForce(PhysBody.ptr, fSum); |
755 | public override void ApplyCentralForce(BulletBody pBody, Vector3 pfSum) | 843 | public override void ApplyCentralForce(BulletBody pBody, Vector3 pfSum) |
756 | { | 844 | { |
757 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 845 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
758 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | 846 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); |
759 | body.ApplyCentralForce(ref fSum); | 847 | body.ApplyCentralForce(ref fSum); |
760 | } | 848 | } |
761 | public override void ApplyCentralImpulse(BulletBody pBody, Vector3 pfSum) | 849 | public override void ApplyCentralImpulse(BulletBody pBody, Vector3 pfSum) |
762 | { | 850 | { |
763 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 851 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
764 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | 852 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); |
765 | body.ApplyCentralImpulse(ref fSum); | 853 | body.ApplyCentralImpulse(ref fSum); |
766 | } | 854 | } |
767 | public override void ApplyTorque(BulletBody pBody, Vector3 pfSum) | 855 | public override void ApplyTorque(BulletBody pBody, Vector3 pfSum) |
768 | { | 856 | { |
769 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 857 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
770 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | 858 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); |
771 | body.ApplyTorque(ref fSum); | 859 | body.ApplyTorque(ref fSum); |
772 | } | 860 | } |
773 | public override void ApplyTorqueImpulse(BulletBody pBody, Vector3 pfSum) | 861 | public override void ApplyTorqueImpulse(BulletBody pBody, Vector3 pfSum) |
774 | { | 862 | { |
775 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 863 | RigidBody body = (pBody as BulletBodyXNA).rigidBody; |
776 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); | 864 | IndexedVector3 fSum = new IndexedVector3(pfSum.X, pfSum.Y, pfSum.Z); |
777 | body.ApplyTorqueImpulse(ref fSum); | 865 | body.ApplyTorqueImpulse(ref fSum); |
778 | } | 866 | } |
779 | 867 | ||
780 | public override void DestroyObject(BulletWorld p, BulletBody p_2) | 868 | public override void DestroyObject(BulletWorld pWorld, BulletBody pBody) |
781 | { | 869 | { |
782 | //TODO: | 870 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
871 | CollisionObject co = (pBody as BulletBodyXNA).rigidBody; | ||
872 | RigidBody bo = co as RigidBody; | ||
873 | if (bo == null) | ||
874 | { | ||
875 | |||
876 | if (world.IsInWorld(co)) | ||
877 | { | ||
878 | world.RemoveCollisionObject(co); | ||
879 | } | ||
880 | } | ||
881 | else | ||
882 | { | ||
883 | |||
884 | if (world.IsInWorld(bo)) | ||
885 | { | ||
886 | world.RemoveRigidBody(bo); | ||
887 | } | ||
888 | } | ||
889 | |||
783 | } | 890 | } |
784 | 891 | ||
785 | public override void Shutdown(BulletWorld pWorld) | 892 | public override void Shutdown(BulletWorld pWorld) |
786 | { | 893 | { |
787 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 894 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
788 | world.Cleanup(); | 895 | world.Cleanup(); |
789 | } | 896 | } |
790 | 897 | ||
791 | public override BulletShape DuplicateCollisionShape(BulletWorld sim, BulletShape srcShape, uint id) | 898 | public override BulletShape DuplicateCollisionShape(BulletWorld pWorld, BulletShape pShape, uint id) |
792 | { | 899 | { |
793 | return null; | 900 | CollisionShape shape1 = (pShape as BulletShapeXNA).shape; |
901 | |||
902 | // TODO: Turn this from a reference copy to a Value Copy. | ||
903 | BulletShapeXNA shape2 = new BulletShapeXNA(shape1, BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
904 | |||
905 | return shape2; | ||
794 | } | 906 | } |
795 | 907 | ||
796 | public override bool DeleteCollisionShape(BulletWorld p, BulletShape p_2) | 908 | public override bool DeleteCollisionShape(BulletWorld pWorld, BulletShape pShape) |
797 | { | 909 | { |
798 | //TODO: | 910 | //TODO: |
799 | return false; | 911 | return false; |
@@ -802,17 +914,40 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
802 | 914 | ||
803 | public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | 915 | public override BulletBody CreateBodyFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) |
804 | { | 916 | { |
805 | CollisionWorld world = ((BulletWorldXNA)pWorld).world; | 917 | CollisionWorld world = (pWorld as BulletWorldXNA).world; |
806 | IndexedMatrix mat = | 918 | IndexedMatrix mat = |
807 | IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y, | 919 | IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y, |
808 | pRawOrientation.Z, pRawOrientation.W)); | 920 | pRawOrientation.Z, pRawOrientation.W)); |
809 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | 921 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); |
810 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 922 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
811 | //UpdateSingleAabb(world, shape); | 923 | //UpdateSingleAabb(world, shape); |
812 | // TODO: Feed Update array into null | 924 | // TODO: Feed Update array into null |
813 | RigidBody body = new RigidBody(0,new SimMotionState(world,pLocalID,mat,null),shape,IndexedVector3.Zero); | 925 | SimMotionState motionState = new SimMotionState(world, pLocalID, mat, null); |
814 | 926 | RigidBody body = new RigidBody(0,motionState,shape,IndexedVector3.Zero); | |
927 | RigidBodyConstructionInfo constructionInfo = new RigidBodyConstructionInfo(0, new SimMotionState(world, pLocalID, mat, null),shape,IndexedVector3.Zero) | ||
928 | { | ||
929 | m_mass = 0 | ||
930 | }; | ||
931 | /* | ||
932 | m_mass = mass; | ||
933 | m_motionState =motionState; | ||
934 | m_collisionShape = collisionShape; | ||
935 | m_localInertia = localInertia; | ||
936 | m_linearDamping = 0f; | ||
937 | m_angularDamping = 0f; | ||
938 | m_friction = 0.5f; | ||
939 | m_restitution = 0f; | ||
940 | m_linearSleepingThreshold = 0.8f; | ||
941 | m_angularSleepingThreshold = 1f; | ||
942 | m_additionalDamping = false; | ||
943 | m_additionalDampingFactor = 0.005f; | ||
944 | m_additionalLinearDampingThresholdSqr = 0.01f; | ||
945 | m_additionalAngularDampingThresholdSqr = 0.01f; | ||
946 | m_additionalAngularDampingFactor = 0.01f; | ||
947 | m_startWorldTransform = IndexedMatrix.Identity; | ||
948 | */ | ||
815 | body.SetUserPointer(pLocalID); | 949 | body.SetUserPointer(pLocalID); |
950 | |||
816 | return new BulletBodyXNA(pLocalID, body); | 951 | return new BulletBodyXNA(pLocalID, body); |
817 | } | 952 | } |
818 | 953 | ||
@@ -825,7 +960,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
825 | pRawOrientation.Z, pRawOrientation.W)); | 960 | pRawOrientation.Z, pRawOrientation.W)); |
826 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | 961 | mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); |
827 | 962 | ||
828 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 963 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
829 | 964 | ||
830 | // TODO: Feed Update array into null | 965 | // TODO: Feed Update array into null |
831 | RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero); | 966 | RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero); |
@@ -834,21 +969,43 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
834 | return new BulletBodyXNA(pLocalID, body); | 969 | return new BulletBodyXNA(pLocalID, body); |
835 | } | 970 | } |
836 | //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | 971 | //(m_mapInfo.terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); |
837 | public override CollisionFlags SetCollisionFlags(BulletBody pBody, CollisionFlags collisionFlags) | 972 | public override CollisionFlags SetCollisionFlags(BulletBody pCollisionObject, CollisionFlags collisionFlags) |
838 | { | 973 | { |
839 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 974 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
840 | body.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags); | 975 | collisionObject.SetCollisionFlags((BulletXNA.BulletCollision.CollisionFlags) (uint) collisionFlags); |
841 | return (CollisionFlags)body.GetCollisionFlags(); | 976 | return (CollisionFlags)collisionObject.GetCollisionFlags(); |
842 | } | 977 | } |
843 | 978 | ||
844 | public override Vector3 GetAnisotripicFriction(BulletConstraint pconstrain) { /* TODO */ return Vector3.Zero; } | 979 | public override Vector3 GetAnisotripicFriction(BulletConstraint pconstrain) |
980 | { | ||
981 | |||
982 | /* TODO */ | ||
983 | return Vector3.Zero; | ||
984 | } | ||
845 | public override Vector3 SetAnisotripicFriction(BulletConstraint pconstrain, Vector3 frict) { /* TODO */ return Vector3.Zero; } | 985 | public override Vector3 SetAnisotripicFriction(BulletConstraint pconstrain, Vector3 frict) { /* TODO */ return Vector3.Zero; } |
846 | public override bool HasAnisotripicFriction(BulletConstraint pconstrain) { /* TODO */ return false; } | 986 | public override bool HasAnisotripicFriction(BulletConstraint pconstrain) { /* TODO */ return false; } |
847 | public override float GetContactProcessingThreshold(BulletBody pBody) { /* TODO */ return 0f; } | 987 | public override float GetContactProcessingThreshold(BulletBody pBody) { /* TODO */ return 0f; } |
848 | public override bool IsStaticObject(BulletBody pBody) { /* TODO */ return false; } | 988 | public override bool IsStaticObject(BulletBody pCollisionObject) |
849 | public override bool IsKinematicObject(BulletBody pBody) { /* TODO */ return false; } | 989 | { |
850 | public override bool IsStaticOrKinematicObject(BulletBody pBody) { /* TODO */ return false; } | 990 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
851 | public override bool HasContactResponse(BulletBody pBody) { /* TODO */ return false; } | 991 | return collisionObject.IsStaticObject(); |
992 | |||
993 | } | ||
994 | public override bool IsKinematicObject(BulletBody pCollisionObject) | ||
995 | { | ||
996 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
997 | return collisionObject.IsKinematicObject(); | ||
998 | } | ||
999 | public override bool IsStaticOrKinematicObject(BulletBody pCollisionObject) | ||
1000 | { | ||
1001 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1002 | return collisionObject.IsStaticOrKinematicObject(); | ||
1003 | } | ||
1004 | public override bool HasContactResponse(BulletBody pCollisionObject) | ||
1005 | { | ||
1006 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1007 | return collisionObject.HasContactResponse(); | ||
1008 | } | ||
852 | public override int GetActivationState(BulletBody pBody) { /* TODO */ return 0; } | 1009 | public override int GetActivationState(BulletBody pBody) { /* TODO */ return 0; } |
853 | public override void SetActivationState(BulletBody pBody, int state) { /* TODO */ } | 1010 | public override void SetActivationState(BulletBody pBody, int state) { /* TODO */ } |
854 | public override float GetDeactivationTime(BulletBody pBody) { /* TODO */ return 0f; } | 1011 | public override float GetDeactivationTime(BulletBody pBody) { /* TODO */ return 0f; } |
@@ -859,15 +1016,15 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
859 | public override float GetHitFraction(BulletBody pBody) { /* TODO */ return 0f; } | 1016 | public override float GetHitFraction(BulletBody pBody) { /* TODO */ return 0f; } |
860 | 1017 | ||
861 | //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | 1018 | //(m_mapInfo.terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); |
862 | public override void SetHitFraction(BulletBody pBody, float pHitFraction) | 1019 | public override void SetHitFraction(BulletBody pCollisionObject, float pHitFraction) |
863 | { | 1020 | { |
864 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 1021 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
865 | body.SetHitFraction(pHitFraction); | 1022 | collisionObject.SetHitFraction(pHitFraction); |
866 | } | 1023 | } |
867 | //BuildCapsuleShape(physicsScene.World.ptr, 1f, 1f, prim.Scale); | 1024 | //BuildCapsuleShape(physicsScene.World.ptr, 1f, 1f, prim.Scale); |
868 | public override BulletShape BuildCapsuleShape(BulletWorld pWorld, float pRadius, float pHeight, Vector3 pScale) | 1025 | public override BulletShape BuildCapsuleShape(BulletWorld pWorld, float pRadius, float pHeight, Vector3 pScale) |
869 | { | 1026 | { |
870 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1027 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
871 | IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); | 1028 | IndexedVector3 scale = new IndexedVector3(pScale.X, pScale.Y, pScale.Z); |
872 | CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight); | 1029 | CapsuleShapeZ capsuleShapeZ = new CapsuleShapeZ(pRadius, pHeight); |
873 | capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin); | 1030 | capsuleShapeZ.SetMargin(world.WorldSettings.Params.collisionMargin); |
@@ -881,14 +1038,24 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
881 | int maxUpdates, ref EntityProperties[] updateArray | 1038 | int maxUpdates, ref EntityProperties[] updateArray |
882 | ) | 1039 | ) |
883 | { | 1040 | { |
1041 | |||
1042 | m_updateArray = updateArray; | ||
1043 | m_collisionArray = collisionArray; | ||
884 | /* TODO */ | 1044 | /* TODO */ |
885 | return new BulletWorldXNA(1, null, null); | 1045 | ConfigurationParameters[] configparms = new ConfigurationParameters[1]; |
1046 | configparms[0] = parms; | ||
1047 | Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); | ||
1048 | m_maxCollisions = maxCollisions; | ||
1049 | m_maxUpdatesPerFrame = maxUpdates; | ||
1050 | |||
1051 | |||
1052 | return new BulletWorldXNA(1, PhysicsScene, BSAPIXNA.Initialize2(worldExtent, configparms, maxCollisions, ref collisionArray, maxUpdates, ref updateArray, null)); | ||
886 | } | 1053 | } |
887 | 1054 | ||
888 | private static object Initialize2(Vector3 worldExtent, | 1055 | private static DiscreteDynamicsWorld Initialize2(Vector3 worldExtent, |
889 | ConfigurationParameters[] o, | 1056 | ConfigurationParameters[] o, |
890 | int mMaxCollisionsPerFrame, ref List<BulletXNA.CollisionDesc> collisionArray, | 1057 | int mMaxCollisionsPerFrame, ref CollisionDesc[] collisionArray, |
891 | int mMaxUpdatesPerFrame, ref List<BulletXNA.EntityProperties> updateArray, | 1058 | int mMaxUpdatesPerFrame, ref EntityProperties[] updateArray, |
892 | object mDebugLogCallbackHandle) | 1059 | object mDebugLogCallbackHandle) |
893 | { | 1060 | { |
894 | CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); | 1061 | CollisionWorld.WorldData.ParamData p = new CollisionWorld.WorldData.ParamData(); |
@@ -968,8 +1135,13 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
968 | SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver(); | 1135 | SequentialImpulseConstraintSolver m_solver = new SequentialImpulseConstraintSolver(); |
969 | 1136 | ||
970 | DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci); | 1137 | DiscreteDynamicsWorld world = new DiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, cci); |
971 | world.UpdatedObjects = updateArray; | 1138 | |
972 | world.UpdatedCollisions = collisionArray; | 1139 | |
1140 | world.UpdatedObjects = BSAPIXNA.GetBulletXNAEntityStruct(BSAPIXNA.BulletSimEntityStructToByteArray(updateArray, updateArray.Length)); | ||
1141 | world.UpdatedCollisions = BSAPIXNA.GetBulletXNACollisionStruct(BSAPIXNA.BulletSimCollisionStructToByteArray(collisionArray, collisionArray.Length)); | ||
1142 | world.LastCollisionDesc = 0; | ||
1143 | world.LastEntityProperty = 0; | ||
1144 | |||
973 | world.WorldSettings.Params = p; | 1145 | world.WorldSettings.Params = p; |
974 | world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0); | 1146 | world.SetForceUpdateAllAabbs(p.shouldForceUpdateAllAabbs != 0); |
975 | world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD; | 1147 | world.GetSolverInfo().m_solverMode = SolverMode.SOLVER_USE_WARMSTARTING | SolverMode.SOLVER_SIMD; |
@@ -1003,7 +1175,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1003 | world.GetSolverInfo().m_restingContactRestitutionThreshold = 2; | 1175 | world.GetSolverInfo().m_restingContactRestitutionThreshold = 2; |
1004 | world.SetForceUpdateAllAabbs(true); | 1176 | world.SetForceUpdateAllAabbs(true); |
1005 | 1177 | ||
1006 | 1178 | //BSParam.TerrainImplementation = 0; | |
1007 | world.SetGravity(new IndexedVector3(0,0,p.gravity)); | 1179 | world.SetGravity(new IndexedVector3(0,0,p.gravity)); |
1008 | 1180 | ||
1009 | return world; | 1181 | return world; |
@@ -1011,7 +1183,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1011 | //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL | 1183 | //m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL |
1012 | public override bool SetConstraintParam(BulletConstraint pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis) | 1184 | public override bool SetConstraintParam(BulletConstraint pConstraint, ConstraintParams paramIndex, float paramvalue, ConstraintParamAxis axis) |
1013 | { | 1185 | { |
1014 | Generic6DofConstraint constrain = ((BulletConstraintXNA)pConstraint).constrain as Generic6DofConstraint; | 1186 | Generic6DofConstraint constrain = (pConstraint as BulletConstraintXNA).constrain as Generic6DofConstraint; |
1015 | if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL) | 1187 | if (axis == ConstraintParamAxis.AXIS_LINEAR_ALL || axis == ConstraintParamAxis.AXIS_ALL) |
1016 | { | 1188 | { |
1017 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0); | 1189 | constrain.SetParam((BulletXNA.BulletDynamics.ConstraintParams) (int) paramIndex, paramvalue, 0); |
@@ -1034,7 +1206,8 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1034 | public override bool PushUpdate(BulletBody pCollisionObject) | 1206 | public override bool PushUpdate(BulletBody pCollisionObject) |
1035 | { | 1207 | { |
1036 | bool ret = false; | 1208 | bool ret = false; |
1037 | RigidBody rb = ((BulletBodyXNA)pCollisionObject).rigidBody; | 1209 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
1210 | RigidBody rb = collisionObject as RigidBody; | ||
1038 | if (rb != null) | 1211 | if (rb != null) |
1039 | { | 1212 | { |
1040 | SimMotionState sms = rb.GetMotionState() as SimMotionState; | 1213 | SimMotionState sms = rb.GetMotionState() as SimMotionState; |
@@ -1052,57 +1225,57 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1052 | 1225 | ||
1053 | public override float GetAngularMotionDisc(BulletShape pShape) | 1226 | public override float GetAngularMotionDisc(BulletShape pShape) |
1054 | { | 1227 | { |
1055 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1228 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1056 | return shape.GetAngularMotionDisc(); | 1229 | return shape.GetAngularMotionDisc(); |
1057 | } | 1230 | } |
1058 | public override float GetContactBreakingThreshold(BulletShape pShape, float defaultFactor) | 1231 | public override float GetContactBreakingThreshold(BulletShape pShape, float defaultFactor) |
1059 | { | 1232 | { |
1060 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1233 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1061 | return shape.GetContactBreakingThreshold(defaultFactor); | 1234 | return shape.GetContactBreakingThreshold(defaultFactor); |
1062 | } | 1235 | } |
1063 | public override bool IsCompound(BulletShape pShape) | 1236 | public override bool IsCompound(BulletShape pShape) |
1064 | { | 1237 | { |
1065 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1238 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1066 | return shape.IsCompound(); | 1239 | return shape.IsCompound(); |
1067 | } | 1240 | } |
1068 | public override bool IsSoftBody(BulletShape pShape) | 1241 | public override bool IsSoftBody(BulletShape pShape) |
1069 | { | 1242 | { |
1070 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1243 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1071 | return shape.IsSoftBody(); | 1244 | return shape.IsSoftBody(); |
1072 | } | 1245 | } |
1073 | public override bool IsPolyhedral(BulletShape pShape) | 1246 | public override bool IsPolyhedral(BulletShape pShape) |
1074 | { | 1247 | { |
1075 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1248 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1076 | return shape.IsPolyhedral(); | 1249 | return shape.IsPolyhedral(); |
1077 | } | 1250 | } |
1078 | public override bool IsConvex2d(BulletShape pShape) | 1251 | public override bool IsConvex2d(BulletShape pShape) |
1079 | { | 1252 | { |
1080 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1253 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1081 | return shape.IsConvex2d(); | 1254 | return shape.IsConvex2d(); |
1082 | } | 1255 | } |
1083 | public override bool IsConvex(BulletShape pShape) | 1256 | public override bool IsConvex(BulletShape pShape) |
1084 | { | 1257 | { |
1085 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1258 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1086 | return shape.IsConvex(); | 1259 | return shape.IsConvex(); |
1087 | } | 1260 | } |
1088 | public override bool IsNonMoving(BulletShape pShape) | 1261 | public override bool IsNonMoving(BulletShape pShape) |
1089 | { | 1262 | { |
1090 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1263 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1091 | return shape.IsNonMoving(); | 1264 | return shape.IsNonMoving(); |
1092 | } | 1265 | } |
1093 | public override bool IsConcave(BulletShape pShape) | 1266 | public override bool IsConcave(BulletShape pShape) |
1094 | { | 1267 | { |
1095 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1268 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1096 | return shape.IsConcave(); | 1269 | return shape.IsConcave(); |
1097 | } | 1270 | } |
1098 | public override bool IsInfinite(BulletShape pShape) | 1271 | public override bool IsInfinite(BulletShape pShape) |
1099 | { | 1272 | { |
1100 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1273 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1101 | return shape.IsInfinite(); | 1274 | return shape.IsInfinite(); |
1102 | } | 1275 | } |
1103 | public override bool IsNativeShape(BulletShape pShape) | 1276 | public override bool IsNativeShape(BulletShape pShape) |
1104 | { | 1277 | { |
1105 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1278 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1106 | bool ret; | 1279 | bool ret; |
1107 | switch (shape.GetShapeType()) | 1280 | switch (shape.GetShapeType()) |
1108 | { | 1281 | { |
@@ -1119,38 +1292,53 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1119 | return ret; | 1292 | return ret; |
1120 | } | 1293 | } |
1121 | 1294 | ||
1122 | public override void SetShapeCollisionMargin(BulletShape shape, float margin) { /* TODO */ } | 1295 | public override void SetShapeCollisionMargin(BulletShape pShape, float pMargin) |
1296 | { | ||
1297 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1298 | shape.SetMargin(pMargin); | ||
1299 | } | ||
1123 | 1300 | ||
1124 | //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation | 1301 | //sim.ptr, shape.ptr,prim.LocalID, prim.RawPosition, prim.RawOrientation |
1125 | public override BulletBody CreateGhostFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) | 1302 | public override BulletBody CreateGhostFromShape(BulletWorld pWorld, BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation) |
1126 | { | 1303 | { |
1127 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1304 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1128 | IndexedMatrix bodyTransform = new IndexedMatrix(); | 1305 | IndexedMatrix bodyTransform = new IndexedMatrix(); |
1129 | bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); | 1306 | bodyTransform._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z); |
1130 | bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W)); | 1307 | bodyTransform.SetRotation(new IndexedQuaternion(pRawOrientation.X,pRawOrientation.Y,pRawOrientation.Z,pRawOrientation.W)); |
1131 | GhostObject gObj = new PairCachingGhostObject(); | 1308 | GhostObject gObj = new PairCachingGhostObject(); |
1132 | gObj.SetWorldTransform(bodyTransform); | 1309 | gObj.SetWorldTransform(bodyTransform); |
1133 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1310 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1134 | gObj.SetCollisionShape(shape); | 1311 | gObj.SetCollisionShape(shape); |
1135 | gObj.SetUserPointer(pLocalID); | 1312 | gObj.SetUserPointer(pLocalID); |
1136 | // TODO: Add to Special CollisionObjects! | 1313 | // TODO: Add to Special CollisionObjects! |
1137 | return new BulletBodyXNA(pLocalID, gObj); | 1314 | return new BulletBodyXNA(pLocalID, gObj); |
1138 | } | 1315 | } |
1139 | 1316 | ||
1140 | public override void SetCollisionShape(BulletWorld pWorld, BulletBody pObj, BulletShape pShape) | 1317 | public override void SetCollisionShape(BulletWorld pWorld, BulletBody pCollisionObject, BulletShape pShape) |
1141 | { | 1318 | { |
1142 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1319 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1143 | CollisionObject obj = ((BulletBodyXNA)pObj).body; | 1320 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).body; |
1144 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1321 | if (pShape == null) |
1145 | obj.SetCollisionShape(shape); | 1322 | { |
1146 | 1323 | collisionObject.SetCollisionShape(new EmptyShape()); | |
1324 | } | ||
1325 | else | ||
1326 | { | ||
1327 | CollisionShape shape = (pShape as BulletShapeXNA).shape; | ||
1328 | collisionObject.SetCollisionShape(shape); | ||
1329 | } | ||
1330 | } | ||
1331 | public override BulletShape GetCollisionShape(BulletBody pCollisionObject) | ||
1332 | { | ||
1333 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; | ||
1334 | CollisionShape shape = collisionObject.GetCollisionShape(); | ||
1335 | return new BulletShapeXNA(shape,BSPhysicsShapeType.SHAPE_UNKNOWN); | ||
1147 | } | 1336 | } |
1148 | public override BulletShape GetCollisionShape(BulletBody obj) { /* TODO */ return null; } | ||
1149 | 1337 | ||
1150 | //(PhysicsScene.World.ptr, nativeShapeData) | 1338 | //(PhysicsScene.World.ptr, nativeShapeData) |
1151 | public override BulletShape BuildNativeShape(BulletWorld pWorld, ShapeData pShapeData) | 1339 | public override BulletShape BuildNativeShape(BulletWorld pWorld, ShapeData pShapeData) |
1152 | { | 1340 | { |
1153 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1341 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1154 | CollisionShape shape = null; | 1342 | CollisionShape shape = null; |
1155 | switch (pShapeData.Type) | 1343 | switch (pShapeData.Type) |
1156 | { | 1344 | { |
@@ -1185,15 +1373,15 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1185 | 1373 | ||
1186 | public override int GetNumberOfCompoundChildren(BulletShape pCompoundShape) | 1374 | public override int GetNumberOfCompoundChildren(BulletShape pCompoundShape) |
1187 | { | 1375 | { |
1188 | CompoundShape compoundshape = ((BulletShapeXNA)pCompoundShape).shape as CompoundShape; | 1376 | CompoundShape compoundshape = (pCompoundShape as BulletShapeXNA).shape as CompoundShape; |
1189 | return compoundshape.GetNumChildShapes(); | 1377 | return compoundshape.GetNumChildShapes(); |
1190 | } | 1378 | } |
1191 | //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot | 1379 | //LinksetRoot.PhysShape.ptr, newShape.ptr, displacementPos, displacementRot |
1192 | public override void AddChildShapeToCompoundShape(BulletShape pCShape, BulletShape paddShape, Vector3 displacementPos, Quaternion displacementRot) | 1380 | public override void AddChildShapeToCompoundShape(BulletShape pCShape, BulletShape paddShape, Vector3 displacementPos, Quaternion displacementRot) |
1193 | { | 1381 | { |
1194 | IndexedMatrix relativeTransform = new IndexedMatrix(); | 1382 | IndexedMatrix relativeTransform = new IndexedMatrix(); |
1195 | CompoundShape compoundshape = ((BulletShapeXNA)pCShape).shape as CompoundShape; | 1383 | CompoundShape compoundshape = (pCShape as BulletShapeXNA).shape as CompoundShape; |
1196 | CollisionShape addshape = ((BulletShapeXNA)paddShape).shape; | 1384 | CollisionShape addshape = (paddShape as BulletShapeXNA).shape; |
1197 | 1385 | ||
1198 | relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z); | 1386 | relativeTransform._origin = new IndexedVector3(displacementPos.X, displacementPos.Y, displacementPos.Z); |
1199 | relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W)); | 1387 | relativeTransform.SetRotation(new IndexedQuaternion(displacementRot.X,displacementRot.Y,displacementRot.Z,displacementRot.W)); |
@@ -1203,7 +1391,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1203 | 1391 | ||
1204 | public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape pCShape, int pii) | 1392 | public override BulletShape RemoveChildShapeFromCompoundShapeIndex(BulletShape pCShape, int pii) |
1205 | { | 1393 | { |
1206 | CompoundShape compoundshape = ((BulletShapeXNA)pCShape).shape as CompoundShape; | 1394 | CompoundShape compoundshape = (pCShape as BulletShapeXNA).shape as CompoundShape; |
1207 | CollisionShape ret = null; | 1395 | CollisionShape ret = null; |
1208 | ret = compoundshape.GetChildShape(pii); | 1396 | ret = compoundshape.GetChildShape(pii); |
1209 | compoundshape.RemoveChildShapeByIndex(pii); | 1397 | compoundshape.RemoveChildShapeByIndex(pii); |
@@ -1222,12 +1410,12 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1222 | return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE); | 1410 | return new BulletShapeXNA(m_planeshape, BSPhysicsShapeType.SHAPE_GROUNDPLANE); |
1223 | } | 1411 | } |
1224 | 1412 | ||
1225 | public override BulletConstraint CreateHingeConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody ppBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) | 1413 | public override BulletConstraint CreateHingeConstraint(BulletWorld pWorld, BulletBody pBody1, BulletBody pBody2, Vector3 ppivotInA, Vector3 ppivotInB, Vector3 paxisInA, Vector3 paxisInB, bool puseLinearReferenceFrameA, bool pdisableCollisionsBetweenLinkedBodies) |
1226 | { | 1414 | { |
1227 | HingeConstraint constrain = null; | 1415 | HingeConstraint constrain = null; |
1228 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1416 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1229 | RigidBody rb1 = ((BulletBodyXNA)pBody1).rigidBody; | 1417 | RigidBody rb1 = (pBody1 as BulletBodyXNA).rigidBody; |
1230 | RigidBody rb2 = ((BulletBodyXNA)ppBody2).rigidBody; | 1418 | RigidBody rb2 = (pBody2 as BulletBodyXNA).rigidBody; |
1231 | if (rb1 != null && rb2 != null) | 1419 | if (rb1 != null && rb2 != null) |
1232 | { | 1420 | { |
1233 | IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z); | 1421 | IndexedVector3 pivotInA = new IndexedVector3(ppivotInA.X, ppivotInA.Y, ppivotInA.Z); |
@@ -1241,7 +1429,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1241 | 1429 | ||
1242 | public override BulletShape CreateHullShape(BulletWorld pWorld, int pHullCount, float[] pConvHulls) | 1430 | public override BulletShape CreateHullShape(BulletWorld pWorld, int pHullCount, float[] pConvHulls) |
1243 | { | 1431 | { |
1244 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1432 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1245 | CompoundShape compoundshape = new CompoundShape(false); | 1433 | CompoundShape compoundshape = new CompoundShape(false); |
1246 | 1434 | ||
1247 | compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin); | 1435 | compoundshape.SetMargin(world.WorldSettings.Params.collisionMargin); |
@@ -1271,7 +1459,11 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1271 | return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL); | 1459 | return new BulletShapeXNA(compoundshape, BSPhysicsShapeType.SHAPE_HULL); |
1272 | } | 1460 | } |
1273 | 1461 | ||
1274 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) { /* TODO */ return null; } | 1462 | public override BulletShape BuildHullShapeFromMesh(BulletWorld world, BulletShape meshShape) |
1463 | { | ||
1464 | /* TODO */ return null; | ||
1465 | |||
1466 | } | ||
1275 | 1467 | ||
1276 | public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) | 1468 | public override BulletShape CreateMeshShape(BulletWorld pWorld, int pIndicesCount, int[] indices, int pVerticesCount, float[] verticesAsFloats) |
1277 | { | 1469 | { |
@@ -1286,7 +1478,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1286 | ObjectArray<int> indicesarr = new ObjectArray<int>(indices); | 1478 | ObjectArray<int> indicesarr = new ObjectArray<int>(indices); |
1287 | ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats); | 1479 | ObjectArray<float> vertices = new ObjectArray<float>(verticesAsFloats); |
1288 | DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount); | 1480 | DumpRaw(indicesarr,vertices,pIndicesCount,pVerticesCount); |
1289 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1481 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1290 | IndexedMesh mesh = new IndexedMesh(); | 1482 | IndexedMesh mesh = new IndexedMesh(); |
1291 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; | 1483 | mesh.m_indexType = PHY_ScalarType.PHY_INTEGER; |
1292 | mesh.m_numTriangles = pIndicesCount/3; | 1484 | mesh.m_numTriangles = pIndicesCount/3; |
@@ -1402,7 +1594,7 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1402 | 1594 | ||
1403 | public override bool TranslationalLimitMotor(BulletConstraint pConstraint, float ponOff, float targetVelocity, float maxMotorForce) | 1595 | public override bool TranslationalLimitMotor(BulletConstraint pConstraint, float ponOff, float targetVelocity, float maxMotorForce) |
1404 | { | 1596 | { |
1405 | TypedConstraint tconstrain = ((BulletConstraintXNA)pConstraint).constrain; | 1597 | TypedConstraint tconstrain = (pConstraint as BulletConstraintXNA).constrain; |
1406 | bool onOff = ponOff != 0; | 1598 | bool onOff = ponOff != 0; |
1407 | bool ret = false; | 1599 | bool ret = false; |
1408 | 1600 | ||
@@ -1428,47 +1620,45 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1428 | /* TODO */ | 1620 | /* TODO */ |
1429 | updatedEntityCount = 0; | 1621 | updatedEntityCount = 0; |
1430 | collidersCount = 0; | 1622 | collidersCount = 0; |
1431 | return 1; | 1623 | |
1624 | |||
1625 | int ret = PhysicsStep2(world,timeStep,maxSubSteps,fixedTimeStep,out updatedEntityCount,out world.physicsScene.m_updateArray, out collidersCount, out world.physicsScene.m_collisionArray); | ||
1626 | |||
1627 | return ret; | ||
1432 | } | 1628 | } |
1433 | 1629 | ||
1434 | private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, | 1630 | private int PhysicsStep2(BulletWorld pWorld, float timeStep, int m_maxSubSteps, float m_fixedTimeStep, |
1435 | out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities, | 1631 | out int updatedEntityCount, out EntityProperties[] updatedEntities, |
1436 | out int collidersCount, out List<BulletXNA.CollisionDesc>colliders) | 1632 | out int collidersCount, out CollisionDesc[] colliders) |
1437 | { | 1633 | { |
1438 | int epic = PhysicsStepint(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities, | 1634 | int epic = PhysicsStepint(pWorld, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out updatedEntities, |
1439 | out collidersCount, out colliders); | 1635 | out collidersCount, out colliders, m_maxCollisions, m_maxUpdatesPerFrame); |
1440 | return epic; | 1636 | return epic; |
1441 | } | 1637 | } |
1442 | 1638 | ||
1443 | private static int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, out List<BulletXNA.EntityProperties> updatedEntities, out int collidersCount, out List<BulletXNA.CollisionDesc> colliders) | 1639 | private static int PhysicsStepint(BulletWorld pWorld,float timeStep, int m_maxSubSteps, float m_fixedTimeStep, out int updatedEntityCount, |
1640 | out EntityProperties[] updatedEntities, out int collidersCount, out CollisionDesc[] colliders, int maxCollisions, int maxUpdates) | ||
1444 | { | 1641 | { |
1445 | int numSimSteps = 0; | 1642 | int numSimSteps = 0; |
1446 | |||
1447 | 1643 | ||
1448 | //if (updatedEntities is null) | 1644 | updatedEntityCount = 0; |
1449 | // updatedEntities = new List<BulletXNA.EntityProperties>(); | 1645 | collidersCount = 0; |
1450 | |||
1451 | //if (colliders is null) | ||
1452 | // colliders = new List<BulletXNA.CollisionDesc>(); | ||
1453 | 1646 | ||
1454 | 1647 | ||
1455 | if (pWorld is BulletWorldXNA) | 1648 | if (pWorld is BulletWorldXNA) |
1456 | { | 1649 | { |
1457 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1650 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1458 | 1651 | ||
1652 | world.LastCollisionDesc = 0; | ||
1653 | world.LastEntityProperty = 0; | ||
1654 | world.UpdatedObjects = new BulletXNA.EntityProperties[maxUpdates]; | ||
1655 | world.UpdatedCollisions = new BulletXNA.CollisionDesc[maxCollisions]; | ||
1459 | numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); | 1656 | numSimSteps = world.StepSimulation(timeStep, m_maxSubSteps, m_fixedTimeStep); |
1460 | int updates = 0; | 1657 | int updates = 0; |
1461 | 1658 | ||
1462 | updatedEntityCount = world.UpdatedObjects.Count; | 1659 | |
1463 | updatedEntities = new List<BulletXNA.EntityProperties>(world.UpdatedObjects); | ||
1464 | updatedEntityCount = updatedEntities.Count; | ||
1465 | world.UpdatedObjects.Clear(); | ||
1466 | 1660 | ||
1467 | 1661 | ||
1468 | collidersCount = world.UpdatedCollisions.Count; | ||
1469 | colliders = new List<BulletXNA.CollisionDesc>(world.UpdatedCollisions); | ||
1470 | |||
1471 | world.UpdatedCollisions.Clear(); | ||
1472 | m_collisionsThisFrame = 0; | 1662 | m_collisionsThisFrame = 0; |
1473 | int numManifolds = world.GetDispatcher().GetNumManifolds(); | 1663 | int numManifolds = world.GetDispatcher().GetNumManifolds(); |
1474 | for (int j = 0; j < numManifolds; j++) | 1664 | for (int j = 0; j < numManifolds; j++) |
@@ -1493,16 +1683,31 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1493 | 1683 | ||
1494 | } | 1684 | } |
1495 | 1685 | ||
1686 | updatedEntityCount = world.LastEntityProperty; | ||
1687 | updatedEntities = GetBulletSimEntityStruct(BulletXNAEntityStructToByteArray(world.UpdatedObjects, world.LastEntityProperty)); | ||
1688 | |||
1689 | |||
1690 | |||
1691 | |||
1692 | collidersCount = world.LastCollisionDesc; | ||
1693 | colliders = | ||
1694 | GetBulletSimCollisionStruct(BulletXNACollisionStructToByteArray(world.UpdatedCollisions, world.LastCollisionDesc));//new List<BulletXNA.CollisionDesc>(world.UpdatedCollisions); | ||
1496 | 1695 | ||
1497 | } | 1696 | } |
1498 | else | 1697 | else |
1499 | { | 1698 | { |
1500 | //if (updatedEntities is null) | 1699 | //if (updatedEntities is null) |
1501 | updatedEntities = new List<BulletXNA.EntityProperties>(); | 1700 | //updatedEntities = new List<BulletXNA.EntityProperties>(); |
1502 | updatedEntityCount = 0; | 1701 | //updatedEntityCount = 0; |
1503 | //if (colliders is null) | 1702 | //if (colliders is null) |
1504 | colliders = new List<BulletXNA.CollisionDesc>(); | 1703 | //colliders = new List<BulletXNA.CollisionDesc>(); |
1505 | collidersCount = 0; | 1704 | //collidersCount = 0; |
1705 | |||
1706 | updatedEntities = new EntityProperties[0]; | ||
1707 | |||
1708 | |||
1709 | colliders = new CollisionDesc[0]; | ||
1710 | |||
1506 | } | 1711 | } |
1507 | return numSimSteps; | 1712 | return numSimSteps; |
1508 | } | 1713 | } |
@@ -1535,22 +1740,23 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1535 | point = contact, | 1740 | point = contact, |
1536 | normal = contactNormal | 1741 | normal = contactNormal |
1537 | }; | 1742 | }; |
1538 | world.UpdatedCollisions.Add(cDesc); | 1743 | if (world.LastCollisionDesc < world.UpdatedCollisions.Length) |
1744 | world.UpdatedCollisions[world.LastCollisionDesc++] = (cDesc); | ||
1539 | m_collisionsThisFrame++; | 1745 | m_collisionsThisFrame++; |
1540 | 1746 | ||
1541 | 1747 | ||
1542 | } | 1748 | } |
1543 | private static EntityProperties GetDebugProperties(BulletWorld pWorld, BulletBody pBody) | 1749 | private static EntityProperties GetDebugProperties(BulletWorld pWorld, BulletBody pCollisionObject) |
1544 | { | 1750 | { |
1545 | EntityProperties ent = new EntityProperties(); | 1751 | EntityProperties ent = new EntityProperties(); |
1546 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1752 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1547 | RigidBody body = ((BulletBodyXNA)pBody).rigidBody; | 1753 | CollisionObject collisionObject = (pCollisionObject as BulletBodyXNA).rigidBody; |
1548 | IndexedMatrix transform = body.GetWorldTransform(); | 1754 | IndexedMatrix transform = collisionObject.GetWorldTransform(); |
1549 | IndexedVector3 LinearVelocity = body.GetInterpolationLinearVelocity(); | 1755 | IndexedVector3 LinearVelocity = collisionObject.GetInterpolationLinearVelocity(); |
1550 | IndexedVector3 AngularVelocity = body.GetInterpolationAngularVelocity(); | 1756 | IndexedVector3 AngularVelocity = collisionObject.GetInterpolationAngularVelocity(); |
1551 | IndexedQuaternion rotation = transform.GetRotation(); | 1757 | IndexedQuaternion rotation = transform.GetRotation(); |
1552 | ent.Acceleration = Vector3.Zero; | 1758 | ent.Acceleration = Vector3.Zero; |
1553 | ent.ID = (uint)body.GetUserPointer(); | 1759 | ent.ID = (uint)collisionObject.GetUserPointer(); |
1554 | ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z); | 1760 | ent.Position = new Vector3(transform._origin.X,transform._origin.Y,transform._origin.Z); |
1555 | ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W); | 1761 | ent.Rotation = new Quaternion(rotation.X,rotation.Y,rotation.Z,rotation.W); |
1556 | ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z); | 1762 | ent.Velocity = new Vector3(LinearVelocity.X, LinearVelocity.Y, LinearVelocity.Z); |
@@ -1562,19 +1768,19 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1562 | 1768 | ||
1563 | public override Vector3 GetLocalScaling(BulletShape pShape) | 1769 | public override Vector3 GetLocalScaling(BulletShape pShape) |
1564 | { | 1770 | { |
1565 | CollisionShape shape = ((BulletShapeXNA)pShape).shape; | 1771 | CollisionShape shape = (pShape as BulletShapeXNA).shape; |
1566 | IndexedVector3 scale = shape.GetLocalScaling(); | 1772 | IndexedVector3 scale = shape.GetLocalScaling(); |
1567 | return new Vector3(scale.X,scale.Y,scale.Z); | 1773 | return new Vector3(scale.X,scale.Y,scale.Z); |
1568 | } | 1774 | } |
1569 | 1775 | ||
1570 | public bool RayCastGround(BulletWorld pWorld, Vector3 _RayOrigin, float pRayHeight, BulletBody NotMe) | 1776 | public bool RayCastGround(BulletWorld pWorld, Vector3 _RayOrigin, float pRayHeight, BulletBody NotMe) |
1571 | { | 1777 | { |
1572 | DiscreteDynamicsWorld world = ((BulletWorldXNA)pWorld).world; | 1778 | DiscreteDynamicsWorld world = (pWorld as BulletWorldXNA).world; |
1573 | if (world != null) | 1779 | if (world != null) |
1574 | { | 1780 | { |
1575 | if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody) | 1781 | if (NotMe is BulletBodyXNA && NotMe.HasPhysicalBody) |
1576 | { | 1782 | { |
1577 | CollisionObject AvoidBody = ((BulletBodyXNA)NotMe).body; | 1783 | CollisionObject AvoidBody = (NotMe as BulletBodyXNA).body; |
1578 | 1784 | ||
1579 | IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z); | 1785 | IndexedVector3 rOrigin = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z); |
1580 | IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight); | 1786 | IndexedVector3 rEnd = new IndexedVector3(_RayOrigin.X, _RayOrigin.Y, _RayOrigin.Z - pRayHeight); |
@@ -1594,5 +1800,160 @@ private sealed class BulletConstraintXNA : BulletConstraint | |||
1594 | } | 1800 | } |
1595 | return false; | 1801 | return false; |
1596 | } | 1802 | } |
1803 | |||
1804 | public static unsafe BulletXNA.CollisionDesc[] GetBulletXNACollisionStruct(byte[] buffer) | ||
1805 | { | ||
1806 | int count = buffer.Length/sizeof (BulletXNA.CollisionDesc); | ||
1807 | BulletXNA.CollisionDesc[] result = new BulletXNA.CollisionDesc[count]; | ||
1808 | BulletXNA.CollisionDesc* ptr; | ||
1809 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1810 | { | ||
1811 | for (int i = 0; i < buffer.Length; i++) | ||
1812 | { | ||
1813 | localBytes[i] = buffer[i]; | ||
1814 | } | ||
1815 | for (int i=0;i<count;i++) | ||
1816 | { | ||
1817 | ptr = (BulletXNA.CollisionDesc*) (localBytes + sizeof (BulletXNA.CollisionDesc)*i); | ||
1818 | result[i] = new BulletXNA.CollisionDesc(); | ||
1819 | result[i] = *ptr; | ||
1820 | } | ||
1821 | } | ||
1822 | return result; | ||
1823 | } | ||
1824 | |||
1825 | public static unsafe CollisionDesc[] GetBulletSimCollisionStruct(byte[] buffer) | ||
1826 | { | ||
1827 | int count = buffer.Length / sizeof(CollisionDesc); | ||
1828 | CollisionDesc[] result = new CollisionDesc[count]; | ||
1829 | CollisionDesc* ptr; | ||
1830 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1831 | { | ||
1832 | for (int i = 0; i < buffer.Length; i++) | ||
1833 | { | ||
1834 | localBytes[i] = buffer[i]; | ||
1835 | } | ||
1836 | for (int i = 0; i < count; i++) | ||
1837 | { | ||
1838 | ptr = (CollisionDesc*)(localBytes + sizeof(CollisionDesc) * i); | ||
1839 | result[i] = new CollisionDesc(); | ||
1840 | result[i] = *ptr; | ||
1841 | } | ||
1842 | } | ||
1843 | return result; | ||
1844 | } | ||
1845 | public static unsafe byte[] BulletSimCollisionStructToByteArray(CollisionDesc[] CollisionDescArray, int count) | ||
1846 | { | ||
1847 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1848 | byte[] byteArray = new byte[sizeof(CollisionDesc) * arrayLength]; | ||
1849 | fixed (CollisionDesc* floatPointer = CollisionDescArray) | ||
1850 | { | ||
1851 | fixed (byte* bytePointer = byteArray) | ||
1852 | { | ||
1853 | CollisionDesc* read = floatPointer; | ||
1854 | CollisionDesc* write = (CollisionDesc*)bytePointer; | ||
1855 | for (int i = 0; i < arrayLength; i++) | ||
1856 | { | ||
1857 | *write++ = *read++; | ||
1858 | } | ||
1859 | } | ||
1860 | } | ||
1861 | return byteArray; | ||
1862 | } | ||
1863 | public static unsafe byte[] BulletXNACollisionStructToByteArray(BulletXNA.CollisionDesc[] CollisionDescArray, int count) | ||
1864 | { | ||
1865 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1866 | byte[] byteArray = new byte[sizeof(BulletXNA.CollisionDesc) * arrayLength]; | ||
1867 | fixed (BulletXNA.CollisionDesc* floatPointer = CollisionDescArray) | ||
1868 | { | ||
1869 | fixed (byte* bytePointer = byteArray) | ||
1870 | { | ||
1871 | BulletXNA.CollisionDesc* read = floatPointer; | ||
1872 | BulletXNA.CollisionDesc* write = (BulletXNA.CollisionDesc*)bytePointer; | ||
1873 | for (int i = 0; i < arrayLength; i++) | ||
1874 | { | ||
1875 | *write++ = *read++; | ||
1876 | } | ||
1877 | } | ||
1878 | } | ||
1879 | return byteArray; | ||
1880 | } | ||
1881 | public static unsafe BulletXNA.EntityProperties[] GetBulletXNAEntityStruct(byte[] buffer) | ||
1882 | { | ||
1883 | int count = buffer.Length / sizeof(BulletXNA.EntityProperties); | ||
1884 | BulletXNA.EntityProperties[] result = new BulletXNA.EntityProperties[count]; | ||
1885 | BulletXNA.EntityProperties* ptr; | ||
1886 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1887 | { | ||
1888 | for (int i = 0; i < buffer.Length; i++) | ||
1889 | { | ||
1890 | localBytes[i] = buffer[i]; | ||
1891 | } | ||
1892 | for (int i = 0; i < count; i++) | ||
1893 | { | ||
1894 | ptr = (BulletXNA.EntityProperties*)(localBytes + sizeof(BulletXNA.EntityProperties) * i); | ||
1895 | result[i] = new BulletXNA.EntityProperties(); | ||
1896 | result[i] = *ptr; | ||
1897 | } | ||
1898 | } | ||
1899 | return result; | ||
1900 | } | ||
1901 | |||
1902 | public static unsafe EntityProperties[] GetBulletSimEntityStruct(byte[] buffer) | ||
1903 | { | ||
1904 | int count = buffer.Length / sizeof(EntityProperties); | ||
1905 | EntityProperties[] result = new EntityProperties[count]; | ||
1906 | EntityProperties* ptr; | ||
1907 | fixed (byte* localBytes = new byte[buffer.Length]) | ||
1908 | { | ||
1909 | for (int i = 0; i < buffer.Length; i++) | ||
1910 | { | ||
1911 | localBytes[i] = buffer[i]; | ||
1912 | } | ||
1913 | for (int i = 0; i < count; i++) | ||
1914 | { | ||
1915 | ptr = (EntityProperties*)(localBytes + sizeof(EntityProperties) * i); | ||
1916 | result[i] = new EntityProperties(); | ||
1917 | result[i] = *ptr; | ||
1918 | } | ||
1919 | } | ||
1920 | return result; | ||
1921 | } | ||
1922 | public static unsafe byte[] BulletSimEntityStructToByteArray(EntityProperties[] CollisionDescArray, int count) | ||
1923 | { | ||
1924 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1925 | byte[] byteArray = new byte[sizeof(EntityProperties) * arrayLength]; | ||
1926 | fixed (EntityProperties* floatPointer = CollisionDescArray) | ||
1927 | { | ||
1928 | fixed (byte* bytePointer = byteArray) | ||
1929 | { | ||
1930 | EntityProperties* read = floatPointer; | ||
1931 | EntityProperties* write = (EntityProperties*)bytePointer; | ||
1932 | for (int i = 0; i < arrayLength; i++) | ||
1933 | { | ||
1934 | *write++ = *read++; | ||
1935 | } | ||
1936 | } | ||
1937 | } | ||
1938 | return byteArray; | ||
1939 | } | ||
1940 | public static unsafe byte[] BulletXNAEntityStructToByteArray(BulletXNA.EntityProperties[] CollisionDescArray, int count) | ||
1941 | { | ||
1942 | int arrayLength = CollisionDescArray.Length > count ? count : CollisionDescArray.Length; | ||
1943 | byte[] byteArray = new byte[sizeof(BulletXNA.EntityProperties) * arrayLength]; | ||
1944 | fixed (BulletXNA.EntityProperties* floatPointer = CollisionDescArray) | ||
1945 | { | ||
1946 | fixed (byte* bytePointer = byteArray) | ||
1947 | { | ||
1948 | BulletXNA.EntityProperties* read = floatPointer; | ||
1949 | BulletXNA.EntityProperties* write = (BulletXNA.EntityProperties*)bytePointer; | ||
1950 | for (int i = 0; i < arrayLength; i++) | ||
1951 | { | ||
1952 | *write++ = *read++; | ||
1953 | } | ||
1954 | } | ||
1955 | } | ||
1956 | return byteArray; | ||
1957 | } | ||
1597 | } | 1958 | } |
1598 | } | 1959 | } |