diff options
author | Robert Adams | 2012-10-01 11:54:35 -0700 |
---|---|---|
committer | Robert Adams | 2012-10-02 11:13:32 -0700 |
commit | 33617e09a185be68ceeaaba0fe9b7b2e6068124d (patch) | |
tree | ea34c6e9a6090ba9c4ae93fcd308f0a9e3df518f /OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |
parent | Correct my name in CONTRIBUTORS.txt (diff) | |
download | opensim-SC-33617e09a185be68ceeaaba0fe9b7b2e6068124d.zip opensim-SC-33617e09a185be68ceeaaba0fe9b7b2e6068124d.tar.gz opensim-SC-33617e09a185be68ceeaaba0fe9b7b2e6068124d.tar.bz2 opensim-SC-33617e09a185be68ceeaaba0fe9b7b2e6068124d.tar.xz |
BulletSim: impliment FloatOnWater OS function.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 77 |
1 files changed, 72 insertions, 5 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index e54bf75..e37a4a0 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -267,6 +267,7 @@ public sealed class BSPrim : BSPhysObject | |||
267 | set { | 267 | set { |
268 | _position = value; | 268 | _position = value; |
269 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? | 269 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? |
270 | PositionSanityCheck(); | ||
270 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() | 271 | PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() |
271 | { | 272 | { |
272 | // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 273 | // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
@@ -275,6 +276,63 @@ public sealed class BSPrim : BSPhysObject | |||
275 | } | 276 | } |
276 | } | 277 | } |
277 | 278 | ||
279 | // Check that the current position is sane and, if not, modify the position to make it so. | ||
280 | // Check for being below terrain and being out of bounds. | ||
281 | // Returns 'true' of the position was made sane by some action. | ||
282 | private bool PositionSanityCheck() | ||
283 | { | ||
284 | bool ret = false; | ||
285 | |||
286 | // If totally below the ground, move the prim up | ||
287 | // TODO: figure out the right solution for this... only for dynamic objects? | ||
288 | /* | ||
289 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); | ||
290 | if (Position.Z < terrainHeight) | ||
291 | { | ||
292 | DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); | ||
293 | _position.Z = terrainHeight + 2.0f; | ||
294 | ret = true; | ||
295 | } | ||
296 | */ | ||
297 | if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) != 0) | ||
298 | { | ||
299 | float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position); | ||
300 | if (Position.Z < waterHeight) | ||
301 | { | ||
302 | _position.Z = waterHeight; | ||
303 | ret = true; | ||
304 | } | ||
305 | } | ||
306 | |||
307 | // TODO: check for out of bounds | ||
308 | return ret; | ||
309 | } | ||
310 | |||
311 | // A version of the sanity check that also makes sure a new position value is | ||
312 | // pushed back to the physics engine. This routine would be used by anyone | ||
313 | // who is not already pushing the value. | ||
314 | private bool PositionSanityCheck2(bool atTaintTime) | ||
315 | { | ||
316 | bool ret = false; | ||
317 | if (PositionSanityCheck()) | ||
318 | { | ||
319 | // The new position value must be pushed into the physics engine but we can't | ||
320 | // just assign to "Position" because of potential call loops. | ||
321 | BSScene.TaintCallback sanityOperation = delegate() | ||
322 | { | ||
323 | DetailLog("{0},BSPrim.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | ||
324 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); | ||
325 | }; | ||
326 | if (atTaintTime) | ||
327 | sanityOperation(); | ||
328 | else | ||
329 | PhysicsScene.TaintedObject("BSPrim.PositionSanityCheck", sanityOperation); | ||
330 | |||
331 | ret = true; | ||
332 | } | ||
333 | return ret; | ||
334 | } | ||
335 | |||
278 | // Return the effective mass of the object. | 336 | // Return the effective mass of the object. |
279 | // If there are multiple items in the linkset, add them together for the root | 337 | // If there are multiple items in the linkset, add them together for the root |
280 | public override float Mass | 338 | public override float Mass |
@@ -481,11 +539,10 @@ public sealed class BSPrim : BSPhysObject | |||
481 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). | 539 | // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). |
482 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); | 540 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); |
483 | 541 | ||
484 | |||
485 | // Set up the object physicalness (does gravity and collisions move this object) | 542 | // Set up the object physicalness (does gravity and collisions move this object) |
486 | MakeDynamic(IsStatic); | 543 | MakeDynamic(IsStatic); |
487 | 544 | ||
488 | // Do any vehicle stuff | 545 | // Update vehicle specific parameters |
489 | _vehicle.Refresh(); | 546 | _vehicle.Refresh(); |
490 | 547 | ||
491 | // Arrange for collision events if the simulator wants them | 548 | // Arrange for collision events if the simulator wants them |
@@ -556,7 +613,6 @@ public sealed class BSPrim : BSPhysObject | |||
556 | // A dynamic object has mass | 613 | // A dynamic object has mass |
557 | IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); | 614 | IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); |
558 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Mass); | 615 | OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Mass); |
559 | // OMV.Vector3 inertia = OMV.Vector3.Zero; | ||
560 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); | 616 | BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); |
561 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); | 617 | BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); |
562 | 618 | ||
@@ -566,7 +622,7 @@ public sealed class BSPrim : BSPhysObject | |||
566 | BulletSimAPI.SetSleepingThresholds2(BSBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); | 622 | BulletSimAPI.SetSleepingThresholds2(BSBody.ptr, PhysicsScene.Params.linearSleepingThreshold, PhysicsScene.Params.angularSleepingThreshold); |
567 | BulletSimAPI.SetContactProcessingThreshold2(BSBody.ptr, PhysicsScene.Params.contactProcessingThreshold); | 623 | BulletSimAPI.SetContactProcessingThreshold2(BSBody.ptr, PhysicsScene.Params.contactProcessingThreshold); |
568 | 624 | ||
569 | // There can be special things needed for implementing linksets. | 625 | // There might be special things needed for implementing linksets. |
570 | Linkset.MakeDynamic(this); | 626 | Linkset.MakeDynamic(this); |
571 | 627 | ||
572 | // Force activation of the object so Bullet will act on it. | 628 | // Force activation of the object so Bullet will act on it. |
@@ -656,7 +712,16 @@ public sealed class BSPrim : BSPhysObject | |||
656 | } | 712 | } |
657 | } | 713 | } |
658 | public override bool FloatOnWater { | 714 | public override bool FloatOnWater { |
659 | set { _floatOnWater = value; } | 715 | set { |
716 | _floatOnWater = value; | ||
717 | PhysicsScene.TaintedObject("BSPrim.setFloatOnWater", delegate() | ||
718 | { | ||
719 | if (_floatOnWater) | ||
720 | CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); | ||
721 | else | ||
722 | CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); | ||
723 | }); | ||
724 | } | ||
660 | } | 725 | } |
661 | public override OMV.Vector3 RotationalVelocity { | 726 | public override OMV.Vector3 RotationalVelocity { |
662 | get { | 727 | get { |
@@ -1198,6 +1263,8 @@ public sealed class BSPrim : BSPhysObject | |||
1198 | _acceleration = entprop.Acceleration; | 1263 | _acceleration = entprop.Acceleration; |
1199 | _rotationalVelocity = entprop.RotationalVelocity; | 1264 | _rotationalVelocity = entprop.RotationalVelocity; |
1200 | 1265 | ||
1266 | PositionSanityCheck2(true); | ||
1267 | |||
1201 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | 1268 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", |
1202 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | 1269 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); |
1203 | 1270 | ||