diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 97 |
1 files changed, 80 insertions, 17 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index de69fa0..f953c1e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -99,6 +99,9 @@ public abstract class BSPhysObject : PhysicsActor | |||
99 | CollisionAccumulation = 0; | 99 | CollisionAccumulation = 0; |
100 | ColliderIsMoving = false; | 100 | ColliderIsMoving = false; |
101 | CollisionScore = 0; | 101 | CollisionScore = 0; |
102 | |||
103 | // All axis free. | ||
104 | LockedAxis = LockedAxisFree; | ||
102 | } | 105 | } |
103 | 106 | ||
104 | // Tell the object to clean up. | 107 | // Tell the object to clean up. |
@@ -136,6 +139,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
136 | 139 | ||
137 | // The objects base shape information. Null if not a prim type shape. | 140 | // The objects base shape information. Null if not a prim type shape. |
138 | public PrimitiveBaseShape BaseShape { get; protected set; } | 141 | public PrimitiveBaseShape BaseShape { get; protected set; } |
142 | |||
139 | // Some types of objects have preferred physical representations. | 143 | // Some types of objects have preferred physical representations. |
140 | // Returns SHAPE_UNKNOWN if there is no preference. | 144 | // Returns SHAPE_UNKNOWN if there is no preference. |
141 | public virtual BSPhysicsShapeType PreferredPhysicalShape | 145 | public virtual BSPhysicsShapeType PreferredPhysicalShape |
@@ -150,15 +154,17 @@ public abstract class BSPhysObject : PhysicsActor | |||
150 | public EntityProperties LastEntityProperties { get; set; } | 154 | public EntityProperties LastEntityProperties { get; set; } |
151 | 155 | ||
152 | public virtual OMV.Vector3 Scale { get; set; } | 156 | public virtual OMV.Vector3 Scale { get; set; } |
153 | public abstract bool IsSolid { get; } | ||
154 | public abstract bool IsStatic { get; } | ||
155 | public abstract bool IsSelected { get; } | ||
156 | 157 | ||
157 | // It can be confusing for an actor to know if it should move or update an object | 158 | // It can be confusing for an actor to know if it should move or update an object |
158 | // depeneding on the setting of 'selected', 'physical, ... | 159 | // depeneding on the setting of 'selected', 'physical, ... |
159 | // This flag is the true test -- if true, the object is being acted on in the physical world | 160 | // This flag is the true test -- if true, the object is being acted on in the physical world |
160 | public abstract bool IsPhysicallyActive { get; } | 161 | public abstract bool IsPhysicallyActive { get; } |
161 | 162 | ||
163 | // Detailed state of the object. | ||
164 | public abstract bool IsSolid { get; } | ||
165 | public abstract bool IsStatic { get; } | ||
166 | public abstract bool IsSelected { get; } | ||
167 | |||
162 | // Materialness | 168 | // Materialness |
163 | public MaterialAttributes.Material Material { get; private set; } | 169 | public MaterialAttributes.Material Material { get; private set; } |
164 | public override void SetMaterial(int material) | 170 | public override void SetMaterial(int material) |
@@ -169,7 +175,8 @@ public abstract class BSPhysObject : PhysicsActor | |||
169 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); | 175 | MaterialAttributes matAttrib = BSMaterials.GetAttributes(Material, false); |
170 | Friction = matAttrib.friction; | 176 | Friction = matAttrib.friction; |
171 | Restitution = matAttrib.restitution; | 177 | Restitution = matAttrib.restitution; |
172 | Density = matAttrib.density; | 178 | Density = matAttrib.density / BSParam.DensityScaleFactor; |
179 | DetailLog("{0},{1}.SetMaterial,Mat={2},frict={3},rest={4},den={5}", LocalID, TypeName, Material, Friction, Restitution, Density); | ||
173 | } | 180 | } |
174 | 181 | ||
175 | // Stop all physical motion. | 182 | // Stop all physical motion. |
@@ -185,14 +192,6 @@ public abstract class BSPhysObject : PhysicsActor | |||
185 | public abstract OMV.Quaternion RawOrientation { get; set; } | 192 | public abstract OMV.Quaternion RawOrientation { get; set; } |
186 | public abstract OMV.Quaternion ForceOrientation { get; set; } | 193 | public abstract OMV.Quaternion ForceOrientation { get; set; } |
187 | 194 | ||
188 | public virtual float TargetSpeed | ||
189 | { | ||
190 | get | ||
191 | { | ||
192 | OMV.Vector3 characterOrientedVelocity = TargetVelocity * OMV.Quaternion.Inverse(OMV.Quaternion.Normalize(RawOrientation)); | ||
193 | return characterOrientedVelocity.X; | ||
194 | } | ||
195 | } | ||
196 | public abstract OMV.Vector3 RawVelocity { get; set; } | 195 | public abstract OMV.Vector3 RawVelocity { get; set; } |
197 | public abstract OMV.Vector3 ForceVelocity { get; set; } | 196 | public abstract OMV.Vector3 ForceVelocity { get; set; } |
198 | 197 | ||
@@ -202,6 +201,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
202 | 201 | ||
203 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } | 202 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } |
204 | 203 | ||
204 | // The current velocity forward | ||
205 | public virtual float ForwardSpeed | 205 | public virtual float ForwardSpeed |
206 | { | 206 | { |
207 | get | 207 | get |
@@ -210,6 +210,22 @@ public abstract class BSPhysObject : PhysicsActor | |||
210 | return characterOrientedVelocity.X; | 210 | return characterOrientedVelocity.X; |
211 | } | 211 | } |
212 | } | 212 | } |
213 | // The forward speed we are trying to achieve (TargetVelocity) | ||
214 | public virtual float TargetVelocitySpeed | ||
215 | { | ||
216 | get | ||
217 | { | ||
218 | OMV.Vector3 characterOrientedVelocity = TargetVelocity * OMV.Quaternion.Inverse(OMV.Quaternion.Normalize(RawOrientation)); | ||
219 | return characterOrientedVelocity.X; | ||
220 | } | ||
221 | } | ||
222 | |||
223 | // The user can optionally set the center of mass. The user's setting will override any | ||
224 | // computed center-of-mass (like in linksets). | ||
225 | public OMV.Vector3? UserSetCenterOfMass { get; set; } | ||
226 | |||
227 | public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free. | ||
228 | public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free | ||
213 | 229 | ||
214 | #region Collisions | 230 | #region Collisions |
215 | 231 | ||
@@ -407,9 +423,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
407 | { | 423 | { |
408 | // Clean out any existing action | 424 | // Clean out any existing action |
409 | UnRegisterPreStepAction(op, id); | 425 | UnRegisterPreStepAction(op, id); |
410 | |||
411 | RegisteredPrestepActions[identifier] = actn; | 426 | RegisteredPrestepActions[identifier] = actn; |
412 | |||
413 | PhysicsScene.BeforeStep += actn; | 427 | PhysicsScene.BeforeStep += actn; |
414 | } | 428 | } |
415 | DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); | 429 | DetailLog("{0},BSPhysObject.RegisterPreStepAction,id={1}", LocalID, identifier); |
@@ -455,9 +469,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
455 | { | 469 | { |
456 | // Clean out any existing action | 470 | // Clean out any existing action |
457 | UnRegisterPostStepAction(op, id); | 471 | UnRegisterPostStepAction(op, id); |
458 | |||
459 | RegisteredPoststepActions[identifier] = actn; | 472 | RegisteredPoststepActions[identifier] = actn; |
460 | |||
461 | PhysicsScene.AfterStep += actn; | 473 | PhysicsScene.AfterStep += actn; |
462 | } | 474 | } |
463 | DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); | 475 | DetailLog("{0},BSPhysObject.RegisterPostStepAction,id={1}", LocalID, identifier); |
@@ -494,7 +506,58 @@ public abstract class BSPhysObject : PhysicsActor | |||
494 | } | 506 | } |
495 | DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID); | 507 | DetailLog("{0},BSPhysObject.UnRegisterAllPostStepActions,", LocalID); |
496 | } | 508 | } |
497 | 509 | ||
510 | // When an update to the physical properties happens, this event is fired to let | ||
511 | // different actors to modify the update before it is passed around | ||
512 | public delegate void PreUpdatePropertyAction(ref EntityProperties entprop); | ||
513 | public event PreUpdatePropertyAction OnPreUpdateProperty; | ||
514 | protected void TriggerPreUpdatePropertyAction(ref EntityProperties entprop) | ||
515 | { | ||
516 | PreUpdatePropertyAction actions = OnPreUpdateProperty; | ||
517 | if (actions != null) | ||
518 | actions(ref entprop); | ||
519 | } | ||
520 | |||
521 | private Dictionary<string, PreUpdatePropertyAction> RegisteredPreUpdatePropertyActions = new Dictionary<string, PreUpdatePropertyAction>(); | ||
522 | public void RegisterPreUpdatePropertyAction(string identifier, PreUpdatePropertyAction actn) | ||
523 | { | ||
524 | lock (RegisteredPreUpdatePropertyActions) | ||
525 | { | ||
526 | // Clean out any existing action | ||
527 | UnRegisterPreUpdatePropertyAction(identifier); | ||
528 | RegisteredPreUpdatePropertyActions[identifier] = actn; | ||
529 | OnPreUpdateProperty += actn; | ||
530 | } | ||
531 | DetailLog("{0},BSPhysObject.RegisterPreUpdatePropertyAction,id={1}", LocalID, identifier); | ||
532 | } | ||
533 | public bool UnRegisterPreUpdatePropertyAction(string identifier) | ||
534 | { | ||
535 | bool removed = false; | ||
536 | lock (RegisteredPreUpdatePropertyActions) | ||
537 | { | ||
538 | if (RegisteredPreUpdatePropertyActions.ContainsKey(identifier)) | ||
539 | { | ||
540 | OnPreUpdateProperty -= RegisteredPreUpdatePropertyActions[identifier]; | ||
541 | RegisteredPreUpdatePropertyActions.Remove(identifier); | ||
542 | removed = true; | ||
543 | } | ||
544 | } | ||
545 | DetailLog("{0},BSPhysObject.UnRegisterPreUpdatePropertyAction,id={1},removed={2}", LocalID, identifier, removed); | ||
546 | return removed; | ||
547 | } | ||
548 | public void UnRegisterAllPreUpdatePropertyActions() | ||
549 | { | ||
550 | lock (RegisteredPreUpdatePropertyActions) | ||
551 | { | ||
552 | foreach (KeyValuePair<string, PreUpdatePropertyAction> kvp in RegisteredPreUpdatePropertyActions) | ||
553 | { | ||
554 | OnPreUpdateProperty -= kvp.Value; | ||
555 | } | ||
556 | RegisteredPreUpdatePropertyActions.Clear(); | ||
557 | } | ||
558 | DetailLog("{0},BSPhysObject.UnRegisterAllPreUpdatePropertyAction,", LocalID); | ||
559 | } | ||
560 | |||
498 | #endregion // Per Simulation Step actions | 561 | #endregion // Per Simulation Step actions |
499 | 562 | ||
500 | // High performance detailed logging routine used by the physical objects. | 563 | // High performance detailed logging routine used by the physical objects. |