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.cs77
1 files changed, 37 insertions, 40 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 309d004..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
@@ -97,6 +97,9 @@ public abstract class BSPhysObject : PhysicsActor
97 97
98 CollisionCollection = new CollisionEventUpdate(); 98 CollisionCollection = new CollisionEventUpdate();
99 CollisionsLastReported = CollisionCollection; 99 CollisionsLastReported = CollisionCollection;
100 CollisionsLastTick = new CollisionEventUpdate();
101 CollisionsLastTickStep = -1;
102
100 SubscribedEventsMs = 0; 103 SubscribedEventsMs = 0;
101 CollidingStep = 0; 104 CollidingStep = 0;
102 CollidingGroundStep = 0; 105 CollidingGroundStep = 0;
@@ -112,13 +115,13 @@ public abstract class BSPhysObject : PhysicsActor
112 public virtual void Destroy() 115 public virtual void Destroy()
113 { 116 {
114 PhysicalActors.Enable(false); 117 PhysicalActors.Enable(false);
115 PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate() 118 PhysScene.TaintedObject("BSPhysObject.Destroy", delegate()
116 { 119 {
117 PhysicalActors.Dispose(); 120 PhysicalActors.Dispose();
118 }); 121 });
119 } 122 }
120 123
121 public BSScene PhysicsScene { get; protected set; } 124 public BSScene PhysScene { get; protected set; }
122 // 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
123 public string PhysObjectName { get; protected set; } 126 public string PhysObjectName { get; protected set; }
124 public string TypeName { get; protected set; } 127 public string TypeName { get; protected set; }
@@ -138,7 +141,7 @@ public abstract class BSPhysObject : PhysicsActor
138 // Reference to the physical body (btCollisionObject) of this object 141 // Reference to the physical body (btCollisionObject) of this object
139 public BulletBody PhysBody; 142 public BulletBody PhysBody;
140 // Reference to the physical shape (btCollisionShape) of this object 143 // Reference to the physical shape (btCollisionShape) of this object
141 public BulletShape PhysShape; 144 public BSShape PhysShape;
142 145
143 // The physical representation of the prim might require an asset fetch. 146 // The physical representation of the prim might require an asset fetch.
144 // 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'.
@@ -151,13 +154,6 @@ public abstract class BSPhysObject : PhysicsActor
151 // 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.
152 public PrimitiveBaseShape BaseShape { get; protected set; } 155 public PrimitiveBaseShape BaseShape { get; protected set; }
153 156
154 // Some types of objects have preferred physical representations.
155 // Returns SHAPE_UNKNOWN if there is no preference.
156 public virtual BSPhysicsShapeType PreferredPhysicalShape
157 {
158 get { return BSPhysicsShapeType.SHAPE_UNKNOWN; }
159 }
160
161 // 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.
162 // Keep the current and last EntityProperties to enable computation of differences 158 // Keep the current and last EntityProperties to enable computation of differences
163 // between the current update and the previous values. 159 // between the current update and the previous values.
@@ -266,7 +262,8 @@ public abstract class BSPhysObject : PhysicsActor
266 262
267 // 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
268 // computed center-of-mass (like in linksets). 264 // computed center-of-mass (like in linksets).
269 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; }
270 267
271 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.
272 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
@@ -277,7 +274,7 @@ public abstract class BSPhysObject : PhysicsActor
277 public void ActivateIfPhysical(bool forceIt) 274 public void ActivateIfPhysical(bool forceIt)
278 { 275 {
279 if (IsPhysical && PhysBody.HasPhysicalBody) 276 if (IsPhysical && PhysBody.HasPhysicalBody)
280 PhysicsScene.PE.Activate(PhysBody, forceIt); 277 PhysScene.PE.Activate(PhysBody, forceIt);
281 } 278 }
282 279
283 // '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
@@ -340,29 +337,29 @@ public abstract class BSPhysObject : PhysicsActor
340 protected long CollisionAccumulation { get; set; } 337 protected long CollisionAccumulation { get; set; }
341 338
342 public override bool IsColliding { 339 public override bool IsColliding {
343 get { return (CollidingStep == PhysicsScene.SimulationStep); } 340 get { return (CollidingStep == PhysScene.SimulationStep); }
344 set { 341 set {
345 if (value) 342 if (value)
346 CollidingStep = PhysicsScene.SimulationStep; 343 CollidingStep = PhysScene.SimulationStep;
347 else 344 else
348 CollidingStep = 0; 345 CollidingStep = 0;
349 } 346 }
350 } 347 }
351 public override bool CollidingGround { 348 public override bool CollidingGround {
352 get { return (CollidingGroundStep == PhysicsScene.SimulationStep); } 349 get { return (CollidingGroundStep == PhysScene.SimulationStep); }
353 set 350 set
354 { 351 {
355 if (value) 352 if (value)
356 CollidingGroundStep = PhysicsScene.SimulationStep; 353 CollidingGroundStep = PhysScene.SimulationStep;
357 else 354 else
358 CollidingGroundStep = 0; 355 CollidingGroundStep = 0;
359 } 356 }
360 } 357 }
361 public override bool CollidingObj { 358 public override bool CollidingObj {
362 get { return (CollidingObjectStep == PhysicsScene.SimulationStep); } 359 get { return (CollidingObjectStep == PhysScene.SimulationStep); }
363 set { 360 set {
364 if (value) 361 if (value)
365 CollidingObjectStep = PhysicsScene.SimulationStep; 362 CollidingObjectStep = PhysScene.SimulationStep;
366 else 363 else
367 CollidingObjectStep = 0; 364 CollidingObjectStep = 0;
368 } 365 }
@@ -387,14 +384,14 @@ public abstract class BSPhysObject : PhysicsActor
387 bool ret = false; 384 bool ret = false;
388 385
389 // The following lines make IsColliding(), CollidingGround() and CollidingObj work 386 // The following lines make IsColliding(), CollidingGround() and CollidingObj work
390 CollidingStep = PhysicsScene.SimulationStep; 387 CollidingStep = PhysScene.SimulationStep;
391 if (collidingWith <= PhysicsScene.TerrainManager.HighestTerrainID) 388 if (collidingWith <= PhysScene.TerrainManager.HighestTerrainID)
392 { 389 {
393 CollidingGroundStep = PhysicsScene.SimulationStep; 390 CollidingGroundStep = PhysScene.SimulationStep;
394 } 391 }
395 else 392 else
396 { 393 {
397 CollidingObjectStep = PhysicsScene.SimulationStep; 394 CollidingObjectStep = PhysScene.SimulationStep;
398 } 395 }
399 396
400 CollisionAccumulation++; 397 CollisionAccumulation++;
@@ -404,10 +401,10 @@ public abstract class BSPhysObject : PhysicsActor
404 401
405 // 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.
406 // 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.
407 if (CollisionsLastTickStep != PhysicsScene.SimulationStep) 404 if (CollisionsLastTickStep != PhysScene.SimulationStep)
408 { 405 {
409 CollisionsLastTick = new CollisionEventUpdate(); 406 CollisionsLastTick = new CollisionEventUpdate();
410 CollisionsLastTickStep = PhysicsScene.SimulationStep; 407 CollisionsLastTickStep = PhysScene.SimulationStep;
411 } 408 }
412 CollisionsLastTick.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); 409 CollisionsLastTick.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
413 410
@@ -434,9 +431,9 @@ public abstract class BSPhysObject : PhysicsActor
434 bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); 431 bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0);
435 432
436 // 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
437 if (force || (PhysicsScene.SimulationNowTime >= NextCollisionOkTime)) 434 if (force || (PhysScene.SimulationNowTime >= NextCollisionOkTime))
438 { 435 {
439 NextCollisionOkTime = PhysicsScene.SimulationNowTime + SubscribedEventsMs; 436 NextCollisionOkTime = PhysScene.SimulationNowTime + SubscribedEventsMs;
440 437
441 // 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
442 // 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.
@@ -454,7 +451,7 @@ public abstract class BSPhysObject : PhysicsActor
454 451
455 // The CollisionCollection instance is passed around in the simulator. 452 // The CollisionCollection instance is passed around in the simulator.
456 // 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.
457 // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here, 454 // This fixes an interesting 'gotcha'. If we call CollisionCollection.Clear() here,
458 // 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.
459 CollisionCollection = new CollisionEventUpdate(); 456 CollisionCollection = new CollisionEventUpdate();
460 } 457 }
@@ -471,10 +468,10 @@ public abstract class BSPhysObject : PhysicsActor
471 // make sure first collision happens 468 // make sure first collision happens
472 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs); 469 NextCollisionOkTime = Util.EnvironmentTickCountSubtract(SubscribedEventsMs);
473 470
474 PhysicsScene.TaintedObject(TypeName+".SubscribeEvents", delegate() 471 PhysScene.TaintedObject(TypeName+".SubscribeEvents", delegate()
475 { 472 {
476 if (PhysBody.HasPhysicalBody) 473 if (PhysBody.HasPhysicalBody)
477 CurrentCollisionFlags = PhysicsScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 474 CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
478 }); 475 });
479 } 476 }
480 else 477 else
@@ -486,11 +483,11 @@ public abstract class BSPhysObject : PhysicsActor
486 public override void UnSubscribeEvents() { 483 public override void UnSubscribeEvents() {
487 // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); 484 // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName);
488 SubscribedEventsMs = 0; 485 SubscribedEventsMs = 0;
489 PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() 486 PhysScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate()
490 { 487 {
491 // 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.
492 if (PhysBody.HasPhysicalBody) 489 if (PhysBody.HasPhysicalBody)
493 CurrentCollisionFlags = PhysicsScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); 490 CurrentCollisionFlags = PhysScene.PE.RemoveFromCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS);
494 }); 491 });
495 } 492 }
496 // Return 'true' if the simulator wants collision events 493 // Return 'true' if the simulator wants collision events
@@ -504,7 +501,7 @@ public abstract class BSPhysObject : PhysicsActor
504 { 501 {
505 // Scale the collision count by the time since the last collision. 502 // Scale the collision count by the time since the last collision.
506 // The "+1" prevents dividing by zero. 503 // The "+1" prevents dividing by zero.
507 long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; 504 long timeAgo = PhysScene.SimulationStep - CollidingStep + 1;
508 CollisionScore = CollisionAccumulation / timeAgo; 505 CollisionScore = CollisionAccumulation / timeAgo;
509 } 506 }
510 public override float CollisionScore { get; set; } 507 public override float CollisionScore { get; set; }
@@ -531,8 +528,8 @@ public abstract class BSPhysObject : PhysicsActor
531 // High performance detailed logging routine used by the physical objects. 528 // High performance detailed logging routine used by the physical objects.
532 protected void DetailLog(string msg, params Object[] args) 529 protected void DetailLog(string msg, params Object[] args)
533 { 530 {
534 if (PhysicsScene.PhysicsLogging.Enabled) 531 if (PhysScene.PhysicsLogging.Enabled)
535 PhysicsScene.DetailLog(msg, args); 532 PhysScene.DetailLog(msg, args);
536 } 533 }
537 534
538} 535}