diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index c7a81e0..f804a0f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -94,7 +94,7 @@ public sealed class BSPrim : BSPhysObject | |||
94 | _size = size; | 94 | _size = size; |
95 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). | 95 | Scale = size; // prims are the size the user wants them to be (different for BSCharactes). |
96 | _orientation = rotation; | 96 | _orientation = rotation; |
97 | _buoyancy = 1f; | 97 | _buoyancy = 0f; |
98 | _velocity = OMV.Vector3.Zero; | 98 | _velocity = OMV.Vector3.Zero; |
99 | _rotationalVelocity = OMV.Vector3.Zero; | 99 | _rotationalVelocity = OMV.Vector3.Zero; |
100 | BaseShape = pbs; | 100 | BaseShape = pbs; |
@@ -408,12 +408,15 @@ public sealed class BSPrim : BSPhysObject | |||
408 | { | 408 | { |
409 | if (IsStatic) | 409 | if (IsStatic) |
410 | { | 410 | { |
411 | BulletSimAPI.SetGravity2(PhysBody.ptr, PhysicsScene.DefaultGravity); | ||
411 | Inertia = OMV.Vector3.Zero; | 412 | Inertia = OMV.Vector3.Zero; |
412 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); | 413 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); |
413 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 414 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); |
414 | } | 415 | } |
415 | else | 416 | else |
416 | { | 417 | { |
418 | OMV.Vector3 grav = ComputeGravity(); | ||
419 | |||
417 | if (inWorld) | 420 | if (inWorld) |
418 | { | 421 | { |
419 | // Changing interesting properties doesn't change proxy and collision cache | 422 | // Changing interesting properties doesn't change proxy and collision cache |
@@ -422,13 +425,16 @@ public sealed class BSPrim : BSPhysObject | |||
422 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 425 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); |
423 | } | 426 | } |
424 | 427 | ||
428 | // The computation of mass props requires gravity to be set on the object. | ||
429 | BulletSimAPI.SetGravity2(PhysBody.ptr, grav); | ||
430 | |||
425 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 431 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); |
426 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | 432 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); |
427 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 433 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); |
428 | 434 | ||
429 | // center of mass is at the zero of the object | 435 | // center of mass is at the zero of the object |
430 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | 436 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); |
431 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},inWorld={3}", LocalID, physMass, Inertia, inWorld); | 437 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},grav={3},inWorld={4}", LocalID, physMass, Inertia, grav, inWorld); |
432 | 438 | ||
433 | if (inWorld) | 439 | if (inWorld) |
434 | { | 440 | { |
@@ -437,13 +443,23 @@ public sealed class BSPrim : BSPhysObject | |||
437 | 443 | ||
438 | // Must set gravity after it has been added to the world because, for unknown reasons, | 444 | // Must set gravity after it has been added to the world because, for unknown reasons, |
439 | // adding the object resets the object's gravity to world gravity | 445 | // adding the object resets the object's gravity to world gravity |
440 | OMV.Vector3 grav = PhysicsScene.DefaultGravity * (1f - Buoyancy); | ||
441 | BulletSimAPI.SetGravity2(PhysBody.ptr, grav); | 446 | BulletSimAPI.SetGravity2(PhysBody.ptr, grav); |
442 | 447 | ||
443 | } | 448 | } |
444 | } | 449 | } |
445 | } | 450 | } |
446 | 451 | ||
452 | // Return what gravity should be set to this very moment | ||
453 | private OMV.Vector3 ComputeGravity() | ||
454 | { | ||
455 | OMV.Vector3 ret = PhysicsScene.DefaultGravity; | ||
456 | |||
457 | if (!IsStatic) | ||
458 | ret *= (1f - Buoyancy); | ||
459 | |||
460 | return ret; | ||
461 | } | ||
462 | |||
447 | // Is this used? | 463 | // Is this used? |
448 | public override OMV.Vector3 CenterOfMass | 464 | public override OMV.Vector3 CenterOfMass |
449 | { | 465 | { |
@@ -669,7 +685,7 @@ public sealed class BSPrim : BSPhysObject | |||
669 | _isPhysical = value; | 685 | _isPhysical = value; |
670 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() | 686 | PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() |
671 | { | 687 | { |
672 | // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); | 688 | DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); |
673 | SetObjectDynamic(true); | 689 | SetObjectDynamic(true); |
674 | // whether phys-to-static or static-to-phys, the object is not moving. | 690 | // whether phys-to-static or static-to-phys, the object is not moving. |
675 | ZeroMotion(true); | 691 | ZeroMotion(true); |
@@ -726,6 +742,10 @@ public sealed class BSPrim : BSPhysObject | |||
726 | 742 | ||
727 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | 743 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); |
728 | 744 | ||
745 | // TODO: Fix this. Total kludge because adding object to world resets its gravity to default. | ||
746 | // Replace this when the new AddObjectToWorld function is complete. | ||
747 | BulletSimAPI.SetGravity2(PhysBody.ptr, ComputeGravity()); | ||
748 | |||
729 | // Rebuild its shape | 749 | // Rebuild its shape |
730 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); | 750 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr); |
731 | 751 | ||
@@ -976,6 +996,7 @@ public sealed class BSPrim : BSPhysObject | |||
976 | _buoyancy = value; | 996 | _buoyancy = value; |
977 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 997 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
978 | // Force the recalculation of the various inertia,etc variables in the object | 998 | // Force the recalculation of the various inertia,etc variables in the object |
999 | DetailLog("{0},BSPrim.ForceBuoyancy,buoy={1},mass={2}", LocalID, _buoyancy, _mass); | ||
979 | UpdatePhysicalMassProperties(_mass, true); | 1000 | UpdatePhysicalMassProperties(_mass, true); |
980 | ActivateIfPhysical(false); | 1001 | ActivateIfPhysical(false); |
981 | } | 1002 | } |