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.cs233
1 files changed, 87 insertions, 146 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
index 98ea833..98eb4ca 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs
@@ -43,7 +43,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin
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
45 * ForceVariableName: direct reference (store and fetch) to the value in the physics engine. 45 * ForceVariableName: direct reference (store and fetch) to the value in the physics engine.
46 * The last two (and certainly the last one) should be referenced only in taint-time. 46 * The last one should only be referenced in taint-time.
47 */ 47 */
48 48
49/* 49/*
@@ -84,6 +84,7 @@ public abstract class BSPhysObject : PhysicsActor
84 // Initialize variables kept in base. 84 // Initialize variables kept in base.
85 GravModifier = 1.0f; 85 GravModifier = 1.0f;
86 Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); 86 Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity);
87 HoverActive = false;
87 88
88 // We don't have any physical representation yet. 89 // We don't have any physical representation yet.
89 PhysBody = new BulletBody(localID); 90 PhysBody = new BulletBody(localID);
@@ -110,11 +111,10 @@ public abstract class BSPhysObject : PhysicsActor
110 // Tell the object to clean up. 111 // Tell the object to clean up.
111 public virtual void Destroy() 112 public virtual void Destroy()
112 { 113 {
113 UnRegisterAllPreStepActions(); 114 PhysicalActors.Enable(false);
114 UnRegisterAllPostStepActions();
115 PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate() 115 PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate()
116 { 116 {
117 PhysicalActors.Release(); 117 PhysicalActors.Dispose();
118 }); 118 });
119 } 119 }
120 120
@@ -203,15 +203,48 @@ public abstract class BSPhysObject : PhysicsActor
203 public abstract OMV.Quaternion RawOrientation { get; set; } 203 public abstract OMV.Quaternion RawOrientation { get; set; }
204 public abstract OMV.Quaternion ForceOrientation { get; set; } 204 public abstract OMV.Quaternion ForceOrientation { get; set; }
205 205
206 public abstract OMV.Vector3 RawVelocity { get; set; } 206 public OMV.Vector3 RawVelocity { get; set; }
207 public abstract OMV.Vector3 ForceVelocity { get; set; } 207 public abstract OMV.Vector3 ForceVelocity { get; set; }
208 208
209 public OMV.Vector3 RawForce { get; set; }
210 public OMV.Vector3 RawTorque { get; set; }
211 public override void AddAngularForce(OMV.Vector3 force, bool pushforce)
212 {
213 AddAngularForce(force, pushforce, false);
214 }
215 public abstract void AddAngularForce(OMV.Vector3 force, bool pushforce, bool inTaintTime);
216
209 public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } 217 public abstract OMV.Vector3 ForceRotationalVelocity { get; set; }
210 218
211 public abstract float ForceBuoyancy { get; set; } 219 public abstract float ForceBuoyancy { get; set; }
212 220
213 public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } 221 public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; }
214 222
223 public override bool PIDActive { set { MoveToTargetActive = value; } }
224 public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } }
225 public override float PIDTau { set { MoveToTargetTau = value; } }
226
227 public bool MoveToTargetActive { get; set; }
228 public OMV.Vector3 MoveToTargetTarget { get; set; }
229 public float MoveToTargetTau { get; set; }
230
231 // Used for llSetHoverHeight and maybe vehicle height. Hover Height will override MoveTo target's Z
232 public override bool PIDHoverActive { set { HoverActive = value; } }
233 public override float PIDHoverHeight { set { HoverHeight = value; } }
234 public override PIDHoverType PIDHoverType { set { HoverType = value; } }
235 public override float PIDHoverTau { set { HoverTau = value; } }
236
237 public bool HoverActive { get; set; }
238 public float HoverHeight { get; set; }
239 public PIDHoverType HoverType { get; set; }
240 public float HoverTau { get; set; }
241
242 // For RotLookAt
243 public override OMV.Quaternion APIDTarget { set { return; } }
244 public override bool APIDActive { set { return; } }
245 public override float APIDStrength { set { return; } }
246 public override float APIDDamping { set { return; } }
247
215 // The current velocity forward 248 // The current velocity forward
216 public virtual float ForwardSpeed 249 public virtual float ForwardSpeed
217 { 250 {
@@ -237,7 +270,51 @@ public abstract class BSPhysObject : PhysicsActor
237 270
238 public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free. 271 public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free.
239 public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free 272 public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free
240 public readonly String LockedAxisActorName = "BSPrim.LockedAxis"; 273
274 // Enable physical actions. Bullet will keep sleeping non-moving physical objects so
275 // they need waking up when parameters are changed.
276 // Called in taint-time!!
277 public void ActivateIfPhysical(bool forceIt)
278 {
279 if (IsPhysical && PhysBody.HasPhysicalBody)
280 PhysicsScene.PE.Activate(PhysBody, forceIt);
281 }
282
283 // 'actors' act on the physical object to change or constrain its motion. These can range from
284 // hovering to complex vehicle motion.
285 // May be called at non-taint time as this just adds the actor to the action list and the real
286 // work is done during the simulation step.
287 // Note that, if the actor is already in the list and we are disabling same, the actor is just left
288 // in the list disabled.
289 public delegate BSActor CreateActor();
290 public void EnableActor(bool enableActor, string actorName, CreateActor creator)
291 {
292 lock (PhysicalActors)
293 {
294 BSActor theActor;
295 if (PhysicalActors.TryGetActor(actorName, out theActor))
296 {
297 // The actor already exists so just turn it on or off
298 DetailLog("{0},BSPhysObject.EnableActor,enablingExistingActor,name={1},enable={2}", LocalID, actorName, enableActor);
299 theActor.Enabled = enableActor;
300 }
301 else
302 {
303 // The actor does not exist. If it should, create it.
304 if (enableActor)
305 {
306 DetailLog("{0},BSPhysObject.EnableActor,creatingActor,name={1}", LocalID, actorName);
307 theActor = creator();
308 PhysicalActors.Add(actorName, theActor);
309 theActor.Enabled = true;
310 }
311 else
312 {
313 DetailLog("{0},BSPhysObject.EnableActor,notCreatingActorSinceNotEnabled,name={1}", LocalID, actorName);
314 }
315 }
316 }
317 }
241 318
242 #region Collisions 319 #region Collisions
243 320
@@ -255,7 +332,9 @@ public abstract class BSPhysObject : PhysicsActor
255 protected CollisionFlags CurrentCollisionFlags { get; set; } 332 protected CollisionFlags CurrentCollisionFlags { get; set; }
256 // On a collision, check the collider and remember if the last collider was moving 333 // On a collision, check the collider and remember if the last collider was moving
257 // Used to modify the standing of avatars (avatars on stationary things stand still) 334 // Used to modify the standing of avatars (avatars on stationary things stand still)
258 protected bool ColliderIsMoving; 335 public bool ColliderIsMoving;
336 // Used by BSCharacter to manage standing (and not slipping)
337 public bool IsStationary;
259 338
260 // Count of collisions for this object 339 // Count of collisions for this object
261 protected long CollisionAccumulation { get; set; } 340 protected long CollisionAccumulation { get; set; }
@@ -293,7 +372,7 @@ public abstract class BSPhysObject : PhysicsActor
293 protected CollisionEventUpdate CollisionCollection; 372 protected CollisionEventUpdate CollisionCollection;
294 // Remember collisions from last tick for fancy collision based actions 373 // Remember collisions from last tick for fancy collision based actions
295 // (like a BSCharacter walking up stairs). 374 // (like a BSCharacter walking up stairs).
296 protected CollisionEventUpdate CollisionsLastTick; 375 public CollisionEventUpdate CollisionsLastTick;
297 376
298 // The simulation step is telling this object about a collision. 377 // The simulation step is telling this object about a collision.
299 // Return 'true' if a collision was processed and should be sent up. 378 // Return 'true' if a collision was processed and should be sent up.
@@ -424,104 +503,6 @@ public abstract class BSPhysObject : PhysicsActor
424 503
425 public BSActorCollection PhysicalActors; 504 public BSActorCollection PhysicalActors;
426 505
427 // There are some actions that must be performed for a physical object before each simulation step.
428 // These actions are optional so, rather than scanning all the physical objects and asking them
429 // if they have anything to do, a physical object registers for an event call before the step is performed.
430 // This bookkeeping makes it easy to add, remove and clean up after all these registrations.
431 private Dictionary<string, BSScene.PreStepAction> RegisteredPrestepActions = new Dictionary<string, BSScene.PreStepAction>();
432 private Dictionary<string, BSScene.PostStepAction> RegisteredPoststepActions = new Dictionary<string, BSScene.PostStepAction>();
433 protected void RegisterPreStepAction(string op, uint id, BSScene.PreStepAction actn)
434 {
435 string identifier = op + "-" + id.ToString();
436
437 lock (RegisteredPrestepActions)
438 {
439 // Clean out any existing action
440 UnRegisterPreStepAction(op, id);
441 RegisteredPrestepActions[identifier] = actn;
442 PhysicsScene.BeforeStep += actn;
443 }
444 DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier);
445 }
446
447 // Unregister a pre step action. Safe to call if the action has not been registered.
448 // Returns 'true' if an action was actually removed
449 protected bool UnRegisterPreStepAction(string op, uint id)
450 {
451 string identifier = op + "-" + id.ToString();
452 bool removed = false;
453 lock (RegisteredPrestepActions)
454 {
455 if (RegisteredPrestepActions.ContainsKey(identifier))
456 {
457 PhysicsScene.BeforeStep -= RegisteredPrestepActions[identifier];
458 RegisteredPrestepActions.Remove(identifier);
459 removed = true;
460 }
461 }
462 DetailLog("{0},BSPhysObject.UnRegisterPreStepAction,id={1},removed={2}", LocalID, identifier, removed);
463 return removed;
464 }
465
466 protected void UnRegisterAllPreStepActions()
467 {
468 lock (RegisteredPrestepActions)
469 {
470 foreach (KeyValuePair<string, BSScene.PreStepAction> kvp in RegisteredPrestepActions)
471 {
472 PhysicsScene.BeforeStep -= kvp.Value;
473 }
474 RegisteredPrestepActions.Clear();
475 }
476 DetailLog("{0},BSPhysObject.UnRegisterAllPreStepActions,", LocalID);
477 }
478
479 protected void RegisterPostStepAction(string op, uint id, BSScene.PostStepAction actn)
480 {
481 string identifier = op + "-" + id.ToString();
482
483 lock (RegisteredPoststepActions)
484 {
485 // Clean out any existing action
486 UnRegisterPostStepAction(op, id);
487 RegisteredPoststepActions[identifier] = actn;
488 PhysicsScene.AfterStep += actn;
489 }
490 DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier);
491 }
492
493 // Unregister a pre step action. Safe to call if the action has not been registered.
494 // Returns 'true' if an action was actually removed.
495 protected bool UnRegisterPostStepAction(string op, uint id)
496 {
497 string identifier = op + "-" + id.ToString();
498 bool removed = false;
499 lock (RegisteredPoststepActions)
500 {
501 if (RegisteredPoststepActions.ContainsKey(identifier))
502 {
503 PhysicsScene.AfterStep -= RegisteredPoststepActions[identifier];
504 RegisteredPoststepActions.Remove(identifier);
505 removed = true;
506 }
507 }
508 DetailLog("{0},BSPhysObject.UnRegisterPostStepAction,id={1},removed={2}", LocalID, identifier, removed);
509 return removed;
510 }
511
512 protected void UnRegisterAllPostStepActions()
513 {
514 lock (RegisteredPoststepActions)
515 {
516 foreach (KeyValuePair<string, BSScene.PostStepAction> kvp in RegisteredPoststepActions)
517 {
518 PhysicsScene.AfterStep -= kvp.Value;
519 }
520 RegisteredPoststepActions.Clear();
521 }
522 DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID);
523 }
524
525 // When an update to the physical properties happens, this event is fired to let 506 // When an update to the physical properties happens, this event is fired to let
526 // different actors to modify the update before it is passed around 507 // different actors to modify the update before it is passed around
527 public delegate void PreUpdatePropertyAction(ref EntityProperties entprop); 508 public delegate void PreUpdatePropertyAction(ref EntityProperties entprop);
@@ -533,46 +514,6 @@ public abstract class BSPhysObject : PhysicsActor
533 actions(ref entprop); 514 actions(ref entprop);
534 } 515 }
535 516
536 private Dictionary<string, PreUpdatePropertyAction> RegisteredPreUpdatePropertyActions = new Dictionary<string, PreUpdatePropertyAction>();
537 public void RegisterPreUpdatePropertyAction(string identifier, PreUpdatePropertyAction actn)
538 {
539 lock (RegisteredPreUpdatePropertyActions)
540 {
541 // Clean out any existing action
542 UnRegisterPreUpdatePropertyAction(identifier);
543 RegisteredPreUpdatePropertyActions[identifier] = actn;
544 OnPreUpdateProperty += actn;
545 }
546 DetailLog("{0},BSPhysObject.RegisterPreUpdatePropertyAction,id={1}", LocalID, identifier);
547 }
548 public bool UnRegisterPreUpdatePropertyAction(string identifier)
549 {
550 bool removed = false;
551 lock (RegisteredPreUpdatePropertyActions)
552 {
553 if (RegisteredPreUpdatePropertyActions.ContainsKey(identifier))
554 {
555 OnPreUpdateProperty -= RegisteredPreUpdatePropertyActions[identifier];
556 RegisteredPreUpdatePropertyActions.Remove(identifier);
557 removed = true;
558 }
559 }
560 DetailLog("{0},BSPhysObject.UnRegisterPreUpdatePropertyAction,id={1},removed={2}", LocalID, identifier, removed);
561 return removed;
562 }
563 public void UnRegisterAllPreUpdatePropertyActions()
564 {
565 lock (RegisteredPreUpdatePropertyActions)
566 {
567 foreach (KeyValuePair<string, PreUpdatePropertyAction> kvp in RegisteredPreUpdatePropertyActions)
568 {
569 OnPreUpdateProperty -= kvp.Value;
570 }
571 RegisteredPreUpdatePropertyActions.Clear();
572 }
573 DetailLog("{0},BSPhysObject.UnRegisterAllPreUpdatePropertyAction,", LocalID);
574 }
575
576 #endregion // Per Simulation Step actions 517 #endregion // Per Simulation Step actions
577 518
578 // High performance detailed logging routine used by the physical objects. 519 // High performance detailed logging routine used by the physical objects.