diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 146 |
1 files changed, 72 insertions, 74 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 79fe632..f80084a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -132,8 +132,8 @@ public sealed class BSPrim : BSPhysObject | |||
132 | base.Destroy(); | 132 | base.Destroy(); |
133 | 133 | ||
134 | // Undo any links between me and any other object | 134 | // Undo any links between me and any other object |
135 | BSPhysObject parentBefore = Linkset.LinksetRoot; | 135 | BSPhysObject parentBefore = Linkset.LinksetRoot; // DEBUG DEBUG |
136 | int childrenBefore = Linkset.NumberOfChildren; | 136 | int childrenBefore = Linkset.NumberOfChildren; // DEBUG DEBUG |
137 | 137 | ||
138 | Linkset = Linkset.RemoveMeFromLinkset(this); | 138 | Linkset = Linkset.RemoveMeFromLinkset(this); |
139 | 139 | ||
@@ -311,16 +311,18 @@ public sealed class BSPrim : BSPhysObject | |||
311 | _position = value; | 311 | _position = value; |
312 | PositionSanityCheck(false); | 312 | PositionSanityCheck(false); |
313 | 313 | ||
314 | // A linkset might need to know if a component information changed. | ||
315 | Linkset.UpdateProperties(this, false); | ||
316 | |||
317 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() | 314 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() |
318 | { | 315 | { |
319 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 316 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
320 | ForcePosition = _position; | 317 | ForcePosition = _position; |
318 | |||
319 | // A linkset might need to know if a component information changed. | ||
320 | Linkset.UpdateProperties(UpdatedProperties.Position, this); | ||
321 | |||
321 | }); | 322 | }); |
322 | } | 323 | } |
323 | } | 324 | } |
325 | |||
324 | public override OMV.Vector3 ForcePosition { | 326 | public override OMV.Vector3 ForcePosition { |
325 | get { | 327 | get { |
326 | _position = PhysicsScene.PE.GetPosition(PhysBody) - PositionDisplacement; | 328 | _position = PhysicsScene.PE.GetPosition(PhysBody) - PositionDisplacement; |
@@ -335,25 +337,6 @@ public sealed class BSPrim : BSPhysObject | |||
335 | } | 337 | } |
336 | } | 338 | } |
337 | } | 339 | } |
338 | // Override to have position displacement immediately update the physical position. | ||
339 | // A feeble attempt to keep the sim and physical positions in sync | ||
340 | // Must be called at taint time. | ||
341 | public override OMV.Vector3 PositionDisplacement | ||
342 | { | ||
343 | get | ||
344 | { | ||
345 | return base.PositionDisplacement; | ||
346 | } | ||
347 | set | ||
348 | { | ||
349 | base.PositionDisplacement = value; | ||
350 | PhysicsScene.TaintedObject(PhysicsScene.InTaintTime, "BSPrim.setPosition", delegate() | ||
351 | { | ||
352 | if (PhysBody.HasPhysicalBody) | ||
353 | PhysicsScene.PE.SetTranslation(PhysBody, _position + base.PositionDisplacement, _orientation); | ||
354 | }); | ||
355 | } | ||
356 | } | ||
357 | 340 | ||
358 | // Check that the current position is sane and, if not, modify the position to make it so. | 341 | // Check that the current position is sane and, if not, modify the position to make it so. |
359 | // Check for being below terrain and being out of bounds. | 342 | // Check for being below terrain and being out of bounds. |
@@ -370,11 +353,11 @@ public sealed class BSPrim : BSPhysObject | |||
370 | return ret; | 353 | return ret; |
371 | } | 354 | } |
372 | 355 | ||
373 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); | 356 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); |
374 | OMV.Vector3 upForce = OMV.Vector3.Zero; | 357 | OMV.Vector3 upForce = OMV.Vector3.Zero; |
375 | if (RawPosition.Z < terrainHeight) | 358 | if (RawPosition.Z < terrainHeight) |
376 | { | 359 | { |
377 | DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); | 360 | DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, RawPosition, terrainHeight); |
378 | float targetHeight = terrainHeight + (Size.Z / 2f); | 361 | float targetHeight = terrainHeight + (Size.Z / 2f); |
379 | // If the object is below ground it just has to be moved up because pushing will | 362 | // If the object is below ground it just has to be moved up because pushing will |
380 | // not get it through the terrain | 363 | // not get it through the terrain |
@@ -502,6 +485,12 @@ public sealed class BSPrim : BSPhysObject | |||
502 | RegisterPreStepAction("BSPrim.setForce", LocalID, | 485 | RegisterPreStepAction("BSPrim.setForce", LocalID, |
503 | delegate(float timeStep) | 486 | delegate(float timeStep) |
504 | { | 487 | { |
488 | if (!IsPhysicallyActive) | ||
489 | { | ||
490 | UnRegisterPreStepAction("BSPrim.setForce", LocalID); | ||
491 | return; | ||
492 | } | ||
493 | |||
505 | DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force); | 494 | DetailLog("{0},BSPrim.setForce,preStep,force={1}", LocalID, _force); |
506 | if (PhysBody.HasPhysicalBody) | 495 | if (PhysBody.HasPhysicalBody) |
507 | { | 496 | { |
@@ -627,6 +616,12 @@ public sealed class BSPrim : BSPhysObject | |||
627 | RegisterPreStepAction("BSPrim.setTorque", LocalID, | 616 | RegisterPreStepAction("BSPrim.setTorque", LocalID, |
628 | delegate(float timeStep) | 617 | delegate(float timeStep) |
629 | { | 618 | { |
619 | if (!IsPhysicallyActive) | ||
620 | { | ||
621 | UnRegisterPreStepAction("BSPrim.setTorque", LocalID); | ||
622 | return; | ||
623 | } | ||
624 | |||
630 | if (PhysBody.HasPhysicalBody) | 625 | if (PhysBody.HasPhysicalBody) |
631 | AddAngularForce(_torque, false, true); | 626 | AddAngularForce(_torque, false, true); |
632 | } | 627 | } |
@@ -670,12 +665,13 @@ public sealed class BSPrim : BSPhysObject | |||
670 | return; | 665 | return; |
671 | _orientation = value; | 666 | _orientation = value; |
672 | 667 | ||
673 | // A linkset might need to know if a component information changed. | ||
674 | Linkset.UpdateProperties(this, false); | ||
675 | |||
676 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() | 668 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() |
677 | { | 669 | { |
678 | ForceOrientation = _orientation; | 670 | ForceOrientation = _orientation; |
671 | |||
672 | // A linkset might need to know if a component information changed. | ||
673 | Linkset.UpdateProperties(UpdatedProperties.Orientation, this); | ||
674 | |||
679 | }); | 675 | }); |
680 | } | 676 | } |
681 | } | 677 | } |
@@ -727,6 +723,12 @@ public sealed class BSPrim : BSPhysObject | |||
727 | get { return !IsPhantom && !_isVolumeDetect; } | 723 | get { return !IsPhantom && !_isVolumeDetect; } |
728 | } | 724 | } |
729 | 725 | ||
726 | // The object is moving and is actively being dynamic in the physical world | ||
727 | public override bool IsPhysicallyActive | ||
728 | { | ||
729 | get { return !_isSelected && IsPhysical; } | ||
730 | } | ||
731 | |||
730 | // Make gravity work if the object is physical and not selected | 732 | // Make gravity work if the object is physical and not selected |
731 | // Called at taint-time!! | 733 | // Called at taint-time!! |
732 | private void SetObjectDynamic(bool forceRebuild) | 734 | private void SetObjectDynamic(bool forceRebuild) |
@@ -971,10 +973,10 @@ public sealed class BSPrim : BSPhysObject | |||
971 | } | 973 | } |
972 | set { | 974 | set { |
973 | _rotationalVelocity = value; | 975 | _rotationalVelocity = value; |
976 | Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); | ||
974 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 977 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
975 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() | 978 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() |
976 | { | 979 | { |
977 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | ||
978 | ForceRotationalVelocity = _rotationalVelocity; | 980 | ForceRotationalVelocity = _rotationalVelocity; |
979 | }); | 981 | }); |
980 | } | 982 | } |
@@ -987,7 +989,9 @@ public sealed class BSPrim : BSPhysObject | |||
987 | _rotationalVelocity = value; | 989 | _rotationalVelocity = value; |
988 | if (PhysBody.HasPhysicalBody) | 990 | if (PhysBody.HasPhysicalBody) |
989 | { | 991 | { |
992 | DetailLog("{0},BSPrim.ForceRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | ||
990 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); | 993 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); |
994 | // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | ||
991 | ActivateIfPhysical(false); | 995 | ActivateIfPhysical(false); |
992 | } | 996 | } |
993 | } | 997 | } |
@@ -1055,10 +1059,16 @@ public sealed class BSPrim : BSPhysObject | |||
1055 | 1059 | ||
1056 | RegisterPreStepAction("BSPrim.PIDTarget", LocalID, delegate(float timeStep) | 1060 | RegisterPreStepAction("BSPrim.PIDTarget", LocalID, delegate(float timeStep) |
1057 | { | 1061 | { |
1062 | if (!IsPhysicallyActive) | ||
1063 | { | ||
1064 | UnRegisterPreStepAction("BSPrim.PIDTarget", LocalID); | ||
1065 | return; | ||
1066 | } | ||
1067 | |||
1058 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) | 1068 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) |
1059 | 1069 | ||
1060 | // 'movePosition' is where we'd like the prim to be at this moment. | 1070 | // 'movePosition' is where we'd like the prim to be at this moment. |
1061 | OMV.Vector3 movePosition = _targetMotor.Step(timeStep); | 1071 | OMV.Vector3 movePosition = RawPosition + _targetMotor.Step(timeStep); |
1062 | 1072 | ||
1063 | // If we are very close to our target, turn off the movement motor. | 1073 | // If we are very close to our target, turn off the movement motor. |
1064 | if (_targetMotor.ErrorIsZero()) | 1074 | if (_targetMotor.ErrorIsZero()) |
@@ -1102,6 +1112,9 @@ public sealed class BSPrim : BSPhysObject | |||
1102 | 1112 | ||
1103 | RegisterPreStepAction("BSPrim.Hover", LocalID, delegate(float timeStep) | 1113 | RegisterPreStepAction("BSPrim.Hover", LocalID, delegate(float timeStep) |
1104 | { | 1114 | { |
1115 | if (!IsPhysicallyActive) | ||
1116 | return; | ||
1117 | |||
1105 | _hoverMotor.SetCurrent(RawPosition.Z); | 1118 | _hoverMotor.SetCurrent(RawPosition.Z); |
1106 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); | 1119 | _hoverMotor.SetTarget(ComputeCurrentPIDHoverHeight()); |
1107 | float targetHeight = _hoverMotor.Step(timeStep); | 1120 | float targetHeight = _hoverMotor.Step(timeStep); |
@@ -1166,28 +1179,25 @@ public sealed class BSPrim : BSPhysObject | |||
1166 | public override float APIDDamping { set { return; } } | 1179 | public override float APIDDamping { set { return; } } |
1167 | 1180 | ||
1168 | public override void AddForce(OMV.Vector3 force, bool pushforce) { | 1181 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
1182 | // Per documentation, max force is limited. | ||
1183 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); | ||
1184 | |||
1169 | // Since this force is being applied in only one step, make this a force per second. | 1185 | // Since this force is being applied in only one step, make this a force per second. |
1170 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | 1186 | addForce /= PhysicsScene.LastTimeStep; |
1171 | AddForce(addForce, pushforce, false); | 1187 | AddForce(addForce, pushforce, false /* inTaintTime */); |
1172 | } | 1188 | } |
1189 | |||
1173 | // Applying a force just adds this to the total force on the object. | 1190 | // Applying a force just adds this to the total force on the object. |
1174 | // This added force will only last the next simulation tick. | 1191 | // This added force will only last the next simulation tick. |
1175 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | 1192 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
1176 | // for an object, doesn't matter if force is a pushforce or not | 1193 | // for an object, doesn't matter if force is a pushforce or not |
1177 | if (!IsStatic) | 1194 | if (IsPhysicallyActive) |
1178 | { | 1195 | { |
1179 | if (force.IsFinite()) | 1196 | if (force.IsFinite()) |
1180 | { | 1197 | { |
1181 | float magnitude = force.Length(); | ||
1182 | if (magnitude > BSParam.MaxAddForceMagnitude) | ||
1183 | { | ||
1184 | // Force has a limit | ||
1185 | force = force / magnitude * BSParam.MaxAddForceMagnitude; | ||
1186 | } | ||
1187 | |||
1188 | OMV.Vector3 addForce = force; | ||
1189 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); | 1198 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
1190 | 1199 | ||
1200 | OMV.Vector3 addForce = force; | ||
1191 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | 1201 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() |
1192 | { | 1202 | { |
1193 | // Bullet adds this central force to the total force for this tick | 1203 | // Bullet adds this central force to the total force for this tick |
@@ -1209,19 +1219,13 @@ public sealed class BSPrim : BSPhysObject | |||
1209 | 1219 | ||
1210 | public void AddForceImpulse(OMV.Vector3 impulse, bool pushforce, bool inTaintTime) { | 1220 | public void AddForceImpulse(OMV.Vector3 impulse, bool pushforce, bool inTaintTime) { |
1211 | // for an object, doesn't matter if force is a pushforce or not | 1221 | // for an object, doesn't matter if force is a pushforce or not |
1212 | if (!IsStatic) | 1222 | if (!IsPhysicallyActive) |
1213 | { | 1223 | { |
1214 | if (impulse.IsFinite()) | 1224 | if (impulse.IsFinite()) |
1215 | { | 1225 | { |
1216 | float magnitude = impulse.Length(); | 1226 | OMV.Vector3 addImpulse = Util.ClampV(impulse, BSParam.MaxAddForceMagnitude); |
1217 | if (magnitude > BSParam.MaxAddForceMagnitude) | ||
1218 | { | ||
1219 | // Force has a limit | ||
1220 | impulse = impulse / magnitude * BSParam.MaxAddForceMagnitude; | ||
1221 | } | ||
1222 | |||
1223 | // DetailLog("{0},BSPrim.addForceImpulse,call,impulse={1}", LocalID, impulse); | 1227 | // DetailLog("{0},BSPrim.addForceImpulse,call,impulse={1}", LocalID, impulse); |
1224 | OMV.Vector3 addImpulse = impulse; | 1228 | |
1225 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddImpulse", delegate() | 1229 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddImpulse", delegate() |
1226 | { | 1230 | { |
1227 | // Bullet adds this impulse immediately to the velocity | 1231 | // Bullet adds this impulse immediately to the velocity |
@@ -1584,11 +1588,6 @@ public sealed class BSPrim : BSPhysObject | |||
1584 | // Called at taint-time!!! | 1588 | // Called at taint-time!!! |
1585 | public void CreateGeomAndObject(bool forceRebuild) | 1589 | public void CreateGeomAndObject(bool forceRebuild) |
1586 | { | 1590 | { |
1587 | // If this prim is part of a linkset, we must remove and restore the physical | ||
1588 | // links if the body is rebuilt. | ||
1589 | bool needToRestoreLinkset = false; | ||
1590 | bool needToRestoreVehicle = false; | ||
1591 | |||
1592 | // Create the correct physical representation for this type of object. | 1591 | // Create the correct physical representation for this type of object. |
1593 | // Updates PhysBody and PhysShape with the new information. | 1592 | // Updates PhysBody and PhysShape with the new information. |
1594 | // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. | 1593 | // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary. |
@@ -1597,21 +1596,10 @@ public sealed class BSPrim : BSPhysObject | |||
1597 | // Called if the current prim body is about to be destroyed. | 1596 | // Called if the current prim body is about to be destroyed. |
1598 | // Remove all the physical dependencies on the old body. | 1597 | // Remove all the physical dependencies on the old body. |
1599 | // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) | 1598 | // (Maybe someday make the changing of BSShape an event to be subscribed to by BSLinkset, ...) |
1600 | needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); | 1599 | Linkset.RemoveBodyDependencies(this); |
1601 | needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this); | 1600 | _vehicle.RemoveBodyDependencies(this); |
1602 | }); | 1601 | }); |
1603 | 1602 | ||
1604 | if (needToRestoreLinkset) | ||
1605 | { | ||
1606 | // If physical body dependencies were removed, restore them | ||
1607 | Linkset.RestoreBodyDependencies(this); | ||
1608 | } | ||
1609 | if (needToRestoreVehicle) | ||
1610 | { | ||
1611 | // If physical body dependencies were removed, restore them | ||
1612 | _vehicle.RestoreBodyDependencies(this); | ||
1613 | } | ||
1614 | |||
1615 | // Make sure the properties are set on the new object | 1603 | // Make sure the properties are set on the new object |
1616 | UpdatePhysicalParameters(); | 1604 | UpdatePhysicalParameters(); |
1617 | return; | 1605 | return; |
@@ -1628,17 +1616,28 @@ public sealed class BSPrim : BSPhysObject | |||
1628 | // TODO: handle physics introduced by Bullet with computed vehicle physics. | 1616 | // TODO: handle physics introduced by Bullet with computed vehicle physics. |
1629 | if (_vehicle.IsActive) | 1617 | if (_vehicle.IsActive) |
1630 | { | 1618 | { |
1631 | entprop.RotationalVelocity = OMV.Vector3.Zero; | 1619 | // entprop.RotationalVelocity = OMV.Vector3.Zero; |
1620 | } | ||
1621 | |||
1622 | // DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG | ||
1623 | |||
1624 | // Undo any center-of-mass displacement that might have been done. | ||
1625 | if (PositionDisplacement != OMV.Vector3.Zero) | ||
1626 | { | ||
1627 | // Correct for any rotation around the center-of-mass | ||
1628 | // TODO!!! | ||
1629 | entprop.Position -= PositionDisplacement; | ||
1632 | } | 1630 | } |
1633 | 1631 | ||
1634 | // Assign directly to the local variables so the normal set actions do not happen | 1632 | // Assign directly to the local variables so the normal set actions do not happen |
1635 | entprop.Position -= PositionDisplacement; | ||
1636 | _position = entprop.Position; | 1633 | _position = entprop.Position; |
1637 | _orientation = entprop.Rotation; | 1634 | _orientation = entprop.Rotation; |
1638 | _velocity = entprop.Velocity; | 1635 | _velocity = entprop.Velocity; |
1639 | _acceleration = entprop.Acceleration; | 1636 | _acceleration = entprop.Acceleration; |
1640 | _rotationalVelocity = entprop.RotationalVelocity; | 1637 | _rotationalVelocity = entprop.RotationalVelocity; |
1641 | 1638 | ||
1639 | // DetailLog("{0},BSPrim.UpdateProperties,afterAssign,entprop={1}", LocalID, entprop); // DEBUG DEBUG | ||
1640 | |||
1642 | // The sanity check can change the velocity and/or position. | 1641 | // The sanity check can change the velocity and/or position. |
1643 | if (IsPhysical && PositionSanityCheck(true)) | 1642 | if (IsPhysical && PositionSanityCheck(true)) |
1644 | { | 1643 | { |
@@ -1647,8 +1646,7 @@ public sealed class BSPrim : BSPhysObject | |||
1647 | } | 1646 | } |
1648 | 1647 | ||
1649 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG | 1648 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG |
1650 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", | 1649 | DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); |
1651 | LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); | ||
1652 | 1650 | ||
1653 | // remember the current and last set values | 1651 | // remember the current and last set values |
1654 | LastEntityProperties = CurrentEntityProperties; | 1652 | LastEntityProperties = CurrentEntityProperties; |
@@ -1667,7 +1665,7 @@ public sealed class BSPrim : BSPhysObject | |||
1667 | */ | 1665 | */ |
1668 | 1666 | ||
1669 | // The linkset implimentation might want to know about this. | 1667 | // The linkset implimentation might want to know about this. |
1670 | Linkset.UpdateProperties(this, true); | 1668 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
1671 | } | 1669 | } |
1672 | } | 1670 | } |
1673 | } | 1671 | } |