From e13ff5a39233fd871e69f9ace23b4559cdfdcb7f Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 13 Nov 2016 11:19:54 -0800 Subject: [PATCH] BulletSim: update avatar velocity setting to the new TargetVelocity pattern. Now PhysicsActor.Velocity.set and PhysicsActor.SetMomentum do the same thing of setting the instantanious avatar velocity. PhysicsActor.TargetVelocity sets a velocity target and the movement motor is used to accelerate the' avatar to that velocity. --- .../BulletS/BSActorAvatarMove.cs | 8 +--- .../PhysicsModules/BulletS/BSCharacter.cs | 47 ++++++++----------- .../PhysicsModules/BulletS/BSPhysObject.cs | 34 ++++++++++---- .../Region/PhysicsModules/BulletS/BSPrim.cs | 11 ----- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs index 79ee00f4ca..40c6b983b0 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs @@ -108,10 +108,6 @@ public class BSActorAvatarMove : BSActor { if (m_velocityMotor != null) { -// if (targ == OMV.Vector3.Zero) -// Util.PrintCallStack(); -// -// Console.WriteLine("SetVelocityAndTarget, {0} {1}", vel, targ); m_velocityMotor.Reset(); m_velocityMotor.SetTarget(targ); m_velocityMotor.SetCurrent(vel); @@ -128,7 +124,7 @@ public class BSActorAvatarMove : BSActor m_waitingForLowVelocityForStationary = true; } - // If a movement motor has not been created, create one and start the hovering. + // If a movement motor has not been created, create one and start the movement private void ActivateAvatarMove() { if (m_velocityMotor == null) @@ -161,7 +157,7 @@ public class BSActorAvatarMove : BSActor } } - // Called just before the simulation step. Update the vertical position for hoverness. + // Called just before the simulation step. private void Mover(float timeStep) { // Don't do movement while the object is selected. diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs index 757f06ccd3..6322695e17 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs @@ -449,6 +449,7 @@ public sealed class BSCharacter : BSPhysObject public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } + // PhysicsActor.TargetVelocity // Sets the target in the motor. This starts the changing of the avatar's velocity. public override OMV.Vector3 TargetVelocity { @@ -459,7 +460,7 @@ public sealed class BSCharacter : BSPhysObject set { DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value); - m_targetVelocity = value; + base.m_targetVelocity = value; OMV.Vector3 targetVel = value; if (_setAlwaysRun && !_flying) targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 1f); @@ -472,32 +473,12 @@ public sealed class BSCharacter : BSPhysObject public override OMV.Vector3 Velocity { get { return RawVelocity; } set { - RawVelocity = value; - OMV.Vector3 vel = RawVelocity; - - DetailLog("{0}: set Velocity = {1}", LocalID, value); - - PhysScene.TaintedObject(LocalID, "BSCharacter.setVelocity", delegate() + if (m_moveActor != null) { - if (m_moveActor != null) - m_moveActor.SetVelocityAndTarget(vel, vel, true /* inTaintTime */); - - DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, vel); - ForceVelocity = vel; - }); - } - } - - public override OMV.Vector3 ForceVelocity { - get { return RawVelocity; } - set { - PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity"); -// Util.PrintCallStack(); - DetailLog("{0}: set ForceVelocity = {1}", LocalID, value); - - RawVelocity = value; - PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity); - PhysScene.PE.Activate(PhysBody, true); + // m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */); + m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false /* inTaintTime */); + } + base.Velocity = value; } } @@ -506,11 +487,23 @@ public sealed class BSCharacter : BSPhysObject { if (m_moveActor != null) { - m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */); + // m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */); + m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false /* inTaintTime */); } base.SetMomentum(momentum); } + public override OMV.Vector3 ForceVelocity { + get { return RawVelocity; } + set { + PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity"); + DetailLog("{0}: BSCharacter.ForceVelocity.set = {1}", LocalID, value); + + RawVelocity = Util.ClampV(value, BSParam.MaxLinearVelocity); + PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity); + PhysScene.PE.Activate(PhysBody, true); + } + } public override OMV.Vector3 Torque { get { return RawTorque; } diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs index 3682455154..a846869983 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs @@ -230,15 +230,22 @@ public abstract class BSPhysObject : PhysicsActor // Update the physical location and motion of the object. Called with data from Bullet. public abstract void UpdateProperties(EntityProperties entprop); + // The position value as known by BulletSim. Does not effect the physics engine. public virtual OMV.Vector3 RawPosition { get; set; } + // Set position in BulletSim and the physics engined to a value immediately. Must be called at taint time. public abstract OMV.Vector3 ForcePosition { get; set; } + // The orientation value as known by BulletSim. Does not effect the physics engine. public virtual OMV.Quaternion RawOrientation { get; set; } + // Set orientation in BulletSim and the physics engine to a value immediately. Must be called at taint time. public abstract OMV.Quaternion ForceOrientation { get; set; } + // The velocity value as known by BulletSim. Does not effect the physics engine. public virtual OMV.Vector3 RawVelocity { get; set; } + // Set velocity in BulletSim and the physics engined to a value immediately. Must be called at taint time. public abstract OMV.Vector3 ForceVelocity { get; set; } + // The rotational velocity value as known by BulletSim. Does not effect the physics engine. public OMV.Vector3 RawRotationalVelocity { get; set; } // RawForce is a constant force applied to object (see Force { set; } ) @@ -252,17 +259,28 @@ public abstract class BSPhysObject : PhysicsActor public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force); public abstract void AddForce(bool inTaintTime, OMV.Vector3 force); + // PhysicsActor.Velocity + public override OMV.Vector3 Velocity + { + get { return RawVelocity; } + set + { + // This sets the velocity now. BSCharacter will override to clear target velocity + // before calling this. + RawVelocity = value; + PhysScene.TaintedObject(LocalID, TypeName + ".SetVelocity", delegate () { + // DetailLog("{0},BSPhysObject.Velocity.set,vel={1}", LocalID, RawVelocity); + ForceVelocity = RawVelocity; + }); + } + } + // PhysicsActor.SetMomentum - // All the physics engined use this as a way of forcing the velocity to something. + // All the physics engines use this as a way of forcing the velocity to something. + // BSCharacter overrides this so it can set the target velocity to zero before calling this. 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; - }); + this.Velocity = momentum; } public override OMV.Vector3 RotationalVelocity { diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs index 78a617d731..db2b9db987 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs @@ -787,17 +787,6 @@ public class BSPrim : BSPhysObject } } } - public override OMV.Vector3 Velocity { - get { return RawVelocity; } - set { - RawVelocity = value; - PhysScene.TaintedObject(LocalID, "BSPrim.setVelocity", delegate() - { - // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, RawVelocity); - ForceVelocity = RawVelocity; - }); - } - } public override OMV.Vector3 ForceVelocity { get { return RawVelocity; } set {