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 (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.

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 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)
m_moveActor.SetVelocityAndTarget(vel, vel, true /* inTaintTime */);
DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, vel);
ForceVelocity = vel;
});
{
// m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */);
m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false /* inTaintTime */);
}
}
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);
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; }

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.
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,18 +259,29 @@ public abstract class BSPhysObject : PhysicsActor
public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force);
public abstract void AddForce(bool inTaintTime, OMV.Vector3 force);
// PhysicsActor.SetMomentum
// All the physics engined use this as a way of forcing the velocity to something.
public override void SetMomentum(OMV.Vector3 momentum)
// PhysicsActor.Velocity
public override OMV.Vector3 Velocity
{
// This doesn't just set Velocity=momentum because velocity is ramped up to (see MoveActor)
RawVelocity = momentum;
PhysScene.TaintedObject(LocalID, TypeName + ".SetMomentum", delegate()
get { return RawVelocity; }
set
{
// 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;
});
}
}
// 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 {
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 {
get { return RawVelocity; }
set {