diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 26b8df5..159f79f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -115,6 +115,8 @@ public sealed class BSPrim : BSPhysObject | |||
115 | PhysBody = new BulletBody(LocalID); | 115 | PhysBody = new BulletBody(LocalID); |
116 | PhysShape = new BulletShape(); | 116 | PhysShape = new BulletShape(); |
117 | 117 | ||
118 | Linkset.Refresh(this); | ||
119 | |||
118 | DetailLog("{0},BSPrim.constructor,call", LocalID); | 120 | DetailLog("{0},BSPrim.constructor,call", LocalID); |
119 | // do the actual object creation at taint time | 121 | // do the actual object creation at taint time |
120 | PhysicsScene.TaintedObject("BSPrim.create", delegate() | 122 | PhysicsScene.TaintedObject("BSPrim.create", delegate() |
@@ -384,13 +386,13 @@ public sealed class BSPrim : BSPhysObject | |||
384 | } | 386 | } |
385 | 387 | ||
386 | // Return the effective mass of the object. | 388 | // Return the effective mass of the object. |
387 | // If there are multiple items in the linkset, add them together for the root | 389 | // The definition of this call is to return the mass of the prim. |
390 | // If the simulator cares about the mass of the linkset, it will sum it itself. | ||
388 | public override float Mass | 391 | public override float Mass |
389 | { | 392 | { |
390 | get | 393 | get |
391 | { | 394 | { |
392 | return Linkset.LinksetMass; | 395 | return _mass; |
393 | // return _mass; | ||
394 | } | 396 | } |
395 | } | 397 | } |
396 | 398 | ||
@@ -400,22 +402,41 @@ public sealed class BSPrim : BSPhysObject | |||
400 | } | 402 | } |
401 | // Set the physical mass to the passed mass. | 403 | // Set the physical mass to the passed mass. |
402 | // Note that this does not change _mass! | 404 | // Note that this does not change _mass! |
403 | public override void UpdatePhysicalMassProperties(float physMass) | 405 | public override void UpdatePhysicalMassProperties(float physMass, bool inWorld) |
404 | { | 406 | { |
405 | if (IsStatic) | 407 | if (PhysBody.HasPhysicalBody) |
406 | { | 408 | { |
407 | Inertia = OMV.Vector3.Zero; | 409 | if (IsStatic) |
408 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); | 410 | { |
409 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 411 | Inertia = OMV.Vector3.Zero; |
410 | } | 412 | BulletSimAPI.SetMassProps2(PhysBody.ptr, 0f, Inertia); |
411 | else | 413 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); |
412 | { | 414 | } |
413 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | 415 | else |
414 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | 416 | { |
415 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | 417 | if (inWorld) |
416 | // center of mass is at the zero of the object | 418 | { |
417 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | 419 | // Changing interesting properties doesn't change proxy and collision cache |
418 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); | 420 | // information. The Bullet solution is to re-add the object to the world |
421 | // after parameters are changed. | ||
422 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | ||
423 | } | ||
424 | |||
425 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | ||
426 | BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); | ||
427 | |||
428 | Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); | ||
429 | BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); | ||
430 | BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); | ||
431 | // center of mass is at the zero of the object | ||
432 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); | ||
433 | DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); | ||
434 | |||
435 | if (inWorld) | ||
436 | { | ||
437 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); | ||
438 | } | ||
439 | } | ||
419 | } | 440 | } |
420 | } | 441 | } |
421 | 442 | ||
@@ -714,7 +735,7 @@ public sealed class BSPrim : BSPhysObject | |||
714 | Linkset.Refresh(this); | 735 | Linkset.Refresh(this); |
715 | 736 | ||
716 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", | 737 | DetailLog("{0},BSPrim.UpdatePhysicalParameters,taintExit,static={1},solid={2},mass={3},collide={4},cf={5:X},body={6},shape={7}", |
717 | LocalID, IsStatic, IsSolid, _mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); | 738 | LocalID, IsStatic, IsSolid, Mass, SubscribedEvents(), CurrentCollisionFlags, PhysBody, PhysShape); |
718 | } | 739 | } |
719 | 740 | ||
720 | // "Making dynamic" means changing to and from static. | 741 | // "Making dynamic" means changing to and from static. |
@@ -737,7 +758,7 @@ public sealed class BSPrim : BSPhysObject | |||
737 | BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); | 758 | BulletSimAPI.SetRestitution2(PhysBody.ptr, matAttrib.restitution); |
738 | 759 | ||
739 | // Mass is zero which disables a bunch of physics stuff in Bullet | 760 | // Mass is zero which disables a bunch of physics stuff in Bullet |
740 | UpdatePhysicalMassProperties(0f); | 761 | UpdatePhysicalMassProperties(0f, false); |
741 | // Set collision detection parameters | 762 | // Set collision detection parameters |
742 | if (BSParam.CcdMotionThreshold > 0f) | 763 | if (BSParam.CcdMotionThreshold > 0f) |
743 | { | 764 | { |
@@ -777,7 +798,7 @@ public sealed class BSPrim : BSPhysObject | |||
777 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); | 798 | // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.PhysBody.ptr, _position, _orientation); |
778 | 799 | ||
779 | // A dynamic object has mass | 800 | // A dynamic object has mass |
780 | UpdatePhysicalMassProperties(RawMass); | 801 | UpdatePhysicalMassProperties(RawMass, false); |
781 | 802 | ||
782 | // Set collision detection parameters | 803 | // Set collision detection parameters |
783 | if (BSParam.CcdMotionThreshold > 0f) | 804 | if (BSParam.CcdMotionThreshold > 0f) |
@@ -950,13 +971,9 @@ public sealed class BSPrim : BSPhysObject | |||
950 | set { | 971 | set { |
951 | _buoyancy = value; | 972 | _buoyancy = value; |
952 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 973 | // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
953 | // Buoyancy is faked by changing the gravity applied to the object | 974 | // Force the recalculation of the various inertia,etc variables in the object |
954 | if (PhysBody.HasPhysicalBody) | 975 | UpdatePhysicalMassProperties(_mass, true); |
955 | { | 976 | ActivateIfPhysical(false); |
956 | float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); | ||
957 | BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); | ||
958 | ActivateIfPhysical(false); | ||
959 | } | ||
960 | } | 977 | } |
961 | } | 978 | } |
962 | 979 | ||