aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs41
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs77
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs8
3 files changed, 104 insertions, 22 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index b88ec3c..5cf8953 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -234,6 +234,15 @@ public class BSCharacter : BSPhysObject
234 _position.Z = terrainHeight + 2.0f; 234 _position.Z = terrainHeight + 2.0f;
235 ret = true; 235 ret = true;
236 } 236 }
237 if ((CurrentCollisionFlags & CollisionFlags.BS_FLOATS_ON_WATER) == 0)
238 {
239 float waterHeight = PhysicsScene.GetWaterLevelAtXYZ(_position);
240 if (Position.Z < waterHeight)
241 {
242 _position.Z = waterHeight;
243 ret = true;
244 }
245 }
237 246
238 // TODO: check for out of bounds 247 // TODO: check for out of bounds
239 return ret; 248 return ret;
@@ -242,18 +251,22 @@ public class BSCharacter : BSPhysObject
242 // A version of the sanity check that also makes sure a new position value is 251 // A version of the sanity check that also makes sure a new position value is
243 // pushed back to the physics engine. This routine would be used by anyone 252 // pushed back to the physics engine. This routine would be used by anyone
244 // who is not already pushing the value. 253 // who is not already pushing the value.
245 private bool PositionSanityCheck2() 254 private bool PositionSanityCheck2(bool atTaintTime)
246 { 255 {
247 bool ret = false; 256 bool ret = false;
248 if (PositionSanityCheck()) 257 if (PositionSanityCheck())
249 { 258 {
250 // The new position value must be pushed into the physics engine but we can't 259 // The new position value must be pushed into the physics engine but we can't
251 // just assign to "Position" because of potential call loops. 260 // just assign to "Position" because of potential call loops.
252 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() 261 BSScene.TaintCallback sanityOperation = delegate()
253 { 262 {
254 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 263 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
255 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation); 264 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
256 }); 265 };
266 if (atTaintTime)
267 sanityOperation();
268 else
269 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", sanityOperation);
257 ret = true; 270 ret = true;
258 } 271 }
259 return ret; 272 return ret;
@@ -378,7 +391,16 @@ public class BSCharacter : BSPhysObject
378 set { _collidingObj = value; } 391 set { _collidingObj = value; }
379 } 392 }
380 public override bool FloatOnWater { 393 public override bool FloatOnWater {
381 set { _floatOnWater = value; } 394 set {
395 _floatOnWater = value;
396 PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate()
397 {
398 if (_floatOnWater)
399 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
400 else
401 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
402 });
403 }
382 } 404 }
383 public override OMV.Vector3 RotationalVelocity { 405 public override OMV.Vector3 RotationalVelocity {
384 get { return _rotationalVelocity; } 406 get { return _rotationalVelocity; }
@@ -493,15 +515,14 @@ public class BSCharacter : BSPhysObject
493 _velocity = entprop.Velocity; 515 _velocity = entprop.Velocity;
494 _acceleration = entprop.Acceleration; 516 _acceleration = entprop.Acceleration;
495 _rotationalVelocity = entprop.RotationalVelocity; 517 _rotationalVelocity = entprop.RotationalVelocity;
518 // Do some sanity checking for the avatar. Make sure it's above ground and inbounds.
519 PositionSanityCheck2(true);
520
496 // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. 521 // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop.
497 // base.RequestPhysicsterseUpdate(); 522 // base.RequestPhysicsterseUpdate();
498 523
499 // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. 524 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}",
500 PositionSanityCheck2(); 525 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity);
501
502 float heightHere = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); // only for debug
503 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}",
504 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere);
505 } 526 }
506} 527}
507} 528}
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
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
index 1125d7e..d49e5f3 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs
@@ -344,10 +344,7 @@ public enum CollisionFlags : uint
344 CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6, 344 CF_DISABLE_SPU_COLLISION_PROCESS = 1 << 6,
345 // Following used by BulletSim to control collisions 345 // Following used by BulletSim to control collisions
346 BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10, 346 BS_SUBSCRIBE_COLLISION_EVENTS = 1 << 10,
347 // BS_VOLUME_DETECT_OBJECT = 1 << 11, 347 BS_FLOATS_ON_WATER = 1 << 11,
348 // BS_PHANTOM_OBJECT = 1 << 12,
349 // BS_PHYSICAL_OBJECT = 1 << 13,
350 // BS_TERRAIN_OBJECT = 1 << 14,
351 BS_NONE = 0, 348 BS_NONE = 0,
352 BS_ALL = 0xFFFFFFFF, 349 BS_ALL = 0xFFFFFFFF,
353 350
@@ -356,9 +353,6 @@ public enum CollisionFlags : uint
356 BS_ACTIVE = CF_STATIC_OBJECT 353 BS_ACTIVE = CF_STATIC_OBJECT
357 | CF_KINEMATIC_OBJECT 354 | CF_KINEMATIC_OBJECT
358 | CF_NO_CONTACT_RESPONSE 355 | CF_NO_CONTACT_RESPONSE
359 // | BS_VOLUME_DETECT_OBJECT
360 // | BS_PHANTOM_OBJECT
361 // | BS_PHYSICAL_OBJECT,
362}; 356};
363 357
364// Values for collisions groups and masks 358// Values for collisions groups and masks