From c7e4b14a26c2c3a265b268a9e6c43e6c93db205e Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 30 Sep 2016 19:35:44 -0700 Subject: BulletSim: fix problem with avatar velocity going to zero when flying across region boundries. Move code for Velocity, ForceVelocity and SetMomentum to BSPhysObject and have both BSPrim and BSCharacter share the code. --- .../Region/PhysicsModules/BulletS/BSCharacter.cs | 19 ++------ .../Region/PhysicsModules/BulletS/BSPhysObject.cs | 45 +++++++++++++++++- OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs | 53 ++++------------------ 3 files changed, 58 insertions(+), 59 deletions(-) (limited to 'OpenSim/Region/PhysicsModules') diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs index 5ad2136..213f2eb 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs @@ -52,7 +52,6 @@ public sealed class BSCharacter : BSPhysObject private bool _setAlwaysRun; private bool _throttleUpdates; private bool _floatOnWater; - private OMV.Vector3 _rotationalVelocity; private bool _kinematic; private float _buoyancy; @@ -291,7 +290,7 @@ public sealed class BSCharacter : BSPhysObject { RawVelocity = OMV.Vector3.Zero; _acceleration = OMV.Vector3.Zero; - _rotationalVelocity = OMV.Vector3.Zero; + RawRotationalVelocity = OMV.Vector3.Zero; // Zero some other properties directly into the physics engine PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.ZeroMotion", delegate() @@ -303,7 +302,7 @@ public sealed class BSCharacter : BSPhysObject public override void ZeroAngularMotion(bool inTaintTime) { - _rotationalVelocity = OMV.Vector3.Zero; + RawRotationalVelocity = OMV.Vector3.Zero; PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.ZeroMotion", delegate() { @@ -618,14 +617,6 @@ public sealed class BSCharacter : BSPhysObject }); } } - public override OMV.Vector3 RotationalVelocity { - get { return _rotationalVelocity; } - set { _rotationalVelocity = value; } - } - public override OMV.Vector3 ForceRotationalVelocity { - get { return _rotationalVelocity; } - set { _rotationalVelocity = value; } - } public override bool Kinematic { get { return _kinematic; } set { _kinematic = value; } @@ -716,8 +707,6 @@ public sealed class BSCharacter : BSPhysObject public override void AddAngularForce(bool inTaintTime, OMV.Vector3 force) { } - public override void SetMomentum(OMV.Vector3 momentum) { - } // The avatar's physical shape (whether capsule or cube) is unit sized. BulletSim sets // the scale of that unit shape to create the avatars full size. @@ -841,7 +830,7 @@ public sealed class BSCharacter : BSPhysObject RawVelocity = entprop.Velocity; _acceleration = entprop.Acceleration; - _rotationalVelocity = entprop.RotationalVelocity; + RawRotationalVelocity = entprop.RotationalVelocity; // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. if (PositionSanityCheck(true)) @@ -861,7 +850,7 @@ public sealed class BSCharacter : BSPhysObject // PhysScene.PostUpdate(this); DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", - LocalID, RawPosition, RawOrientation, RawVelocity, _acceleration, _rotationalVelocity); + LocalID, RawPosition, RawOrientation, RawVelocity, _acceleration, RawRotationalVelocity); } } } diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs index bb21f0c..7c6f213 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs @@ -239,6 +239,8 @@ public abstract class BSPhysObject : PhysicsActor public virtual OMV.Vector3 RawVelocity { get; set; } public abstract OMV.Vector3 ForceVelocity { get; set; } + public OMV.Vector3 RawRotationalVelocity { get; set; } + // RawForce is a constant force applied to object (see Force { set; } ) public OMV.Vector3 RawForce { get; set; } public OMV.Vector3 RawTorque { get; set; } @@ -250,7 +252,48 @@ public abstract class BSPhysObject : PhysicsActor public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force); public abstract void AddForce(bool inTaintTime, OMV.Vector3 force); - public abstract OMV.Vector3 ForceRotationalVelocity { get; set; } + // PhysicsActor.SetMomentum + // All the physics engined use this as a way of forcing the velocity to something. + public override void SetMomentum(OMV.Vector3 momentum) + { + // This doesn't just set Velocity=momentum because velocity is ramped up to (see MoveActor) + RawVelocity = momentum; + PhysScene.TaintedObject(LocalID, TypeName + ".SetMomentum", delegate() + { + // DetailLog("{0},BSPrim.SetMomentum,taint,vel={1}", LocalID, RawVelocity); + ForceVelocity = RawVelocity; + }); + } + + public override OMV.Vector3 RotationalVelocity { + get { + return RawRotationalVelocity; + } + set { + RawRotationalVelocity = value; + Util.ClampV(RawRotationalVelocity, BSParam.MaxAngularVelocity); + // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); + PhysScene.TaintedObject(LocalID, TypeName + ".setRotationalVelocity", delegate() + { + ForceRotationalVelocity = RawRotationalVelocity; + }); + } + } + public OMV.Vector3 ForceRotationalVelocity { + get { + return RawRotationalVelocity; + } + set { + RawRotationalVelocity = Util.ClampV(value, BSParam.MaxAngularVelocity); + if (PhysBody.HasPhysicalBody) + { + DetailLog("{0},{1}.ForceRotationalVel,taint,rotvel={2}", LocalID, TypeName, RawRotationalVelocity); + PhysScene.PE.SetAngularVelocity(PhysBody, RawRotationalVelocity); + // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); + ActivateIfPhysical(false); + } + } + } public abstract float ForceBuoyancy { get; set; } diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs index fd9b834..78a617d 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs @@ -59,7 +59,6 @@ public class BSPrim : BSPhysObject private bool _setAlwaysRun; private bool _throttleUpdates; private bool _floatOnWater; - private OMV.Vector3 _rotationalVelocity; private bool _kinematic; private float _buoyancy; @@ -90,7 +89,7 @@ public class BSPrim : BSPhysObject RawOrientation = rotation; _buoyancy = 0f; RawVelocity = OMV.Vector3.Zero; - _rotationalVelocity = OMV.Vector3.Zero; + RawRotationalVelocity = OMV.Vector3.Zero; BaseShape = pbs; _isPhysical = pisPhysical; _isVolumeDetect = false; @@ -256,7 +255,7 @@ public class BSPrim : BSPhysObject { RawVelocity = OMV.Vector3.Zero; _acceleration = OMV.Vector3.Zero; - _rotationalVelocity = OMV.Vector3.Zero; + RawRotationalVelocity = OMV.Vector3.Zero; // Zero some other properties in the physics engine PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.ZeroMotion", delegate() @@ -267,15 +266,15 @@ public class BSPrim : BSPhysObject } public override void ZeroAngularMotion(bool inTaintTime) { - _rotationalVelocity = OMV.Vector3.Zero; + RawRotationalVelocity = OMV.Vector3.Zero; // Zero some other properties in the physics engine PhysScene.TaintedObject(inTaintTime, LocalID, "BSPrim.ZeroMotion", delegate() { // DetailLog("{0},BSPrim.ZeroAngularMotion,call,rotVel={1}", LocalID, _rotationalVelocity); if (PhysBody.HasPhysicalBody) { - PhysScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); - PhysScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); + PhysScene.PE.SetInterpolationAngularVelocity(PhysBody, RawRotationalVelocity); + PhysScene.PE.SetAngularVelocity(PhysBody, RawRotationalVelocity); } }); } @@ -426,9 +425,9 @@ public class BSPrim : BSPhysObject RawVelocity = Util.ClampV(RawVelocity, BSParam.MaxLinearVelocity); ret = true; } - if (_rotationalVelocity.LengthSquared() > BSParam.MaxAngularVelocitySquared) + if (RawRotationalVelocity.LengthSquared() > BSParam.MaxAngularVelocitySquared) { - _rotationalVelocity = Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); + RawRotationalVelocity = Util.ClampV(RawRotationalVelocity, BSParam.MaxAngularVelocity); ret = true; } @@ -1008,7 +1007,7 @@ public class BSPrim : BSPhysObject // For good measure, make sure the transform is set through to the motion state ForcePosition = RawPosition; ForceVelocity = RawVelocity; - ForceRotationalVelocity = _rotationalVelocity; + ForceRotationalVelocity = RawRotationalVelocity; // A dynamic object has mass UpdatePhysicalMassProperties(RawMass, false); @@ -1128,35 +1127,6 @@ public class BSPrim : BSPhysObject }); } } - public override OMV.Vector3 RotationalVelocity { - get { - return _rotationalVelocity; - } - set { - _rotationalVelocity = value; - Util.ClampV(_rotationalVelocity, BSParam.MaxAngularVelocity); - // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); - PhysScene.TaintedObject(LocalID, "BSPrim.setRotationalVelocity", delegate() - { - ForceRotationalVelocity = _rotationalVelocity; - }); - } - } - public override OMV.Vector3 ForceRotationalVelocity { - get { - return _rotationalVelocity; - } - set { - _rotationalVelocity = Util.ClampV(value, BSParam.MaxAngularVelocity); - if (PhysBody.HasPhysicalBody) - { - DetailLog("{0},BSPrim.ForceRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); - PhysScene.PE.SetAngularVelocity(PhysBody, _rotationalVelocity); - // PhysicsScene.PE.SetInterpolationAngularVelocity(PhysBody, _rotationalVelocity); - ActivateIfPhysical(false); - } - } - } public override bool Kinematic { get { return _kinematic; } set { _kinematic = value; @@ -1358,9 +1328,6 @@ public class BSPrim : BSPhysObject }); } - public override void SetMomentum(OMV.Vector3 momentum) { - // DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); - } #region Mass Calculation private float CalculateMass() @@ -1930,7 +1897,7 @@ public class BSPrim : BSPhysObject if (entprop.Velocity == OMV.Vector3.Zero || !entprop.Velocity.ApproxEquals(RawVelocity, BSParam.UpdateVelocityChangeThreshold)) RawVelocity = entprop.Velocity; _acceleration = entprop.Acceleration; - _rotationalVelocity = entprop.RotationalVelocity; + RawRotationalVelocity = entprop.RotationalVelocity; // DetailLog("{0},BSPrim.UpdateProperties,afterAssign,entprop={1}", LocalID, entprop); // DEBUG DEBUG @@ -1939,7 +1906,7 @@ public class BSPrim : BSPhysObject { entprop.Position = RawPosition; entprop.Velocity = RawVelocity; - entprop.RotationalVelocity = _rotationalVelocity; + entprop.RotationalVelocity = RawRotationalVelocity; entprop.Acceleration = _acceleration; } -- cgit v1.1