From c1371ab786a699ce91693e6e575bb81144a79c57 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 23 Jan 2013 08:28:36 -0800 Subject: [PATCH] BulletSim: working on COM --- .../Physics/BulletSPlugin/BSApiTemplate.cs | 19 +++++++++++++++++++ .../BulletSPlugin/BSLinksetCompound.cs | 7 ++++--- .../Region/Physics/BulletSPlugin/BSPrim.cs | 15 +++++++++++---- .../Physics/BulletSPlugin/BulletSimTODO.txt | 2 ++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index bc163eb946..2828cab23d 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -140,6 +140,25 @@ public struct EntityProperties public Vector3 Velocity; public Vector3 Acceleration; public Vector3 RotationalVelocity; + + public override string ToString() + { + StringBuilder buff = new StringBuilder(); + buff.Append(""); + return buff.ToString(); + } } // Format of this structure must match the definition in the C++ code diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs index 0077da766a..d8e4028506 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs @@ -377,7 +377,7 @@ public sealed class BSLinksetCompound : BSLinkset // Constraint linksets are rebuilt every time. // Note that this works for rebuilding just the root after a linkset is taken apart. // Called at taint time!! - private bool disableCOM = true; // disable until we get this debugged + private bool disableCOM = false; // disable until we get this debugged private void RecomputeLinksetCompound() { try @@ -400,8 +400,9 @@ public sealed class BSLinksetCompound : BSLinkset } // DEBUG DEBUG else { - centerOfMass = ComputeLinksetGeometricCenter(); - centerDisplacement = centerOfMass - LinksetRoot.RawPosition; + centerOfMass = ComputeLinksetCenterOfMass(); + // 'centerDisplacement' is the value to *add* to all the shape offsets + centerDisplacement = LinksetRoot.RawPosition - centerOfMass; // Since we're displacing the center of the shape, we need to move the body in the world LinksetRoot.PositionDisplacement = centerDisplacement; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index b37a1f8522..dad7250960 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -336,6 +336,7 @@ public sealed class BSPrim : BSPhysObject } } } + /* Disable. Presume whoever is setting displacement is already adjusting position, etc. // 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. @@ -355,6 +356,7 @@ public sealed class BSPrim : BSPhysObject }); } } + */ // 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. @@ -371,11 +373,11 @@ public sealed class BSPrim : BSPhysObject return ret; } - float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); + float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(RawPosition); OMV.Vector3 upForce = OMV.Vector3.Zero; if (RawPosition.Z < terrainHeight) { - DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); + DetailLog("{0},BSPrim.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, RawPosition, terrainHeight); float targetHeight = terrainHeight + (Size.Z / 2f); // If the object is below ground it just has to be moved up because pushing will // not get it through the terrain @@ -1637,7 +1639,11 @@ public sealed class BSPrim : BSPhysObject // entprop.RotationalVelocity = OMV.Vector3.Zero; } + DetailLog("{0},BSPrim.UpdateProperties,entry,entprop={1}", LocalID, entprop); // DEBUG DEBUG + // Assign directly to the local variables so the normal set actions do not happen + + // Undo any center-of-mass displacement that might have been done. entprop.Position -= PositionDisplacement; _position = entprop.Position; _orientation = entprop.Rotation; @@ -1645,6 +1651,8 @@ public sealed class BSPrim : BSPhysObject _acceleration = entprop.Acceleration; _rotationalVelocity = entprop.RotationalVelocity; + DetailLog("{0},BSPrim.UpdateProperties,afterAssign,entprop={1}", LocalID, entprop); // DEBUG DEBUG + // The sanity check can change the velocity and/or position. if (IsPhysical && PositionSanityCheck(true)) { @@ -1653,8 +1661,7 @@ public sealed class BSPrim : BSPhysObject } OMV.Vector3 direction = OMV.Vector3.UnitX * _orientation; // DEBUG DEBUG DEBUG - DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},dir={3},vel={4},rotVel={5}", - LocalID, _position, _orientation, direction, _velocity, _rotationalVelocity); + DetailLog("{0},BSPrim.UpdateProperties,call,entProp={1},dir={2}", LocalID, entprop, direction); // remember the current and last set values LastEntityProperties = CurrentEntityProperties; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 41bab2601d..801f6908ee 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -1,5 +1,7 @@ CURRENT PRIORITIES ================================================= +Deleting a linkset while standing on the root will leave the physical shape of the root behind. + Not sure if it is because standing on it. Done with large prim linksets. Child movement in linkset (don't rebuild linkset) Vehicle angular vertical attraction vehicle angular banking