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.
melanie
Robert Adams 2016-11-13 11:19:54 -08:00
parent b6329fb784
commit e13ff5a392
4 changed files with 48 additions and 52 deletions

View File

@ -108,10 +108,6 @@ public class BSActorAvatarMove : BSActor
{ {
if (m_velocityMotor != null) if (m_velocityMotor != null)
{ {
// if (targ == OMV.Vector3.Zero)
// Util.PrintCallStack();
//
// Console.WriteLine("SetVelocityAndTarget, {0} {1}", vel, targ);
m_velocityMotor.Reset(); m_velocityMotor.Reset();
m_velocityMotor.SetTarget(targ); m_velocityMotor.SetTarget(targ);
m_velocityMotor.SetCurrent(vel); m_velocityMotor.SetCurrent(vel);
@ -128,7 +124,7 @@ public class BSActorAvatarMove : BSActor
m_waitingForLowVelocityForStationary = true; 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() private void ActivateAvatarMove()
{ {
if (m_velocityMotor == null) 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) private void Mover(float timeStep)
{ {
// Don't do movement while the object is selected. // Don't do movement while the object is selected.

View File

@ -449,6 +449,7 @@ public sealed class BSCharacter : BSPhysObject
public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } }
public override OMV.Vector3 CenterOfMass { 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. // Sets the target in the motor. This starts the changing of the avatar's velocity.
public override OMV.Vector3 TargetVelocity public override OMV.Vector3 TargetVelocity
{ {
@ -459,7 +460,7 @@ public sealed class BSCharacter : BSPhysObject
set set
{ {
DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value); DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value);
m_targetVelocity = value; base.m_targetVelocity = value;
OMV.Vector3 targetVel = value; OMV.Vector3 targetVel = value;
if (_setAlwaysRun && !_flying) if (_setAlwaysRun && !_flying)
targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 1f); targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 1f);
@ -472,32 +473,12 @@ public sealed class BSCharacter : BSPhysObject
public override OMV.Vector3 Velocity { public override OMV.Vector3 Velocity {
get { return RawVelocity; } get { return RawVelocity; }
set { 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 */); {
// m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */);
DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, vel); m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false /* inTaintTime */);
ForceVelocity = vel;
});
} }
} base.Velocity = value;
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);
} }
} }
@ -506,11 +487,23 @@ public sealed class BSCharacter : BSPhysObject
{ {
if (m_moveActor != null) 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); 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 { public override OMV.Vector3 Torque {
get { return RawTorque; } get { return RawTorque; }

View File

@ -230,15 +230,22 @@ public abstract class BSPhysObject : PhysicsActor
// Update the physical location and motion of the object. Called with data from Bullet. // Update the physical location and motion of the object. Called with data from Bullet.
public abstract void UpdateProperties(EntityProperties entprop); 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; } 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; } 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; } 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; } 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; } 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; } 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; } public OMV.Vector3 RawRotationalVelocity { get; set; }
// RawForce is a constant force applied to object (see Force { set; } ) // RawForce is a constant force applied to object (see Force { set; } )
@ -252,18 +259,29 @@ public abstract class BSPhysObject : PhysicsActor
public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force); public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force);
public abstract void AddForce(bool inTaintTime, OMV.Vector3 force); public abstract void AddForce(bool inTaintTime, OMV.Vector3 force);
// PhysicsActor.SetMomentum // PhysicsActor.Velocity
// All the physics engined use this as a way of forcing the velocity to something. public override OMV.Vector3 Velocity
public override void SetMomentum(OMV.Vector3 momentum)
{ {
// This doesn't just set Velocity=momentum because velocity is ramped up to (see MoveActor) get { return RawVelocity; }
RawVelocity = momentum; set
PhysScene.TaintedObject(LocalID, TypeName + ".SetMomentum", delegate()
{ {
// DetailLog("{0},BSPrim.SetMomentum,taint,vel={1}", LocalID, RawVelocity); // 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; ForceVelocity = RawVelocity;
}); });
} }
}
// PhysicsActor.SetMomentum
// 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.Velocity = momentum;
}
public override OMV.Vector3 RotationalVelocity { public override OMV.Vector3 RotationalVelocity {
get { get {

View File

@ -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 { public override OMV.Vector3 ForceVelocity {
get { return RawVelocity; } get { return RawVelocity; }
set { set {