aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs232
1 files changed, 72 insertions, 160 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 26a581f..29f27e8 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -49,8 +49,6 @@ public sealed class BSPrim : BSPhysObject
49 private ulong _hullKey; 49 private ulong _hullKey;
50 private List<ConvexResult> _hulls; 50 private List<ConvexResult> _hulls;
51 51
52 private BSScene _scene;
53 public BSScene Scene { get { return _scene; } }
54 private String _avName; 52 private String _avName;
55 private uint _localID = 0; 53 private uint _localID = 0;
56 54
@@ -87,18 +85,6 @@ public sealed class BSPrim : BSPhysObject
87 private bool _kinematic; 85 private bool _kinematic;
88 private float _buoyancy; 86 private float _buoyancy;
89 87
90 // Membership in a linkset is controlled by this class.
91 public override BSLinkset Linkset { get; set; }
92
93 private int _subscribedEventsMs = 0;
94 private int _nextCollisionOkTime = 0;
95 long _collidingStep;
96 long _collidingGroundStep;
97 CollisionFlags m_currentCollisionFlags = 0;
98
99 public override BulletBody BSBody { get; set; }
100 public override BulletShape BSShape { get; set; }
101
102 private BSDynamics _vehicle; 88 private BSDynamics _vehicle;
103 89
104 private OMV.Vector3 _PIDTarget; 90 private OMV.Vector3 _PIDTarget;
@@ -113,10 +99,10 @@ public sealed class BSPrim : BSPhysObject
113 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical) 99 OMV.Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
114 { 100 {
115 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID); 101 // m_log.DebugFormat("{0}: BSPrim creation of {1}, id={2}", LogHeader, primName, localID);
102 base.BaseInitialize(parent_scene);
116 _localID = localID; 103 _localID = localID;
117 _avName = primName; 104 _avName = primName;
118 _physicsActorType = (int)ActorTypes.Prim; 105 _physicsActorType = (int)ActorTypes.Prim;
119 _scene = parent_scene;
120 _position = pos; 106 _position = pos;
121 _size = size; 107 _size = size;
122 _scale = new OMV.Vector3(1f, 1f, 1f); // the scale will be set by CreateGeom depending on object type 108 _scale = new OMV.Vector3(1f, 1f, 1f); // the scale will be set by CreateGeom depending on object type
@@ -129,25 +115,23 @@ public sealed class BSPrim : BSPhysObject
129 _pbs = pbs; 115 _pbs = pbs;
130 _isPhysical = pisPhysical; 116 _isPhysical = pisPhysical;
131 _isVolumeDetect = false; 117 _isVolumeDetect = false;
132 _subscribedEventsMs = 0; 118 _friction = PhysicsScene.Params.defaultFriction; // TODO: compute based on object material
133 _friction = _scene.Params.defaultFriction; // TODO: compute based on object material 119 _density = PhysicsScene.Params.defaultDensity; // TODO: compute based on object material
134 _density = _scene.Params.defaultDensity; // TODO: compute based on object material 120 _restitution = PhysicsScene.Params.defaultRestitution;
135 _restitution = _scene.Params.defaultRestitution; 121 _vehicle = new BSDynamics(PhysicsScene, this); // add vehicleness
136 Linkset = new BSLinkset(Scene, this); // a linkset of one
137 _vehicle = new BSDynamics(Scene, this); // add vehicleness
138 _mass = CalculateMass(); 122 _mass = CalculateMass();
139 DetailLog("{0},BSPrim.constructor,call", LocalID); 123 DetailLog("{0},BSPrim.constructor,call", LocalID);
140 // do the actual object creation at taint time 124 // do the actual object creation at taint time
141 _scene.TaintedObject("BSPrim.create", delegate() 125 PhysicsScene.TaintedObject("BSPrim.create", delegate()
142 { 126 {
143 CreateGeomAndObject(true); 127 CreateGeomAndObject(true);
144 128
145 // Get the pointer to the physical body for this object. 129 // Get the pointer to the physical body for this object.
146 // At the moment, we're still letting BulletSim manage the creation and destruction 130 // At the moment, we're still letting BulletSim manage the creation and destruction
147 // of the object. Someday we'll move that into the C# code. 131 // of the object. Someday we'll move that into the C# code.
148 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); 132 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(PhysicsScene.World.Ptr, LocalID));
149 BSShape = new BulletShape(BulletSimAPI.GetCollisionShape2(BSBody.Ptr)); 133 BSShape = new BulletShape(BulletSimAPI.GetCollisionShape2(BSBody.Ptr));
150 m_currentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr); 134 CurrentCollisionFlags = BulletSimAPI.GetCollisionFlags2(BSBody.Ptr);
151 }); 135 });
152 } 136 }
153 137
@@ -168,11 +152,11 @@ public sealed class BSPrim : BSPhysObject
168 // Undo any vehicle properties 152 // Undo any vehicle properties
169 this.VehicleType = (int)Vehicle.TYPE_NONE; 153 this.VehicleType = (int)Vehicle.TYPE_NONE;
170 154
171 _scene.TaintedObject("BSPrim.destroy", delegate() 155 PhysicsScene.TaintedObject("BSPrim.destroy", delegate()
172 { 156 {
173 DetailLog("{0},BSPrim.Destroy,taint,", LocalID); 157 DetailLog("{0},BSPrim.Destroy,taint,", LocalID);
174 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. 158 // everything in the C# world will get garbage collected. Tell the C++ world to free stuff.
175 BulletSimAPI.DestroyObject(_scene.WorldID, LocalID); 159 BulletSimAPI.DestroyObject(PhysicsScene.WorldID, LocalID);
176 }); 160 });
177 } 161 }
178 162
@@ -183,7 +167,7 @@ public sealed class BSPrim : BSPhysObject
183 get { return _size; } 167 get { return _size; }
184 set { 168 set {
185 _size = value; 169 _size = value;
186 _scene.TaintedObject("BSPrim.setSize", delegate() 170 PhysicsScene.TaintedObject("BSPrim.setSize", delegate()
187 { 171 {
188 _mass = CalculateMass(); // changing size changes the mass 172 _mass = CalculateMass(); // changing size changes the mass
189 // Since _size changed, the mesh needs to be rebuilt. If rebuilt, all the correct 173 // Since _size changed, the mesh needs to be rebuilt. If rebuilt, all the correct
@@ -196,7 +180,7 @@ public sealed class BSPrim : BSPhysObject
196 public override PrimitiveBaseShape Shape { 180 public override PrimitiveBaseShape Shape {
197 set { 181 set {
198 _pbs = value; 182 _pbs = value;
199 _scene.TaintedObject("BSPrim.setShape", delegate() 183 PhysicsScene.TaintedObject("BSPrim.setShape", delegate()
200 { 184 {
201 _mass = CalculateMass(); // changing the shape changes the mass 185 _mass = CalculateMass(); // changing the shape changes the mass
202 CreateGeomAndObject(false); 186 CreateGeomAndObject(false);
@@ -214,7 +198,7 @@ public sealed class BSPrim : BSPhysObject
214 public override bool Selected { 198 public override bool Selected {
215 set { 199 set {
216 _isSelected = value; 200 _isSelected = value;
217 _scene.TaintedObject("BSPrim.setSelected", delegate() 201 PhysicsScene.TaintedObject("BSPrim.setSelected", delegate()
218 { 202 {
219 SetObjectDynamic(); 203 SetObjectDynamic();
220 }); 204 });
@@ -283,13 +267,13 @@ public sealed class BSPrim : BSPhysObject
283 _position = BulletSimAPI.GetPosition2(BSBody.Ptr); 267 _position = BulletSimAPI.GetPosition2(BSBody.Ptr);
284 268
285 // don't do the GetObjectPosition for root elements because this function is called a zillion times 269 // don't do the GetObjectPosition for root elements because this function is called a zillion times
286 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); 270 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID);
287 return _position; 271 return _position;
288 } 272 }
289 set { 273 set {
290 _position = value; 274 _position = value;
291 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? 275 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint?
292 _scene.TaintedObject("BSPrim.setPosition", delegate() 276 PhysicsScene.TaintedObject("BSPrim.setPosition", delegate()
293 { 277 {
294 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 278 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
295 BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); 279 BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation);
@@ -327,7 +311,7 @@ public sealed class BSPrim : BSPhysObject
327 get { return _force; } 311 get { return _force; }
328 set { 312 set {
329 _force = value; 313 _force = value;
330 _scene.TaintedObject("BSPrim.setForce", delegate() 314 PhysicsScene.TaintedObject("BSPrim.setForce", delegate()
331 { 315 {
332 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); 316 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force);
333 BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force); 317 BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force);
@@ -342,40 +326,40 @@ public sealed class BSPrim : BSPhysObject
342 set { 326 set {
343 Vehicle type = (Vehicle)value; 327 Vehicle type = (Vehicle)value;
344 BSPrim vehiclePrim = this; 328 BSPrim vehiclePrim = this;
345 _scene.TaintedObject("setVehicleType", delegate() 329 PhysicsScene.TaintedObject("setVehicleType", delegate()
346 { 330 {
347 // Done at taint time so we're sure the physics engine is not using the variables 331 // Done at taint time so we're sure the physics engine is not using the variables
348 // Vehicle code changes the parameters for this vehicle type. 332 // Vehicle code changes the parameters for this vehicle type.
349 _vehicle.ProcessTypeChange(type); 333 _vehicle.ProcessTypeChange(type);
350 // Tell the scene about the vehicle so it will get processing each frame. 334 // Tell the scene about the vehicle so it will get processing each frame.
351 _scene.VehicleInSceneTypeChanged(this, type); 335 PhysicsScene.VehicleInSceneTypeChanged(this, type);
352 }); 336 });
353 } 337 }
354 } 338 }
355 public override void VehicleFloatParam(int param, float value) 339 public override void VehicleFloatParam(int param, float value)
356 { 340 {
357 _scene.TaintedObject("BSPrim.VehicleFloatParam", delegate() 341 PhysicsScene.TaintedObject("BSPrim.VehicleFloatParam", delegate()
358 { 342 {
359 _vehicle.ProcessFloatVehicleParam((Vehicle)param, value); 343 _vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
360 }); 344 });
361 } 345 }
362 public override void VehicleVectorParam(int param, OMV.Vector3 value) 346 public override void VehicleVectorParam(int param, OMV.Vector3 value)
363 { 347 {
364 _scene.TaintedObject("BSPrim.VehicleVectorParam", delegate() 348 PhysicsScene.TaintedObject("BSPrim.VehicleVectorParam", delegate()
365 { 349 {
366 _vehicle.ProcessVectorVehicleParam((Vehicle)param, value); 350 _vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
367 }); 351 });
368 } 352 }
369 public override void VehicleRotationParam(int param, OMV.Quaternion rotation) 353 public override void VehicleRotationParam(int param, OMV.Quaternion rotation)
370 { 354 {
371 _scene.TaintedObject("BSPrim.VehicleRotationParam", delegate() 355 PhysicsScene.TaintedObject("BSPrim.VehicleRotationParam", delegate()
372 { 356 {
373 _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); 357 _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
374 }); 358 });
375 } 359 }
376 public override void VehicleFlags(int param, bool remove) 360 public override void VehicleFlags(int param, bool remove)
377 { 361 {
378 _scene.TaintedObject("BSPrim.VehicleFlags", delegate() 362 PhysicsScene.TaintedObject("BSPrim.VehicleFlags", delegate()
379 { 363 {
380 _vehicle.ProcessVehicleFlags(param, remove); 364 _vehicle.ProcessVehicleFlags(param, remove);
381 }); 365 });
@@ -393,8 +377,9 @@ public sealed class BSPrim : BSPhysObject
393 public override void SetVolumeDetect(int param) { 377 public override void SetVolumeDetect(int param) {
394 bool newValue = (param != 0); 378 bool newValue = (param != 0);
395 _isVolumeDetect = newValue; 379 _isVolumeDetect = newValue;
396 _scene.TaintedObject("BSPrim.SetVolumeDetect", delegate() 380 PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate()
397 { 381 {
382 DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect);
398 SetObjectDynamic(); 383 SetObjectDynamic();
399 }); 384 });
400 return; 385 return;
@@ -404,7 +389,7 @@ public sealed class BSPrim : BSPhysObject
404 get { return _velocity; } 389 get { return _velocity; }
405 set { 390 set {
406 _velocity = value; 391 _velocity = value;
407 _scene.TaintedObject("BSPrim.setVelocity", delegate() 392 PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate()
408 { 393 {
409 DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); 394 DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity);
410 BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, _velocity); 395 BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, _velocity);
@@ -438,9 +423,9 @@ public sealed class BSPrim : BSPhysObject
438 set { 423 set {
439 _orientation = value; 424 _orientation = value;
440 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? 425 // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint?
441 _scene.TaintedObject("BSPrim.setOrientation", delegate() 426 PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate()
442 { 427 {
443 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); 428 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID);
444 DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); 429 DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
445 BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation); 430 BulletSimAPI.SetTranslation2(BSBody.Ptr, _position, _orientation);
446 }); 431 });
@@ -454,8 +439,9 @@ public sealed class BSPrim : BSPhysObject
454 get { return _isPhysical; } 439 get { return _isPhysical; }
455 set { 440 set {
456 _isPhysical = value; 441 _isPhysical = value;
457 _scene.TaintedObject("BSPrim.setIsPhysical", delegate() 442 PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate()
458 { 443 {
444 DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical);
459 SetObjectDynamic(); 445 SetObjectDynamic();
460 }); 446 });
461 } 447 }
@@ -493,9 +479,9 @@ public sealed class BSPrim : BSPhysObject
493 // Bullet wants static objects to have a mass of zero 479 // Bullet wants static objects to have a mass of zero
494 float mass = IsStatic ? 0f : _mass; 480 float mass = IsStatic ? 0f : _mass;
495 481
496 BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); 482 BulletSimAPI.SetObjectProperties(Scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass);
497 */ 483 */
498 BulletSimAPI.RemoveObjectFromWorld2(Scene.World.Ptr, BSBody.Ptr); 484 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.Ptr, BSBody.Ptr);
499 485
500 // Set up the object physicalness (does gravity and collisions move this object) 486 // Set up the object physicalness (does gravity and collisions move this object)
501 MakeDynamic(IsStatic); 487 MakeDynamic(IsStatic);
@@ -506,15 +492,15 @@ public sealed class BSPrim : BSPhysObject
506 // Arrange for collisions events if the simulator wants them 492 // Arrange for collisions events if the simulator wants them
507 EnableCollisions(SubscribedEvents()); 493 EnableCollisions(SubscribedEvents());
508 494
509 BulletSimAPI.AddObjectToWorld2(Scene.World.Ptr, BSBody.Ptr); 495 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.Ptr, BSBody.Ptr);
510 496
511 // Recompute any linkset parameters. 497 // Recompute any linkset parameters.
512 // When going from non-physical to physical, this re-enables the constraints that 498 // When going from non-physical to physical, this re-enables the constraints that
513 // had been automatically disabled when the mass was set to zero. 499 // had been automatically disabled when the mass was set to zero.
514 Linkset.Refresh(this); 500 Linkset.Refresh(this);
515 501
516 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,static={1},solid={2},mass={3}, cf={4}", 502 DetailLog("{0},BSPrim.UpdatePhysicalParameters,taint,static={1},solid={2},mass={3},collide={4},cf={5}",
517 LocalID, IsStatic, IsSolid, _mass, m_currentCollisionFlags); 503 LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags);
518 } 504 }
519 505
520 // "Making dynamic" means changing to and from static. 506 // "Making dynamic" means changing to and from static.
@@ -527,7 +513,7 @@ public sealed class BSPrim : BSPhysObject
527 if (makeStatic) 513 if (makeStatic)
528 { 514 {
529 // Become a Bullet 'static' object type 515 // Become a Bullet 'static' object type
530 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT); 516 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
531 // Stop all movement 517 // Stop all movement
532 BulletSimAPI.ClearAllForces2(BSBody.Ptr); 518 BulletSimAPI.ClearAllForces2(BSBody.Ptr);
533 // Center of mass is at the center of the object 519 // Center of mass is at the center of the object
@@ -539,16 +525,17 @@ public sealed class BSPrim : BSPhysObject
539 // There can be special things needed for implementing linksets 525 // There can be special things needed for implementing linksets
540 Linkset.MakeStatic(this); 526 Linkset.MakeStatic(this);
541 // The activation state is 'sleeping' so Bullet will not try to act on it 527 // The activation state is 'sleeping' so Bullet will not try to act on it
542 BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.ISLAND_SLEEPING); 528 // BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.ISLAND_SLEEPING);
529 BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.DISABLE_SIMULATION);
543 } 530 }
544 else 531 else
545 { 532 {
546 // Not a Bullet static object 533 // Not a Bullet static object
547 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT); 534 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
548 535
549 // Set various physical properties so internal things will get computed correctly as they are set 536 // Set various physical properties so internal dynamic properties will get computed correctly as they are set
550 BulletSimAPI.SetFriction2(BSBody.Ptr, Scene.Params.defaultFriction); 537 BulletSimAPI.SetFriction2(BSBody.Ptr, PhysicsScene.Params.defaultFriction);
551 BulletSimAPI.SetRestitution2(BSBody.Ptr, Scene.Params.defaultRestitution); 538 BulletSimAPI.SetRestitution2(BSBody.Ptr, PhysicsScene.Params.defaultRestitution);
552 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 539 // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382
553 BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero); 540 BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
554 BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero); 541 BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero);
@@ -562,10 +549,10 @@ public sealed class BSPrim : BSPhysObject
562 BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr); 549 BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
563 550
564 // Various values for simulation limits 551 // Various values for simulation limits
565 BulletSimAPI.SetDamping2(BSBody.Ptr, Scene.Params.linearDamping, Scene.Params.angularDamping); 552 BulletSimAPI.SetDamping2(BSBody.Ptr, PhysicsScene.Params.linearDamping, PhysicsScene.Params.angularDamping);
566 BulletSimAPI.SetDeactivationTime2(BSBody.Ptr, Scene.Params.deactivationTime); 553 BulletSimAPI.SetDeactivationTime2(BSBody.Ptr, PhysicsScene.Params.deactivationTime);
567 BulletSimAPI.SetSleepingThresholds2(BSBody.Ptr, Scene.Params.linearSleepingThreshold, Scene.Params.angularSleepingThreshold); 554 BulletSimAPI.SetSleepingThresholds2(BSBody.Ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold);
568 BulletSimAPI.SetContactProcessingThreshold2(BSBody.Ptr, Scene.Params.contactProcessingThreshold); 555 BulletSimAPI.SetContactProcessingThreshold2(BSBody.Ptr, PhysicsScene.Params.contactProcessingThreshold);
569 556
570 // There can be special things needed for implementing linksets 557 // There can be special things needed for implementing linksets
571 Linkset.MakeDynamic(this); 558 Linkset.MakeDynamic(this);
@@ -581,11 +568,11 @@ public sealed class BSPrim : BSPhysObject
581 if (makeSolid) 568 if (makeSolid)
582 { 569 {
583 // Easy in Bullet -- just remove the object flag that controls collision response 570 // Easy in Bullet -- just remove the object flag that controls collision response
584 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 571 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
585 } 572 }
586 else 573 else
587 { 574 {
588 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); 575 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE);
589 } 576 }
590 } 577 }
591 578
@@ -594,11 +581,11 @@ public sealed class BSPrim : BSPhysObject
594 { 581 {
595 if (wantsCollisionEvents) 582 if (wantsCollisionEvents)
596 { 583 {
597 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 584 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
598 } 585 }
599 else 586 else
600 { 587 {
601 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 588 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
602 } 589 }
603 } 590 }
604 591
@@ -618,11 +605,11 @@ public sealed class BSPrim : BSPhysObject
618 set { _throttleUpdates = value; } 605 set { _throttleUpdates = value; }
619 } 606 }
620 public override bool IsColliding { 607 public override bool IsColliding {
621 get { return (_collidingStep == _scene.SimulationStep); } 608 get { return (CollidingStep == PhysicsScene.SimulationStep); }
622 set { _isColliding = value; } 609 set { _isColliding = value; }
623 } 610 }
624 public override bool CollidingGround { 611 public override bool CollidingGround {
625 get { return (_collidingGroundStep == _scene.SimulationStep); } 612 get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
626 set { _collidingGround = value; } 613 set { _collidingGround = value; }
627 } 614 }
628 public override bool CollidingObj { 615 public override bool CollidingObj {
@@ -656,7 +643,7 @@ public sealed class BSPrim : BSPhysObject
656 set { 643 set {
657 _rotationalVelocity = value; 644 _rotationalVelocity = value;
658 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); 645 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity);
659 _scene.TaintedObject("BSPrim.setRotationalVelocity", delegate() 646 PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate()
660 { 647 {
661 DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); 648 DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity);
662 BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, _rotationalVelocity); 649 BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, _rotationalVelocity);
@@ -673,13 +660,13 @@ public sealed class BSPrim : BSPhysObject
673 get { return _buoyancy; } 660 get { return _buoyancy; }
674 set { 661 set {
675 _buoyancy = value; 662 _buoyancy = value;
676 _scene.TaintedObject("BSPrim.setBuoyancy", delegate() 663 PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate()
677 { 664 {
678 DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 665 DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
679 // Buoyancy is faked by changing the gravity applied to the object 666 // Buoyancy is faked by changing the gravity applied to the object
680 float grav = Scene.Params.gravity * (1f - _buoyancy); 667 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
681 BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav)); 668 BulletSimAPI.SetGravity2(BSBody.Ptr, new OMV.Vector3(0f, 0f, grav));
682 // BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); 669 // BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, _localID, _buoyancy);
683 }); 670 });
684 } 671 }
685 } 672 }
@@ -730,7 +717,7 @@ public sealed class BSPrim : BSPhysObject
730 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID); 717 m_log.WarnFormat("{0}: Got a NaN force applied to a prim. LocalID={1}", LogHeader, LocalID);
731 return; 718 return;
732 } 719 }
733 _scene.TaintedObject("BSPrim.AddForce", delegate() 720 PhysicsScene.TaintedObject("BSPrim.AddForce", delegate()
734 { 721 {
735 OMV.Vector3 fSum = OMV.Vector3.Zero; 722 OMV.Vector3 fSum = OMV.Vector3.Zero;
736 lock (m_accumulatedForces) 723 lock (m_accumulatedForces)
@@ -754,30 +741,6 @@ public sealed class BSPrim : BSPhysObject
754 public override void SetMomentum(OMV.Vector3 momentum) { 741 public override void SetMomentum(OMV.Vector3 momentum) {
755 DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); 742 DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum);
756 } 743 }
757 public override void SubscribeEvents(int ms) {
758 _subscribedEventsMs = ms;
759 if (ms > 0)
760 {
761 // make sure first collision happens
762 _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs;
763
764 Scene.TaintedObject("BSPrim.SubscribeEvents", delegate()
765 {
766 m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
767 });
768 }
769 }
770 public override void UnSubscribeEvents() {
771 _subscribedEventsMs = 0;
772 Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate()
773 {
774 m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
775 });
776 }
777 public override bool SubscribedEvents() {
778 return (_subscribedEventsMs > 0);
779 }
780
781 #region Mass Calculation 744 #region Mass Calculation
782 745
783 private float CalculateMass() 746 private float CalculateMass()
@@ -1071,8 +1034,8 @@ public sealed class BSPrim : BSPhysObject
1071 if (returnMass <= 0) 1034 if (returnMass <= 0)
1072 returnMass = 0.0001f; 1035 returnMass = 0.0001f;
1073 1036
1074 if (returnMass > _scene.MaximumObjectMass) 1037 if (returnMass > PhysicsScene.MaximumObjectMass)
1075 returnMass = _scene.MaximumObjectMass; 1038 returnMass = PhysicsScene.MaximumObjectMass;
1076 1039
1077 return returnMass; 1040 return returnMass;
1078 }// end CalculateMass 1041 }// end CalculateMass
@@ -1090,7 +1053,7 @@ public sealed class BSPrim : BSPhysObject
1090 bool haveShape = false; 1053 bool haveShape = false;
1091 1054
1092 // If the prim attributes are simple, this could be a simple Bullet native shape 1055 // If the prim attributes are simple, this could be a simple Bullet native shape
1093 if ((_pbs.SculptEntry && !Scene.ShouldMeshSculptedPrim) 1056 if ((_pbs.SculptEntry && !PhysicsScene.ShouldMeshSculptedPrim)
1094 || (_pbs.ProfileBegin == 0 && _pbs.ProfileEnd == 0 1057 || (_pbs.ProfileBegin == 0 && _pbs.ProfileEnd == 0
1095 && _pbs.ProfileHollow == 0 1058 && _pbs.ProfileHollow == 0
1096 && _pbs.PathTwist == 0 && _pbs.PathTwistBegin == 0 1059 && _pbs.PathTwist == 0 && _pbs.PathTwistBegin == 0
@@ -1156,12 +1119,12 @@ public sealed class BSPrim : BSPhysObject
1156 private bool CreateGeomMesh() 1119 private bool CreateGeomMesh()
1157 { 1120 {
1158 // level of detail based on size and type of the object 1121 // level of detail based on size and type of the object
1159 float lod = _scene.MeshLOD; 1122 float lod = PhysicsScene.MeshLOD;
1160 if (_pbs.SculptEntry) 1123 if (_pbs.SculptEntry)
1161 lod = _scene.SculptLOD; 1124 lod = PhysicsScene.SculptLOD;
1162 float maxAxis = Math.Max(_size.X, Math.Max(_size.Y, _size.Z)); 1125 float maxAxis = Math.Max(_size.X, Math.Max(_size.Y, _size.Z));
1163 if (maxAxis > _scene.MeshMegaPrimThreshold) 1126 if (maxAxis > PhysicsScene.MeshMegaPrimThreshold)
1164 lod = _scene.MeshMegaPrimLOD; 1127 lod = PhysicsScene.MeshMegaPrimLOD;
1165 1128
1166 ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod); 1129 ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod);
1167 // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey); 1130 // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey);
@@ -1175,14 +1138,14 @@ public sealed class BSPrim : BSPhysObject
1175 { 1138 {
1176 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); 1139 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey);
1177 DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); 1140 DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey);
1178 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); 1141 BulletSimAPI.DestroyMesh(PhysicsScene.WorldID, _meshKey);
1179 _mesh = null; 1142 _mesh = null;
1180 _meshKey = 0; 1143 _meshKey = 0;
1181 } 1144 }
1182 1145
1183 _meshKey = newMeshKey; 1146 _meshKey = newMeshKey;
1184 // always pass false for physicalness as this creates some sort of bounding box which we don't need 1147 // always pass false for physicalness as this creates some sort of bounding box which we don't need
1185 _mesh = _scene.mesher.CreateMesh(_avName, _pbs, _size, lod, false); 1148 _mesh = PhysicsScene.mesher.CreateMesh(_avName, _pbs, _size, lod, false);
1186 1149
1187 int[] indices = _mesh.getIndexListAsInt(); 1150 int[] indices = _mesh.getIndexListAsInt();
1188 List<OMV.Vector3> vertices = _mesh.getVertexList(); 1151 List<OMV.Vector3> vertices = _mesh.getVertexList();
@@ -1198,7 +1161,7 @@ public sealed class BSPrim : BSPhysObject
1198 1161
1199 // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}", 1162 // m_log.DebugFormat("{0}: CreateGeomMesh: calling CreateMesh. lid={1}, key={2}, indices={3}, vertices={4}",
1200 // LogHeader, _localID, _meshKey, indices.Length, vertices.Count); 1163 // LogHeader, _localID, _meshKey, indices.Length, vertices.Count);
1201 BulletSimAPI.CreateMesh(_scene.WorldID, _meshKey, indices.GetLength(0), indices, 1164 BulletSimAPI.CreateMesh(PhysicsScene.WorldID, _meshKey, indices.GetLength(0), indices,
1202 vertices.Count, verticesAsFloats); 1165 vertices.Count, verticesAsFloats);
1203 1166
1204 _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; 1167 _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH;
@@ -1211,7 +1174,7 @@ public sealed class BSPrim : BSPhysObject
1211 // Returns 'true' of a mesh was actually rebuild (we could also have one of these specs). 1174 // Returns 'true' of a mesh was actually rebuild (we could also have one of these specs).
1212 private bool CreateGeomHull() 1175 private bool CreateGeomHull()
1213 { 1176 {
1214 float lod = _pbs.SculptEntry ? _scene.SculptLOD : _scene.MeshLOD; 1177 float lod = _pbs.SculptEntry ? PhysicsScene.SculptLOD : PhysicsScene.MeshLOD;
1215 ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod); 1178 ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod);
1216 // m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _hullKey, newHullKey); 1179 // m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _hullKey, newHullKey);
1217 1180
@@ -1225,7 +1188,7 @@ public sealed class BSPrim : BSPhysObject
1225 { 1188 {
1226 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); 1189 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey);
1227 DetailLog("{0},BSPrim.CreateGeomHull,deleteOldHull,key={1}", LocalID, _hullKey); 1190 DetailLog("{0},BSPrim.CreateGeomHull,deleteOldHull,key={1}", LocalID, _hullKey);
1228 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); 1191 BulletSimAPI.DestroyHull(PhysicsScene.WorldID, _hullKey);
1229 _hullKey = 0; 1192 _hullKey = 0;
1230 } 1193 }
1231 1194
@@ -1314,7 +1277,7 @@ public sealed class BSPrim : BSPhysObject
1314 1277
1315 // create the hull definition in Bullet 1278 // create the hull definition in Bullet
1316 // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, _localID, _hullKey, hullCount); 1279 // m_log.DebugFormat("{0}: CreateGeom: calling CreateHull. lid={1}, key={2}, hulls={3}", LogHeader, _localID, _hullKey, hullCount);
1317 BulletSimAPI.CreateHull(_scene.WorldID, _hullKey, hullCount, convHulls); 1280 BulletSimAPI.CreateHull(PhysicsScene.WorldID, _hullKey, hullCount, convHulls);
1318 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; 1281 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL;
1319 // meshes are already scaled by the meshmerizer 1282 // meshes are already scaled by the meshmerizer
1320 _scale = new OMV.Vector3(1f, 1f, 1f); 1283 _scale = new OMV.Vector3(1f, 1f, 1f);
@@ -1354,10 +1317,10 @@ public sealed class BSPrim : BSPhysObject
1354 ShapeData shape; 1317 ShapeData shape;
1355 FillShapeInfo(out shape); 1318 FillShapeInfo(out shape);
1356 // m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, _localID, shape.Type); 1319 // m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, _localID, shape.Type);
1357 bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape); 1320 bool ret = BulletSimAPI.CreateObject(PhysicsScene.WorldID, shape);
1358 1321
1359 // the CreateObject() may have recreated the rigid body. Make sure we have the latest address. 1322 // the CreateObject() may have recreated the rigid body. Make sure we have the latest address.
1360 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); 1323 BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(PhysicsScene.World.Ptr, LocalID));
1361 BSShape = new BulletShape(BulletSimAPI.GetCollisionShape2(BSBody.Ptr)); 1324 BSShape = new BulletShape(BulletSimAPI.GetCollisionShape2(BSBody.Ptr));
1362 1325
1363 return ret; 1326 return ret;
@@ -1490,61 +1453,10 @@ public sealed class BSPrim : BSPhysObject
1490 } 1453 }
1491 */ 1454 */
1492 } 1455 }
1493
1494 // I've collided with something
1495 // Called at taint time from within the Step() function
1496 CollisionEventUpdate collisionCollection;
1497 public override bool Collide(uint collidingWith, BSPhysObject collidee, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
1498 {
1499 bool ret = false;
1500
1501 // The following lines make IsColliding() and IsCollidingGround() work
1502 _collidingStep = Scene.SimulationStep;
1503 if (collidingWith <= Scene.TerrainManager.HighestTerrainID)
1504 {
1505 _collidingGroundStep = Scene.SimulationStep;
1506 }
1507
1508 // DetailLog("{0},BSPrim.Collison,call,with={1}", LocalID, collidingWith);
1509
1510 // prims in the same linkset cannot collide with each other
1511 if (collidee != null && (this.Linkset.LinksetID == collidee.Linkset.LinksetID))
1512 {
1513 return ret;
1514 }
1515
1516 // if someone has subscribed for collision events....
1517 if (SubscribedEvents()) {
1518 // throttle the collisions to the number of milliseconds specified in the subscription
1519 int nowTime = Scene.SimulationNowTime;
1520 if (nowTime >= _nextCollisionOkTime) {
1521 _nextCollisionOkTime = nowTime + _subscribedEventsMs;
1522
1523 if (collisionCollection == null)
1524 collisionCollection = new CollisionEventUpdate();
1525 collisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
1526 ret = true;
1527 }
1528 }
1529 return ret;
1530 }
1531
1532 // The scene is telling us it's time to pass our collected collisions into the simulator
1533 public override void SendCollisions()
1534 {
1535 if (collisionCollection != null && collisionCollection.Count > 0)
1536 {
1537 base.SendCollisionUpdate(collisionCollection);
1538 // The collisionCollection structure is passed around in the simulator.
1539 // Make sure we don't have a handle to that one and that a new one is used next time.
1540 collisionCollection = null;
1541 }
1542 }
1543
1544 // Invoke the detailed logger and output something if it's enabled. 1456 // Invoke the detailed logger and output something if it's enabled.
1545 private void DetailLog(string msg, params Object[] args) 1457 private void DetailLog(string msg, params Object[] args)
1546 { 1458 {
1547 Scene.PhysicsLogging.Write(msg, args); 1459 PhysicsScene.PhysicsLogging.Write(msg, args);
1548 } 1460 }
1549} 1461}
1550} 1462}