aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs74
1 files changed, 34 insertions, 40 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index f047176..e796804 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -38,7 +38,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
38 * Class to wrap all objects. 38 * Class to wrap all objects.
39 * The rest of BulletSim doesn't need to keep checking for avatars or prims 39 * The rest of BulletSim doesn't need to keep checking for avatars or prims
40 * unless the difference is significant. 40 * unless the difference is significant.
41 * 41 *
42 * Variables in the physicsl objects are in three forms: 42 * Variables in the physicsl objects are in three forms:
43 * VariableName: used by the simulator and performs taint operations, etc 43 * VariableName: used by the simulator and performs taint operations, etc
44 * RawVariableName: direct reference to the BulletSim storage for the variable value 44 * RawVariableName: direct reference to the BulletSim storage for the variable value
@@ -52,7 +52,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
52 * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce 52 * SOP.ApplyImpulse SOP.ApplyAngularImpulse SOP.SetAngularImpulse SOP.SetForce
53 * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse 53 * SOG.ApplyImpulse SOG.ApplyAngularImpulse SOG.SetAngularImpulse
54 * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v 54 * PA.AddForce PA.AddAngularForce PA.Torque = v PA.Force = v
55 * BS.ApplyCentralForce BS.ApplyTorque 55 * BS.ApplyCentralForce BS.ApplyTorque
56 */ 56 */
57 57
58// Flags used to denote which properties updates when making UpdateProperties calls to linksets, etc. 58// Flags used to denote which properties updates when making UpdateProperties calls to linksets, etc.
@@ -72,14 +72,14 @@ public abstract class BSPhysObject : PhysicsActor
72 } 72 }
73 protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName) 73 protected BSPhysObject(BSScene parentScene, uint localID, string name, string typeName)
74 { 74 {
75 PhysicsScene = parentScene; 75 PhysScene = parentScene;
76 LocalID = localID; 76 LocalID = localID;
77 PhysObjectName = name; 77 PhysObjectName = name;
78 Name = name; // PhysicsActor also has the name of the object. Someday consolidate. 78 Name = name; // PhysicsActor also has the name of the object. Someday consolidate.
79 TypeName = typeName; 79 TypeName = typeName;
80 80
81 // The collection of things that push me around 81 // The collection of things that push me around
82 PhysicalActors = new BSActorCollection(PhysicsScene); 82 PhysicalActors = new BSActorCollection(PhysScene);
83 83
84 // Initialize variables kept in base. 84 // Initialize variables kept in base.
85 GravModifier = 1.0f; 85 GravModifier = 1.0f;
@@ -88,7 +88,7 @@ public abstract class BSPhysObject : PhysicsActor
88 88
89 // We don't have any physical representation yet. 89 // We don't have any physical representation yet.
90 PhysBody = new BulletBody(localID); 90 PhysBody = new BulletBody(localID);
91 PhysShape = new BulletShape(); 91 PhysShape = new BSShapeNull();
92 92
93 PrimAssetState = PrimAssetCondition.Unknown; 93 PrimAssetState = PrimAssetCondition.Unknown;
94 94
@@ -115,13 +115,13 @@ public abstract class BSPhysObject : PhysicsActor
115 public virtual void Destroy() 115 public virtual void Destroy()
116 { 116 {
117 PhysicalActors.Enable(false); 117 PhysicalActors.Enable(false);
118 PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate() 118 PhysScene.TaintedObject("BSPhysObject.Destroy", delegate()
119 { 119 {
120 PhysicalActors.Dispose(); 120 PhysicalActors.Dispose();
121 }); 121 });
122 } 122 }
123 123
124 public BSScene PhysicsScene { get; protected set; } 124 public BSScene PhysScene { get; protected set; }
125 // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor 125 // public override uint LocalID { get; set; } // Use the LocalID definition in PhysicsActor
126 public string PhysObjectName { get; protected set; } 126 public string PhysObjectName { get; protected set; }
127 public string TypeName { get; protected set; } 127 public string TypeName { get; protected set; }
@@ -141,7 +141,7 @@ public abstract class BSPhysObject : PhysicsActor
141 // Reference to the physical body (btCollisionObject) of this object 141 // Reference to the physical body (btCollisionObject) of this object
142 public BulletBody PhysBody; 142 public BulletBody PhysBody;
143 // Reference to the physical shape (btCollisionShape) of this object 143 // Reference to the physical shape (btCollisionShape) of this object
144 public BulletShape PhysShape; 144 public BSShape PhysShape;
145 145
146 // The physical representation of the prim might require an asset fetch. 146 // The physical representation of the prim might require an asset fetch.
147 // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'. 147 // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'.
@@ -154,13 +154,6 @@ public abstract class BSPhysObject : PhysicsActor
154 // The objects base shape information. Null if not a prim type shape. 154 // The objects base shape information. Null if not a prim type shape.
155 public PrimitiveBaseShape BaseShape { get; protected set; } 155 public PrimitiveBaseShape BaseShape { get; protected set; }
156 156
157 // Some types of objects have preferred physical representations.
158 // Returns SHAPE_UNKNOWN if there is no preference.
159 public virtual BSPhysicsShapeType PreferredPhysicalShape
160 {
161 get { return BSPhysicsShapeType.SHAPE_UNKNOWN; }
162 }
163
164 // When the physical properties are updated, an EntityProperty holds the update values. 157 // When the physical properties are updated, an EntityProperty holds the update values.
165 // Keep the current and last EntityProperties to enable computation of differences 158 // Keep the current and last EntityProperties to enable computation of differences
166 // between the current update and the previous values. 159 // between the current update and the previous values.
@@ -269,7 +262,8 @@ public abstract class BSPhysObject : PhysicsActor
269 262
270 // The user can optionally set the center of mass. The user's setting will override any 263 // The user can optionally set the center of mass. The user's setting will override any
271 // computed center-of-mass (like in linksets). 264 // computed center-of-mass (like in linksets).
272 public OMV.Vector3? UserSetCenterOfMass { get; set; } 265 // Note this is a displacement from the root's coordinates. Zero means use the root prim as center-of-mass.
266 public OMV.Vector3? UserSetCenterOfMassDisplacement { get; set; }
273 267
274 public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free. 268 public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free.
275 public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free 269 public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free
@@ -280,7 +274,7 @@ public abstract class BSPhysObject : PhysicsActor
280 public void ActivateIfPhysical(bool forceIt) 274 public void ActivateIfPhysical(bool forceIt)
281 { 275 {
282 if (IsPhysical && PhysBody.HasPhysicalBody) 276 if (IsPhysical && PhysBody.HasPhysicalBody)
283 PhysicsScene.PE.Activate(PhysBody, forceIt); 277 PhysScene.PE.Activate(PhysBody, forceIt);
284 } 278 }
285 279
286 // 'actors' act on the physical object to change or constrain its motion. These can range from 280 // 'actors' act on the physical object to change or constrain its motion. These can range from
@@ -343,29 +337,29 @@ public abstract class BSPhysObject : PhysicsActor
343 protected long CollisionAccumulation { get; set; } 337 protected long CollisionAccumulation { get; set; }
344 338
345 public override bool IsColliding { 339 public override bool IsColliding {
346 get { return (CollidingStep == PhysicsScene.SimulationStep); } 340 get { return (CollidingStep == PhysScene.SimulationStep); }
347 set { 341 set {
348 if (value) 342 if (value)
349 CollidingStep = PhysicsScene.SimulationStep; 343 CollidingStep = PhysScene.SimulationStep;
350 else 344 else
351 CollidingStep = 0; 345 CollidingStep = 0;
352 } 346 }
353 } 347 }
354 public override bool CollidingGround { 348 public override bool CollidingGround {
355 get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } 349 get { return (CollidingGroundStep == PhysScene.SimulationStep); }
356 set 350 set
357 { 351 {
358 if (value) 352 if (value)
359 CollidingGroundStep = PhysicsScene.SimulationStep; 353 CollidingGroundStep = PhysScene.SimulationStep;
360 else 354 else
361 CollidingGroundStep = 0; 355 CollidingGroundStep = 0;
362 } 356 }
363 } 357 }
364 public override bool CollidingObj { 358 public override bool CollidingObj {
365 get { return (CollidingObjectStep == PhysicsScene.SimulationStep); } 359 get { return (CollidingObjectStep == PhysScene.SimulationStep); }
366 set { 360 set {
367 if (value) 361 if (value)
368 CollidingObjectStep = PhysicsScene.SimulationStep; 362 CollidingObjectStep = PhysScene.SimulationStep;
369 else 363 else
370 CollidingObjectStep = 0; 364 CollidingObjectStep = 0;
371 } 365 }
@@ -390,14 +384,14 @@ public abstract class BSPhysObject : PhysicsActor
390 bool ret = false; 384 bool ret = false;
391 385
392 // The following lines make IsColliding(), CollidingGround() and CollidingObj work 386 // The following lines make IsColliding(), CollidingGround() and CollidingObj work
393 CollidingStep = PhysicsScene.SimulationStep; 387 CollidingStep = PhysScene.SimulationStep;
394 if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) 388 if (collidingWith <= PhysScene.TerrainManager.HighestTerrainID)
395 { 389 {
396 CollidingGroundStep = PhysicsScene.SimulationStep; 390 CollidingGroundStep = PhysScene.SimulationStep;
397 } 391 }
398 else 392 else
399 { 393 {
400 CollidingObjectStep = PhysicsScene.SimulationStep; 394 CollidingObjectStep = PhysScene.SimulationStep;
401 } 395 }
402 396
403 CollisionAccumulation++; 397 CollisionAccumulation++;
@@ -407,10 +401,10 @@ public abstract class BSPhysObject : PhysicsActor
407 401
408 // Make a collection of the collisions that happened the last simulation tick. 402 // Make a collection of the collisions that happened the last simulation tick.
409 // This is different than the collection created for sending up to the simulator as it is cleared every tick. 403 // This is different than the collection created for sending up to the simulator as it is cleared every tick.
410 if (CollisionsLastTickStep != PhysicsScene.SimulationStep) 404 if (CollisionsLastTickStep != PhysScene.SimulationStep)
411 { 405 {
412 CollisionsLastTick = new CollisionEventUpdate(); 406 CollisionsLastTick = new CollisionEventUpdate();
413 CollisionsLastTickStep = PhysicsScene.SimulationStep; 407 CollisionsLastTickStep = PhysScene.SimulationStep;
414 } 408 }
415 CollisionsLastTick.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); 409 CollisionsLastTick.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
416 410
@@ -437,9 +431,9 @@ public abstract class BSPhysObject : PhysicsActor
437 bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); 431 bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0);
438 432
439 // throttle the collisions to the number of milliseconds specified in the subscription 433 // throttle the collisions to the number of milliseconds specified in the subscription
440 if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime)) 434 if (force || (PhysScene.SimulationNowTime >= NextCollisionOkTime))
441 { 435 {
442 NextCollisionOkTime = PhysicsScene.SimulationNowTime + SubscribedEventsMs; 436 NextCollisionOkTime = PhysScene.SimulationNowTime + SubscribedEventsMs;
443 437
444 // We are called if we previously had collisions. If there are no collisions 438 // We are called if we previously had collisions. If there are no collisions
445 // this time, send up one last empty event so OpenSim can sense collision end. 439 // this time, send up one last empty event so OpenSim can sense collision end.
@@ -457,7 +451,7 @@ public abstract class BSPhysObject : PhysicsActor
457 451
458 // The CollisionCollection instance is passed around in the simulator. 452 // The CollisionCollection instance is passed around in the simulator.
459 // Make sure we don't have a handle to that one and that a new one is used for next time. 453 // Make sure we don't have a handle to that one and that a new one is used for next time.
460 // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here, 454 // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here,
461 // a race condition is created for the other users of this instance. 455 // a race condition is created for the other users of this instance.
462 CollisionCollection = new CollisionEventUpdate(); 456 CollisionCollection = new CollisionEventUpdate();
463 } 457 }
@@ -474,10 +468,10 @@ public abstract class BSPhysObject : PhysicsActor
474 // make sure first collision happens 468 // make sure first collision happens
475 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs); 469 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs);
476 470
477 PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() 471 PhysScene.TaintedObject(TypeName+".SubscribeEvents", delegate()
478 { 472 {
479 if (PhysBody.HasPhysicalBody) 473 if (PhysBody.HasPhysicalBody)
480 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 474 CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
481 }); 475 });
482 } 476 }
483 else 477 else
@@ -489,11 +483,11 @@ public abstract class BSPhysObject : PhysicsActor
489 public override void UnSubscribeEvents() { 483 public override void UnSubscribeEvents() {
490 // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); 484 // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName);
491 SubscribedEventsMs = 0; 485 SubscribedEventsMs = 0;
492 PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() 486 PhysScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate()
493 { 487 {
494 // Make sure there is a body there because sometimes destruction happens in an un-ideal order. 488 // Make sure there is a body there because sometimes destruction happens in an un-ideal order.
495 if (PhysBody.HasPhysicalBody) 489 if (PhysBody.HasPhysicalBody)
496 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 490 CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
497 }); 491 });
498 } 492 }
499 // Return 'true' if the simulator wants collision events 493 // Return 'true' if the simulator wants collision events
@@ -507,7 +501,7 @@ public abstract class BSPhysObject : PhysicsActor
507 { 501 {
508 // Scale the collision count by the time since the last collision. 502 // Scale the collision count by the time since the last collision.
509 // The "+1" prevents dividing by zero. 503 // The "+1" prevents dividing by zero.
510 long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; 504 long timeAgo = PhysScene.SimulationStep - CollidingStep + 1;
511 CollisionScore = CollisionAccumulation / timeAgo; 505 CollisionScore = CollisionAccumulation / timeAgo;
512 } 506 }
513 public override float CollisionScore { get; set; } 507 public override float CollisionScore { get; set; }
@@ -534,8 +528,8 @@ public abstract class BSPhysObject : PhysicsActor
534 // High performance detailed logging routine used by the physical objects. 528 // High performance detailed logging routine used by the physical objects.
535 protected void DetailLog(string msg, params Object[] args) 529 protected void DetailLog(string msg, params Object[] args)
536 { 530 {
537 if (PhysicsScene.PhysicsLogging.Enabled) 531 if (PhysScene.PhysicsLogging.Enabled)
538 PhysicsScene.DetailLog(msg, args); 532 PhysScene.DetailLog(msg, args);
539 } 533 }
540 534
541} 535}