aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs')
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs99
1 files changed, 85 insertions, 14 deletions
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
index 9e048ab..85e34c1 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
@@ -47,7 +47,9 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
47 // private string m_sceneIdentifier = string.Empty; 47 // private string m_sceneIdentifier = string.Empty;
48 48
49 private List<BulletDotNETCharacter> m_characters = new List<BulletDotNETCharacter>(); 49 private List<BulletDotNETCharacter> m_characters = new List<BulletDotNETCharacter>();
50 private Dictionary<uint, BulletDotNETCharacter> m_charactersLocalID = new Dictionary<uint, BulletDotNETCharacter>();
50 private List<BulletDotNETPrim> m_prims = new List<BulletDotNETPrim>(); 51 private List<BulletDotNETPrim> m_prims = new List<BulletDotNETPrim>();
52 private Dictionary<uint, BulletDotNETPrim> m_primsLocalID = new Dictionary<uint, BulletDotNETPrim>();
51 private List<BulletDotNETPrim> m_activePrims = new List<BulletDotNETPrim>(); 53 private List<BulletDotNETPrim> m_activePrims = new List<BulletDotNETPrim>();
52 private List<PhysicsActor> m_taintedActors = new List<PhysicsActor>(); 54 private List<PhysicsActor> m_taintedActors = new List<PhysicsActor>();
53 private btDiscreteDynamicsWorld m_world; 55 private btDiscreteDynamicsWorld m_world;
@@ -134,7 +136,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
134 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); 136 m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
135 m_world = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration); 137 m_world = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
136 m_world.setGravity(m_gravity); 138 m_world.setGravity(m_gravity);
137 //EnableCollisionInterface(); 139 EnableCollisionInterface();
138 140
139 141
140 } 142 }
@@ -145,7 +147,16 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
145 avCapRadius, avStandupTensor, avDensity, 147 avCapRadius, avStandupTensor, avDensity,
146 avHeightFudgeFactor, avMovementDivisorWalk, 148 avHeightFudgeFactor, avMovementDivisorWalk,
147 avMovementDivisorRun); 149 avMovementDivisorRun);
148 m_characters.Add(chr); 150 try
151 {
152 m_characters.Add(chr);
153 m_charactersLocalID.Add(chr.m_localID, chr);
154 }
155 catch
156 {
157 // noop if it's already there
158 m_log.Debug("[PHYSICS] BulletDotNet: adding duplicate avatar localID");
159 }
149 AddPhysicsActorTaint(chr); 160 AddPhysicsActorTaint(chr);
150 return chr; 161 return chr;
151 } 162 }
@@ -154,6 +165,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
154 { 165 {
155 BulletDotNETCharacter chr = (BulletDotNETCharacter) actor; 166 BulletDotNETCharacter chr = (BulletDotNETCharacter) actor;
156 167
168 m_charactersLocalID.Remove(chr.m_localID);
157 m_characters.Remove(chr); 169 m_characters.Remove(chr);
158 m_world.removeRigidBody(chr.Body); 170 m_world.removeRigidBody(chr.Body);
159 m_world.removeCollisionObject(chr.Body); 171 m_world.removeCollisionObject(chr.Body);
@@ -279,7 +291,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
279 prim.Move(timeStep); 291 prim.Move(timeStep);
280 } 292 }
281 } 293 }
282 float steps = m_world.stepSimulation(timeStep * 1000, 10, WorldTimeComp); 294 float steps = m_world.stepSimulation(timeStep, 10, WorldTimeComp);
283 295
284 foreach (BulletDotNETCharacter chr in m_characters) 296 foreach (BulletDotNETCharacter chr in m_characters)
285 { 297 {
@@ -296,20 +308,67 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
296 } 308 }
297 if (m_CollisionInterface != null) 309 if (m_CollisionInterface != null)
298 { 310 {
299 List<int> collisions = m_CollisionInterface.GetContactList(); 311 List<BulletDotNETPrim> primsWithCollisions = new List<BulletDotNETPrim>();
300 lock (collisions) 312 List<BulletDotNETCharacter> charactersWithCollisions = new List<BulletDotNETCharacter>();
313
314 // get the collisions that happened this tick
315 List<BulletDotNET.ContactAddedCallbackHandler.ContactInfo> collisions = m_CollisionInterface.GetContactList();
316 // passed back the localID of the prim so we can associate the prim
317 foreach (BulletDotNET.ContactAddedCallbackHandler.ContactInfo ci in collisions)
301 { 318 {
302 foreach (int pvalue in collisions) 319 // ContactPoint = { contactPoint, contactNormal, penetrationDepth }
303 { 320 ContactPoint contact = new ContactPoint(new Vector3(ci.pX, ci.pY, ci.pZ),
304 System.Console.Write(string.Format("{0} ", pvalue)); 321 new Vector3(ci.nX, ci.nY, ci.nZ), ci.depth);
305 } 322
323 ProcessContact(ci.contact, ci.contactWith, contact, ref primsWithCollisions, ref charactersWithCollisions);
324 ProcessContact(ci.contactWith, ci.contact, contact, ref primsWithCollisions, ref charactersWithCollisions);
325
306 } 326 }
307 m_CollisionInterface.Clear(); 327 m_CollisionInterface.Clear();
308 328 // for those prims and characters that had collisions cause collision events
329 foreach (BulletDotNETPrim bdnp in primsWithCollisions)
330 {
331 bdnp.SendCollisions();
332 }
333 foreach (BulletDotNETCharacter bdnc in charactersWithCollisions)
334 {
335 bdnc.SendCollisions();
336 }
309 } 337 }
310 return steps; 338 return steps;
311 } 339 }
312 340
341 private void ProcessContact(uint cont, uint contWith, ContactPoint contact,
342 ref List<BulletDotNETPrim> primsWithCollisions,
343 ref List<BulletDotNETCharacter> charactersWithCollisions)
344 {
345 BulletDotNETPrim bdnp;
346 // collisions with a normal prim?
347 if (m_primsLocalID.TryGetValue(cont, out bdnp))
348 {
349 // Added collision event to the prim. This creates a pile of events
350 // that will be sent to any subscribed listeners.
351 bdnp.AddCollision(contWith, contact);
352 if (!primsWithCollisions.Contains(bdnp))
353 {
354 primsWithCollisions.Add(bdnp);
355 }
356 }
357 else
358 {
359 BulletDotNETCharacter bdnc;
360 // if not a prim, maybe it's one of the characters
361 if (m_charactersLocalID.TryGetValue(cont, out bdnc))
362 {
363 bdnc.AddCollision(contWith, contact);
364 if (!charactersWithCollisions.Contains(bdnc))
365 {
366 charactersWithCollisions.Add(bdnc);
367 }
368 }
369 }
370 }
371
313 public override void GetResults() 372 public override void GetResults()
314 { 373 {
315 374
@@ -387,6 +446,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
387 m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition); 446 m_terrainTransform = new btTransform(QuatIdentity, m_terrainPosition);
388 m_terrainMotionState = new btDefaultMotionState(m_terrainTransform); 447 m_terrainMotionState = new btDefaultMotionState(m_terrainTransform);
389 TerrainBody = new btRigidBody(0, m_terrainMotionState, m_terrainShape); 448 TerrainBody = new btRigidBody(0, m_terrainMotionState, m_terrainShape);
449 TerrainBody.setUserPointer((IntPtr)0);
390 m_world.addRigidBody(TerrainBody); 450 m_world.addRigidBody(TerrainBody);
391 451
392 452
@@ -459,6 +519,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
459 { 519 {
460 lock (m_prims) 520 lock (m_prims)
461 { 521 {
522 m_primsLocalID.Clear();
462 foreach (BulletDotNETPrim prim in m_prims) 523 foreach (BulletDotNETPrim prim in m_prims)
463 { 524 {
464 if (prim.Body != null) 525 if (prim.Body != null)
@@ -513,6 +574,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
513 m_world.removeRigidBody(body); 574 m_world.removeRigidBody(body);
514 } 575 }
515 remActivePrim(prm); 576 remActivePrim(prm);
577 m_primsLocalID.Remove(prm.m_localID);
516 m_prims.Remove(prm); 578 m_prims.Remove(prm);
517 } 579 }
518 580
@@ -686,9 +748,18 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
686 { 748 {
687 if (!m_prims.Contains(pPrim)) 749 if (!m_prims.Contains(pPrim))
688 { 750 {
689 m_prims.Add(pPrim); 751 try
752 {
753 m_prims.Add(pPrim);
754 m_primsLocalID.Add(pPrim.m_localID, pPrim);
755 }
756 catch
757 {
758 // noop if it's already there
759 m_log.Debug("[PHYSICS] BulletDotNet: adding duplicate prim localID");
760 }
690 m_world.addRigidBody(pPrim.Body); 761 m_world.addRigidBody(pPrim.Body);
691 m_log.Debug("ADDED"); 762 // m_log.Debug("[PHYSICS] added prim to scene");
692 } 763 }
693 } 764 }
694 } 765 }
@@ -696,8 +767,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
696 { 767 {
697 if (m_CollisionInterface == null) 768 if (m_CollisionInterface == null)
698 { 769 {
699 m_CollisionInterface = new ContactAddedCallbackHandler(); 770 m_CollisionInterface = new ContactAddedCallbackHandler(m_world);
700 m_world.SetCollisionAddedCallback(m_CollisionInterface); 771 // m_world.SetCollisionAddedCallback(m_CollisionInterface);
701 } 772 }
702 } 773 }
703 774