From 459fcd81c9d6e7c92738b40f1b4b4fe746699379 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 11 Jan 2013 16:36:34 -0800 Subject: BulletSim: move center of gravity of linkset to its geometric center. Necessitated allowing simulator and physical position of a body to get out of sync since Bullet assumes that <0,0,0> is the center of mass. Update DLLs and SOs for the UpdateChildTransform so positions of individual prim in a linkset can be implemented. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 40 +++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 02d06b4..003dc54 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -50,7 +50,10 @@ public sealed class BSPrim : BSPhysObject private bool _grabbed; private bool _isSelected; private bool _isVolumeDetect; + + // _position is what the simulator thinks the positions of the prim is. private OMV.Vector3 _position; + private float _mass; // the mass of this object private float _density; private OMV.Vector3 _force; @@ -320,18 +323,37 @@ public sealed class BSPrim : BSPhysObject } public override OMV.Vector3 ForcePosition { get { - _position = PhysicsScene.PE.GetPosition(PhysBody); + _position = PhysicsScene.PE.GetPosition(PhysBody) - PositionDisplacement; return _position; } set { _position = value; if (PhysBody.HasPhysicalBody) { - PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); ActivateIfPhysical(false); } } } + // Override to have position displacement immediately update the physical position. + // A feeble attempt to keep the sim and physical positions in sync + // Must be called at taint time. + public override OMV.Vector3 PositionDisplacement + { + get + { + return base.PositionDisplacement; + } + set + { + base.PositionDisplacement = value; + PhysicsScene.TaintedObject(PhysicsScene.InTaintTime, "BSPrim.setPosition", delegate() + { + if (PhysBody.HasPhysicalBody) + PhysicsScene.PE.SetTranslation(PhysBody, _position + base.PositionDisplacement, _orientation); + }); + } + } // Check that the current position is sane and, if not, modify the position to make it so. // Check for being below terrain and being out of bounds. @@ -590,6 +612,7 @@ public sealed class BSPrim : BSPhysObject _velocity = value; if (PhysBody.HasPhysicalBody) { + DetailLog("{0},BSPrim.ForceVelocity,taint,vel={1}", LocalID, _velocity); PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); ActivateIfPhysical(false); } @@ -654,12 +677,7 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() { - if (PhysBody.HasPhysicalBody) - { - // _position = PhysicsScene.PE.GetObjectPosition(PhysicsScene.World, BSBody); - // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); - PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); - } + ForceOrientation = _orientation; }); } } @@ -674,7 +692,8 @@ public sealed class BSPrim : BSPhysObject set { _orientation = value; - PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); + if (PhysBody.HasPhysicalBody) + PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); } } public override int PhysicsActorType { @@ -813,7 +832,7 @@ public sealed class BSPrim : BSPhysObject // PhysicsScene.PE.ClearAllForces(BSBody); // For good measure, make sure the transform is set through to the motion state - PhysicsScene.PE.SetTranslation(PhysBody, _position, _orientation); + PhysicsScene.PE.SetTranslation(PhysBody, _position + PositionDisplacement, _orientation); // Center of mass is at the center of the object // DEBUG DEBUG PhysicsScene.PE.SetCenterOfMassByPosRot(Linkset.LinksetRoot.PhysBody, _position, _orientation); @@ -1615,6 +1634,7 @@ public sealed class BSPrim : BSPhysObject } // Assign directly to the local variables so the normal set actions do not happen + entprop.Position -= PositionDisplacement; _position = entprop.Position; _orientation = entprop.Rotation; _velocity = entprop.Velocity; -- cgit v1.1