From 5ab151c2d69277b8c528b8ebe94d2b0d2312a2fc Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 8 Aug 2012 13:48:49 -0700 Subject: BulletSim: add avatar code to keep avatars from ending up trapped under the terrain --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 56 ++++++++++------------ OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs | 13 ++--- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 4 +- OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 26 +++++----- bin/OpenSimDefaults.ini | 2 +- 5 files changed, 47 insertions(+), 54 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index d4f5c63..8149a53 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -205,6 +205,8 @@ public class BSCharacter : PhysicsActor } set { _position = value; + PositionSanityCheck(); + _scene.TaintedObject(delegate() { DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); @@ -212,6 +214,28 @@ public class BSCharacter : PhysicsActor }); } } + + // 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. + // Returns 'true' of the position was made sane by some action. + private bool PositionSanityCheck() + { + bool ret = false; + + // If below the ground, move the avatar up + float terrainHeight = Scene.GetTerrainHeightAtXYZ(_position); + if (_position.Z < terrainHeight) + { + DetailLog("{0},PositionAdjustUnderGround,call,pos={1},orient={2}", LocalID, _position, _orientation); + _position.Z = terrainHeight + 2.0f; + ret = true; + } + + // TODO: check for out of bounds + + return ret; + } + public override float Mass { get { return _mass; @@ -456,42 +480,12 @@ public class BSCharacter : PhysicsActor // the world that things have changed. public void UpdateProperties(EntityProperties entprop) { - /* - bool changed = false; - // we assign to the local variables so the normal set action does not happen - if (_position != entprop.Position) { - _position = entprop.Position; - changed = true; - } - if (_orientation != entprop.Rotation) { - _orientation = entprop.Rotation; - changed = true; - } - if (_velocity != entprop.Velocity) { - _velocity = entprop.Velocity; - changed = true; - } - if (_acceleration != entprop.Acceleration) { - _acceleration = entprop.Acceleration; - changed = true; - } - if (_rotationalVelocity != entprop.RotationalVelocity) { - _rotationalVelocity = entprop.RotationalVelocity; - changed = true; - } - if (changed) { - // m_log.DebugFormat("{0}: UpdateProperties: id={1}, c={2}, pos={3}, rot={4}", LogHeader, LocalID, changed, _position, _orientation); - // Avatar movement is not done by generating this event. There is code in the heartbeat - // loop that updates avatars. - // base.RequestPhysicsterseUpdate(); - } - */ _position = entprop.Position; _orientation = entprop.Rotation; _velocity = entprop.Velocity; _acceleration = entprop.Acceleration; _rotationalVelocity = entprop.RotationalVelocity; - // Avatars don't report theirr changes the usual way. Changes are checked for in the heartbeat loop. + // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. // base.RequestPhysicsterseUpdate(); } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs index 6f8430c..d19c4b8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinkset.cs @@ -296,13 +296,13 @@ public class BSLinkset DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", m_linksetRoot.LocalID, m_linksetRoot.LocalID, childPrim.LocalID); BSConstraint constrain = m_scene.Constraints.CreateConstraint( m_scene.World, m_linksetRoot.Body, childPrim.Body, - // childRelativePosition, - // childRelativeRotation, + childRelativePosition, + childRelativeRotation, OMV.Vector3.Zero, - OMV.Quaternion.Identity, - OMV.Vector3.Zero, - OMV.Quaternion.Identity + -childRelativeRotation ); + + // zero linear and angular limits makes the objects unable to move in relation to each other constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); @@ -339,7 +339,8 @@ public class BSLinkset // Invoke the detailed logger and output something if it's enabled. private void DebugLog(string msg, params Object[] args) { - m_scene.Logger.DebugFormat(msg, args); + if (m_scene.ShouldDebugLog) + m_scene.Logger.DebugFormat(msg, args); } // Invoke the detailed logger and output something if it's enabled. diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 11868bc..98b69b1 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -42,7 +42,7 @@ public sealed class BSPrim : PhysicsActor private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly string LogHeader = "[BULLETS PRIM]"; - private void DebugLog(string mm, params Object[] xx) { if (_scene.shouldDebugLog) m_log.DebugFormat(mm, xx); } + private void DebugLog(string mm, params Object[] xx) { if (_scene.ShouldDebugLog) m_log.DebugFormat(mm, xx); } private IMesh _mesh; private PrimitiveBaseShape _pbs; @@ -1338,7 +1338,6 @@ public sealed class BSPrim : PhysicsActor base.RequestPhysicsterseUpdate(); } - /* else { // For debugging, we also report the movement of children @@ -1346,7 +1345,6 @@ public sealed class BSPrim : PhysicsActor LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, entprop.Acceleration, entprop.RotationalVelocity); } - */ } // I've collided with something diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index 0e257b6..117086a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -73,7 +73,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static readonly string LogHeader = "[BULLETS SCENE]"; - public void DebugLog(string mm, params Object[] xx) { if (shouldDebugLog) m_log.DebugFormat(mm, xx); } + public void DebugLog(string mm, params Object[] xx) { if (ShouldDebugLog) m_log.DebugFormat(mm, xx); } public string BulletSimVersion = "?"; @@ -169,7 +169,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters ConfigurationParameters[] m_params; GCHandle m_paramsHandle; - public bool shouldDebugLog { get; private set; } + public bool ShouldDebugLog { get; private set; } private BulletSimAPI.DebugLogCallback m_DebugLogCallbackHandle; @@ -812,12 +812,12 @@ public class BSScene : PhysicsScene, IPhysicsParameters private struct ParameterDefn { - public string name; - public string desc; - public float defaultValue; - public ParamUser userParam; - public ParamGet getter; - public ParamSet setter; + public string name; // string name of the parameter + public string desc; // a short description of what the parameter means + public float defaultValue; // default value if not specified anywhere else + public ParamUser userParam; // get the value from the configuration file + public ParamGet getter; // return the current value stored for this parameter + public ParamSet setter; // set the current value for this parameter public ParameterDefn(string n, string d, float v, ParamUser u, ParamGet g, ParamSet s) { name = n; @@ -834,7 +834,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters // To add a new externally referencable/settable parameter, add the paramter storage // location somewhere in the program and make an entry in this table with the // getters and setters. - // To add a new variable, it is easiest to find an existing definition and copy it. + // It is easiest to find an existing definition and copy it. // Parameter values are floats. Booleans are converted to a floating value. // // A ParameterDefn() takes the following parameters: @@ -870,7 +870,7 @@ public class BSScene : PhysicsScene, IPhysicsParameters (s) => { return (float)s.m_meshLOD; }, (s,p,l,v) => { s.m_meshLOD = (int)v; } ), new ParameterDefn("SculptLOD", "Level of detail to render sculpties (32, 16, 8 or 4. 32=most detailed)", - 32, + 32f, (s,cf,p,v) => { s.m_sculptLOD = cf.GetInt(p, (int)v); }, (s) => { return (float)s.m_sculptLOD; }, (s,p,l,v) => { s.m_sculptLOD = (int)v; } ), @@ -1106,9 +1106,9 @@ public class BSScene : PhysicsScene, IPhysicsParameters (s,p,l,v) => { s.m_detailedStatsStep = (int)v; } ), new ParameterDefn("ShouldDebugLog", "Enables detailed DEBUG log statements", ConfigurationParameters.numericFalse, - (s,cf,p,v) => { s.shouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); }, - (s) => { return s.NumericBool(s.shouldDebugLog); }, - (s,p,l,v) => { s.shouldDebugLog = s.BoolNumeric(v); } ), + (s,cf,p,v) => { s.ShouldDebugLog = cf.GetBoolean(p, s.BoolNumeric(v)); }, + (s) => { return s.NumericBool(s.ShouldDebugLog); }, + (s,p,l,v) => { s.ShouldDebugLog = s.BoolNumeric(v); } ), }; diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index a27e775..dcbd90c 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -939,7 +939,7 @@ FixedTimeStep = .01667 MaxCollisionsPerFrame = 2048 - MaxUpdatesPerFrame = 2048 + MaxUpdatesPerFrame = 8192 [RemoteAdmin] enabled = false -- cgit v1.1