diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 94 |
1 files changed, 39 insertions, 55 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index aaa6fe5..f80084a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -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 |
@@ -682,12 +665,13 @@ public sealed class BSPrim : BSPhysObject | |||
682 | return; | 665 | return; |
683 | _orientation = value; | 666 | _orientation = value; |
684 | 667 | ||
685 | // A linkset might need to know if a component information changed. | ||
686 | Linkset.UpdateProperties(this, false); | ||
687 | |||
688 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() | 668 | PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() |
689 | { | 669 | { |
690 | 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 | |||
691 | }); | 675 | }); |
692 | } | 676 | } |
693 | } | 677 | } |
@@ -989,10 +973,10 @@ public sealed class BSPrim : BSPhysObject | |||
989 | } | 973 | } |
990 | set { | 974 | set { |
991 | _rotationalVelocity = value; | 975 | _rotationalVelocity = value; |
976 | Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); | ||
992 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 977 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
993 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() | 978 | PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() |
994 | { | 979 | { |
995 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | ||
996 | ForceRotationalVelocity = _rotationalVelocity; | 980 | ForceRotationalVelocity = _rotationalVelocity; |
997 | }); | 981 | }); |
998 | } | 982 | } |
@@ -1005,7 +989,9 @@ public sealed class BSPrim : BSPhysObject | |||
1005 | _rotationalVelocity = value; | 989 | _rotationalVelocity = value; |
1006 | if (PhysBody.HasPhysicalBody) | 990 | if (PhysBody.HasPhysicalBody) |
1007 | { | 991 | { |
992 | DetailLog("{0},BSPrim.ForceRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | ||
1008 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); | 993 | PhysicsScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); |
994 | // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); | ||
1009 | ActivateIfPhysical(false); | 995 | ActivateIfPhysical(false); |
1010 | } | 996 | } |
1011 | } | 997 | } |
@@ -1082,7 +1068,7 @@ public sealed class BSPrim : BSPhysObject | |||
1082 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) | 1068 | OMV.Vector3 origPosition = RawPosition; // DEBUG DEBUG (for printout below) |
1083 | 1069 | ||
1084 | // '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. |
1085 | OMV.Vector3 movePosition = _targetMotor.Step(timeStep); | 1071 | OMV.Vector3 movePosition = RawPosition + _targetMotor.Step(timeStep); |
1086 | 1072 | ||
1087 | // 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. |
1088 | if (_targetMotor.ErrorIsZero()) | 1074 | if (_targetMotor.ErrorIsZero()) |
@@ -1193,10 +1179,14 @@ public sealed class BSPrim : BSPhysObject | |||
1193 | public override float APIDDamping { set { return; } } | 1179 | public override float APIDDamping { set { return; } } |
1194 | 1180 | ||
1195 | 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 | |||
1196 | // 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. |
1197 | OMV.Vector3 addForce = force / PhysicsScene.LastTimeStep; | 1186 | addForce /= PhysicsScene.LastTimeStep; |
1198 | AddForce(addForce, pushforce, false); | 1187 | AddForce(addForce, pushforce, false /* inTaintTime */); |
1199 | } | 1188 | } |
1189 | |||
1200 | // 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. |
1201 | // This added force will only last the next simulation tick. | 1191 | // This added force will only last the next simulation tick. |
1202 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { | 1192 | public void AddForce(OMV.Vector3 force, bool pushforce, bool inTaintTime) { |
@@ -1205,9 +1195,9 @@ public sealed class BSPrim : BSPhysObject | |||
1205 | { | 1195 | { |
1206 | if (force.IsFinite()) | 1196 | if (force.IsFinite()) |
1207 | { | 1197 | { |
1208 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); | ||
1209 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); | 1198 | // DetailLog("{0},BSPrim.addForce,call,force={1}", LocalID, addForce); |
1210 | 1199 | ||
1200 | OMV.Vector3 addForce = force; | ||
1211 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() | 1201 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.AddForce", delegate() |
1212 | { | 1202 | { |
1213 | // 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 |
@@ -1598,11 +1588,6 @@ public sealed class BSPrim : BSPhysObject | |||
1598 | // Called at taint-time!!! | 1588 | // Called at taint-time!!! |
1599 | public void CreateGeomAndObject(bool forceRebuild) | 1589 | public void CreateGeomAndObject(bool forceRebuild) |
1600 | { | 1590 | { |
1601 | // If this prim is part of a linkset, we must remove and restore the physical | ||
1602 | // links if the body is rebuilt. | ||
1603 | bool needToRestoreLinkset = false; | ||
1604 | bool needToRestoreVehicle = false; | ||
1605 | |||
1606 | // Create the correct physical representation for this type of object. | 1591 | // Create the correct physical representation for this type of object. |
1607 | // Updates PhysBody and PhysShape with the new information. | 1592 | // Updates PhysBody and PhysShape with the new information. |
1608 | // 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. |
@@ -1611,21 +1596,10 @@ public sealed class BSPrim : BSPhysObject | |||
1611 | // Called if the current prim body is about to be destroyed. | 1596 | // Called if the current prim body is about to be destroyed. |
1612 | // Remove all the physical dependencies on the old body. | 1597 | // Remove all the physical dependencies on the old body. |
1613 | // (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, ...) |
1614 | needToRestoreLinkset = Linkset.RemoveBodyDependencies(this); | 1599 | Linkset.RemoveBodyDependencies(this); |
1615 | needToRestoreVehicle = _vehicle.RemoveBodyDependencies(this); | 1600 | _vehicle.RemoveBodyDependencies(this); |
1616 | }); | 1601 | }); |
1617 | 1602 | ||
1618 | if (needToRestoreLinkset) | ||
1619 | { | ||
1620 | // If physical body dependencies were removed, restore them | ||
1621 | Linkset.RestoreBodyDependencies(this); | ||
1622 | } | ||
1623 | if (needToRestoreVehicle) | ||
1624 | { | ||
1625 | // If physical body dependencies were removed, restore them | ||
1626 | _vehicle.RestoreBodyDependencies(this); | ||
1627 | } | ||
1628 | |||
1629 | // Make sure the properties are set on the new object | 1603 | // Make sure the properties are set on the new object |
1630 | UpdatePhysicalParameters(); | 1604 | UpdatePhysicalParameters(); |
1631 | return; | 1605 | return; |
@@ -1642,17 +1616,28 @@ public sealed class BSPrim : BSPhysObject | |||
1642 | // TODO: handle physics introduced by Bullet with computed vehicle physics. | 1616 | // TODO: handle physics introduced by Bullet with computed vehicle physics. |
1643 | if (_vehicle.IsActive) | 1617 | if (_vehicle.IsActive) |
1644 | { | 1618 | { |
1645 | 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; | ||
1646 | } | 1630 | } |
1647 | 1631 | ||
1648 | // 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 |
1649 | entprop.Position -= PositionDisplacement; | ||
1650 | _position = entprop.Position; | 1633 | _position = entprop.Position; |
1651 | _orientation = entprop.Rotation; | 1634 | _orientation = entprop.Rotation; |
1652 | _velocity = entprop.Velocity; | 1635 | _velocity = entprop.Velocity; |
1653 | _acceleration = entprop.Acceleration; | 1636 | _acceleration = entprop.Acceleration; |
1654 | _rotationalVelocity = entprop.RotationalVelocity; | 1637 | _rotationalVelocity = entprop.RotationalVelocity; |
1655 | 1638 | ||
1639 | // DetailLog("{0},BSPrim.UpdateProperties,afterAssign,entprop={1}", LocalID, entprop); // DEBUG DEBUG | ||
1640 | |||
1656 | // The sanity check can change the velocity and/or position. | 1641 | // The sanity check can change the velocity and/or position. |
1657 | if (IsPhysical && PositionSanityCheck(true)) | 1642 | if (IsPhysical && PositionSanityCheck(true)) |
1658 | { | 1643 | { |
@@ -1661,8 +1646,7 @@ public sealed class BSPrim : BSPhysObject | |||
1661 | } | 1646 | } |
1662 | 1647 | ||
1663 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG | 1648 | OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG |
1664 | 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); |
1665 | LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); | ||
1666 | 1650 | ||
1667 | // remember the current and last set values | 1651 | // remember the current and last set values |
1668 | LastEntityProperties = CurrentEntityProperties; | 1652 | LastEntityProperties = CurrentEntityProperties; |
@@ -1681,7 +1665,7 @@ public sealed class BSPrim : BSPhysObject | |||
1681 | */ | 1665 | */ |
1682 | 1666 | ||
1683 | // The linkset implimentation might want to know about this. | 1667 | // The linkset implimentation might want to know about this. |
1684 | Linkset.UpdateProperties(this, true); | 1668 | Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); |
1685 | } | 1669 | } |
1686 | } | 1670 | } |
1687 | } | 1671 | } |