From 3b0df52d10c157cd2711d64ef9007d2afccbd468 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 20 Jan 2013 09:33:13 -0800 Subject: BulletSim: modify motors to return correction rather than current value to better use them for incremental updates. Modify prim and character to use the new motors. Simplify the vehicle linear movement code to just update the velocity directly or the basic movement. --- OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 478aeab..696c4bd 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -198,7 +198,8 @@ public sealed class BSCharacter : BSPhysObject // TODO: Decide if the step parameters should be changed depending on the avatar's // state (flying, colliding, ...). There is code in ODE to do this. - OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep); + _velocityMotor.Step(timeStep); + OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; // If falling, we keep the world's downward vector no matter what the other axis specify. if (!Flying && !IsColliding) -- cgit v1.1 From 3c4868f61362c2c86cef9f98e197362f57ca627b Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 20 Jan 2013 19:13:18 -0800 Subject: BulletSim: fix problem of avatar sliding very slowly occasionally after stopping walking. Consolidate movement tests into the one prestep motion action --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 75 ++++++++++++---------- 1 file changed, 41 insertions(+), 34 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 696c4bd..cd279e3 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -56,6 +56,7 @@ public sealed class BSCharacter : BSPhysObject private int _physicsActorType; private bool _isPhysical; private bool _flying; + private bool _wasWalking; // 'true' if the avatar was walking/moving last frame private bool _setAlwaysRun; private bool _throttleUpdates; private bool _floatOnWater; @@ -83,6 +84,7 @@ public sealed class BSCharacter : BSPhysObject _position = pos; _flying = isFlying; + _wasWalking = true; // causes first step to initialize standing _orientation = OMV.Quaternion.Identity; _velocity = OMV.Vector3.Zero; _buoyancy = ComputeBuoyancyFromFlying(isFlying); @@ -199,25 +201,51 @@ public sealed class BSCharacter : BSPhysObject // state (flying, colliding, ...). There is code in ODE to do this. _velocityMotor.Step(timeStep); - OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; - // If falling, we keep the world's downward vector no matter what the other axis specify. - if (!Flying && !IsColliding) + // If we're not supposed to be moving, make sure things are zero. + if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f)) { - stepVelocity.Z = _velocity.Z; - // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); + if (_wasWalking) + { + _velocityMotor.Zero(); + _velocity = OMV.Vector3.Zero; + PhysicsScene.PE.SetLinearVelocity(PhysBody, OMV.Vector3.Zero); + _currentFriction = BSParam.AvatarStandingFriction; + PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); + // DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); + } + _wasWalking = false; } + else + { + OMV.Vector3 stepVelocity = _velocityMotor.CurrentValue; + + if (_currentFriction != BSParam.AvatarFriction) + { + // Probably starting up walking. Set friction to moving friction. + _currentFriction = BSParam.AvatarFriction; + PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); + } - // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. - OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass; + // If falling, we keep the world's downward vector no matter what the other axis specify. + if (!Flying && !IsColliding) + { + stepVelocity.Z = _velocity.Z; + // DetailLog("{0},BSCharacter.MoveMotor,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); + } + + // 'stepVelocity' is now the speed we'd like the avatar to move in. Turn that into an instantanous force. + OMV.Vector3 moveForce = (stepVelocity - _velocity) * Mass; - // Should we check for move force being small and forcing velocity to zero? + // Should we check for move force being small and forcing velocity to zero? - // Add special movement force to allow avatars to walk up stepped surfaces. - moveForce += WalkUpStairs(); + // Add special movement force to allow avatars to walk up stepped surfaces. + moveForce += WalkUpStairs(); - // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); - PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); + // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); + PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); + _wasWalking = true; + } }); } @@ -560,27 +588,6 @@ public sealed class BSCharacter : BSPhysObject PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); _velocity = value; - // Depending on whether the avatar is moving or not, change the friction - // to keep the avatar from slipping around - if (_velocity.Length() == 0) - { - if (_currentFriction != BSParam.AvatarStandingFriction) - { - _currentFriction = BSParam.AvatarStandingFriction; - if (PhysBody.HasPhysicalBody) - PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); - } - } - else - { - if (_currentFriction != BSParam.AvatarFriction) - { - _currentFriction = BSParam.AvatarFriction; - if (PhysBody.HasPhysicalBody) - PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); - } - } - PhysicsScene.PE.SetLinearVelocity(PhysBody, _velocity); PhysicsScene.PE.Activate(PhysBody, true); } @@ -855,7 +862,7 @@ public sealed class BSCharacter : BSPhysObject _position = entprop.Position; _orientation = entprop.Rotation; - // Smooth velocity. OpenSimulator is very sensitive to changes in velocity of the avatar + // Smooth velocity. OpenSimulator is VERY sensitive to changes in velocity of the avatar // and will send agent updates to the clients if velocity changes by more than // 0.001m/s. Bullet introduces a lot of jitter in the velocity which causes many // extra updates. -- cgit v1.1 From 52b341e2e24384395fddc7d32fd66358f5062468 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 20 Jan 2013 22:35:42 -0800 Subject: BulletSim: More aggressive as setting character velocity to zero when should be standing. Modify angular force routines to be the same pattern as linear force routines. BulletSim vehicle turning is scaled like SL and is DIFFERENT THAN ODE!! Fix some bugs in BSMotor dealing with the motor going to zero. Add a bunch of parameters: MaxLinearVelocity, MaxAngularVelocity, MaxAddForceMagnitude, VehicleMaxLinearVelocity, VehicleMaxAngularVelocity, and most of the values are defaulted to values that are larger than in SL. Use the new parameters in BSPrim, BSCharacter and BSDynamic. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index cd279e3..a9e16e6 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -200,20 +200,36 @@ public sealed class BSCharacter : BSPhysObject // TODO: Decide if the step parameters should be changed depending on the avatar's // state (flying, colliding, ...). There is code in ODE to do this. + // COMMENTARY: when the user is making the avatar walk, except for falling, the velocity + // specified for the avatar is the one that should be used. For falling, if the avatar + // is not flying and is not colliding then it is presumed to be falling and the Z + // component is not fooled with (thus allowing gravity to do its thing). + // When the avatar is standing, though, the user has specified a velocity of zero and + // the avatar should be standing. But if the avatar is pushed by something in the world + // (raising elevator platform, moving vehicle, ...) the avatar should be allowed to + // move. Thus, the velocity cannot be forced to zero. The problem is that small velocity + // errors can creap in and the avatar will slowly float off in some direction. + // So, the problem is that, when an avatar is standing, we cannot tell creaping error + // from real pushing.OMV.Vector3.Zero; + // The code below keeps setting the velocity to zero hoping the world will keep pushing. + _velocityMotor.Step(timeStep); // If we're not supposed to be moving, make sure things are zero. - if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f)) + if (_velocityMotor.ErrorIsZero() && _velocityMotor.TargetValue == OMV.Vector3.Zero && IsColliding) { - if (_wasWalking) + // The avatar shouldn't be moving + _velocityMotor.Zero(); + ZeroMotion(true /* inTaintTime */); + + // Standing has more friction on the ground + if (_currentFriction != BSParam.AvatarStandingFriction) { - _velocityMotor.Zero(); - _velocity = OMV.Vector3.Zero; - PhysicsScene.PE.SetLinearVelocity(PhysBody, OMV.Vector3.Zero); _currentFriction = BSParam.AvatarStandingFriction; PhysicsScene.PE.SetFriction(PhysBody, _currentFriction); - // DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); } + DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1}", LocalID, _velocityMotor.TargetValue); + _wasWalking = false; } else @@ -242,7 +258,7 @@ public sealed class BSCharacter : BSPhysObject // Add special movement force to allow avatars to walk up stepped surfaces. moveForce += WalkUpStairs(); - // DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); + DetailLog("{0},BSCharacter.MoveMotor,move,stepVel={1},vel={2},mass={3},moveForce={4}", LocalID, stepVelocity, _velocity, Mass, moveForce); PhysicsScene.PE.ApplyCentralImpulse(PhysBody, moveForce); _wasWalking = true; } -- cgit v1.1 From 471c4778639aec60078e6cee7c964682c959f033 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 21 Jan 2013 15:58:22 -0800 Subject: BulletSim: allow changing position and rotation of a child of a linkset without rebuilding the whole compound shape. Should make vehicles move smoother. --- OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index a9e16e6..7603254 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -899,7 +899,7 @@ public sealed class BSCharacter : BSPhysObject CurrentEntityProperties = entprop; // Tell the linkset about value changes - Linkset.UpdateProperties(this, true); + Linkset.UpdateProperties(UpdatedProperties.EntPropUpdates, this); // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. // base.RequestPhysicsterseUpdate(); -- cgit v1.1