aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorRobert Adams2012-12-21 10:00:03 -0800
committerRobert Adams2012-12-21 10:00:03 -0800
commit8c99f63239702bcdb8f1e0efa57efc91c98fc3d7 (patch)
treeea049bbeb4f40060a8f8595f0a872e5a1ecd1cb7
parentBulletSim: Better detail logging of VMotor actions. (diff)
downloadopensim-SC_OLD-8c99f63239702bcdb8f1e0efa57efc91c98fc3d7.zip
opensim-SC_OLD-8c99f63239702bcdb8f1e0efa57efc91c98fc3d7.tar.gz
opensim-SC_OLD-8c99f63239702bcdb8f1e0efa57efc91c98fc3d7.tar.bz2
opensim-SC_OLD-8c99f63239702bcdb8f1e0efa57efc91c98fc3d7.tar.xz
BulletSim: avatar movement smoothed with motor that modifies avatar velocity to target velocity. Fails in incorporating physical world effects (gravity) so avatar doesn't fly correctly.
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs77
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs8
2 files changed, 81 insertions, 4 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 4dd6264..695896e 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -69,6 +69,8 @@ public sealed class BSCharacter : BSPhysObject
69 private OMV.Vector3 _appliedVelocity; // the last velocity applied to the avatar 69 private OMV.Vector3 _appliedVelocity; // the last velocity applied to the avatar
70 private float _currentFriction; // the friction currently being used (changed by setVelocity). 70 private float _currentFriction; // the friction currently being used (changed by setVelocity).
71 71
72 private BSVMotor _velocityMotor;
73
72 private OMV.Vector3 _PIDTarget; 74 private OMV.Vector3 _PIDTarget;
73 private bool _usePID; 75 private bool _usePID;
74 private float _PIDTau; 76 private float _PIDTau;
@@ -89,6 +91,18 @@ public sealed class BSCharacter : BSPhysObject
89 if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth; 91 if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth;
90 if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth; 92 if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth;
91 93
94 // A motor to control the acceleration and deceleration of the avatar movement.
95 // _velocityMotor = new BSVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f);
96 // _velocityMotor = new BSPIDVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f);
97 // Infinite decay and timescale values so motor only changes current to target values.
98 _velocityMotor = new BSVMotor("BSCharacter.Velocity",
99 0.2f, // time scale
100 BSMotor.Infinite, // decay time scale
101 BSMotor.InfiniteVector, // friction timescale
102 1f // efficiency
103 );
104 _velocityMotor.PhysicsScene = PhysicsScene; // DEBUG DEBUG so motor will output detail log messages.
105
92 _flying = isFlying; 106 _flying = isFlying;
93 _orientation = OMV.Quaternion.Identity; 107 _orientation = OMV.Quaternion.Identity;
94 _velocity = OMV.Vector3.Zero; 108 _velocity = OMV.Vector3.Zero;
@@ -138,6 +152,10 @@ public sealed class BSCharacter : BSPhysObject
138 ForcePosition = _position; 152 ForcePosition = _position;
139 // Set the velocity and compute the proper friction 153 // Set the velocity and compute the proper friction
140 ForceVelocity = _velocity; 154 ForceVelocity = _velocity;
155 // Setting the current and target in the motor will cause it to start computing any deceleration.
156 _velocityMotor.Reset();
157 _velocityMotor.SetCurrent(_velocity);
158 _velocityMotor.SetTarget(_velocity);
141 159
142 // This will enable or disable the flying buoyancy of the avatar. 160 // This will enable or disable the flying buoyancy of the avatar.
143 // Needs to be reset especially when an avatar is recreated after crossing a region boundry. 161 // Needs to be reset especially when an avatar is recreated after crossing a region boundry.
@@ -239,6 +257,7 @@ public sealed class BSCharacter : BSPhysObject
239 public override void ZeroMotion(bool inTaintTime) 257 public override void ZeroMotion(bool inTaintTime)
240 { 258 {
241 _velocity = OMV.Vector3.Zero; 259 _velocity = OMV.Vector3.Zero;
260 _velocityMotor.Zero();
242 _acceleration = OMV.Vector3.Zero; 261 _acceleration = OMV.Vector3.Zero;
243 _rotationalVelocity = OMV.Vector3.Zero; 262 _rotationalVelocity = OMV.Vector3.Zero;
244 263
@@ -400,10 +419,38 @@ public sealed class BSCharacter : BSPhysObject
400 419
401 public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } 420 public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } }
402 public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } 421 public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } }
422
423 // Sets the target in the motor. This starts the changing of the avatar's velocity.
424 public override OMV.Vector3 TargetVelocity
425 {
426 get
427 {
428 return _velocityMotor.TargetValue;
429 }
430 set
431 {
432 DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value);
433 OMV.Vector3 targetVel = value;
434 PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate()
435 {
436 float timeStep = 0.089f; // DEBUG DEBUG FIX FIX FIX
437 _velocityMotor.Reset();
438 _velocityMotor.SetTarget(targetVel);
439 _velocityMotor.SetCurrent(_velocity);
440 // Compute a velocity value and make sure it gets pushed into the avatar.
441 // This makes sure the avatar will start from a stop.
442 ForceVelocity = _velocityMotor.Step(timeStep);
443 });
444 }
445 }
446 // Directly setting velocity means this is what the user really wants now.
403 public override OMV.Vector3 Velocity { 447 public override OMV.Vector3 Velocity {
404 get { return _velocity; } 448 get { return _velocity; }
405 set { 449 set {
406 _velocity = value; 450 _velocity = value;
451 _velocityMotor.Reset();
452 _velocityMotor.SetCurrent(_velocity);
453 _velocityMotor.SetTarget(_velocity);
407 // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); 454 // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity);
408 PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() 455 PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate()
409 { 456 {
@@ -415,6 +462,8 @@ public sealed class BSCharacter : BSPhysObject
415 public override OMV.Vector3 ForceVelocity { 462 public override OMV.Vector3 ForceVelocity {
416 get { return _velocity; } 463 get { return _velocity; }
417 set { 464 set {
465 PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity");
466
418 // Depending on whether the avatar is moving or not, change the friction 467 // Depending on whether the avatar is moving or not, change the friction
419 // to keep the avatar from slipping around 468 // to keep the avatar from slipping around
420 if (_velocity.Length() == 0) 469 if (_velocity.Length() == 0)
@@ -511,6 +560,13 @@ public sealed class BSCharacter : BSPhysObject
511 get { return _flying; } 560 get { return _flying; }
512 set { 561 set {
513 _flying = value; 562 _flying = value;
563
564 // Velocity movement is different when flying: flying velocity degrades over time.
565 if (_flying)
566 _velocityMotor.TargetValueDecayTimeScale = 1f;
567 else
568 _velocityMotor.TargetValueDecayTimeScale = BSMotor.Infinite;
569
514 // simulate flying by changing the effect of gravity 570 // simulate flying by changing the effect of gravity
515 Buoyancy = ComputeBuoyancyFromFlying(_flying); 571 Buoyancy = ComputeBuoyancyFromFlying(_flying);
516 } 572 }
@@ -581,7 +637,10 @@ public sealed class BSCharacter : BSPhysObject
581 } 637 }
582 public override float ForceBuoyancy { 638 public override float ForceBuoyancy {
583 get { return _buoyancy; } 639 get { return _buoyancy; }
584 set { _buoyancy = value; 640 set {
641 PhysicsScene.AssertInTaintTime("BSCharacter.ForceBuoyancy");
642
643 _buoyancy = value;
585 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 644 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
586 // Buoyancy is faked by changing the gravity applied to the object 645 // Buoyancy is faked by changing the gravity applied to the object
587 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 646 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
@@ -698,6 +757,21 @@ public sealed class BSCharacter : BSPhysObject
698 LastEntityProperties = CurrentEntityProperties; 757 LastEntityProperties = CurrentEntityProperties;
699 CurrentEntityProperties = entprop; 758 CurrentEntityProperties = entprop;
700 759
760 // Avatars don't respond to world friction, etc. They only go the speed I tell them too.
761 // Special kludge here for falling. Even though the target velocity might not have a
762 // Z component, the avatar could be falling (walked off a ledge, stopped flying, ...)
763 // and that velocity component must be retained.
764 float timeStep = 0.089f; // DEBUG DEBUG FIX FIX FIX
765 OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep);
766 stepVelocity.Z += entprop.Velocity.Z;
767 _velocity = stepVelocity;
768 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
769 /*
770 OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep);
771 OMV.Vector3 avVel = new OMV.Vector3(stepVelocity.X, stepVelocity.Y, entprop.Velocity.Z);
772 _velocity = avVel;
773 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel);
774
701 if (entprop.Velocity != LastEntityProperties.Velocity) 775 if (entprop.Velocity != LastEntityProperties.Velocity)
702 { 776 {
703 // Changes in the velocity are suppressed in avatars. 777 // Changes in the velocity are suppressed in avatars.
@@ -706,6 +780,7 @@ public sealed class BSCharacter : BSPhysObject
706 _velocity = avVel; 780 _velocity = avVel;
707 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel); 781 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel);
708 } 782 }
783 */
709 784
710 // Tell the linkset about value changes 785 // Tell the linkset about value changes
711 Linkset.UpdateProperties(this, true); 786 Linkset.UpdateProperties(this, true);
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 1c6f946..68a0db6 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -532,16 +532,18 @@ public sealed class BSPrim : BSPhysObject
532 PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() 532 PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate()
533 { 533 {
534 // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); 534 // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity);
535 if (PhysBody.HasPhysicalBody) 535 ForceVelocity = _velocity;
536 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
537 }); 536 });
538 } 537 }
539 } 538 }
540 public override OMV.Vector3 ForceVelocity { 539 public override OMV.Vector3 ForceVelocity {
541 get { return _velocity; } 540 get { return _velocity; }
542 set { 541 set {
542 PhysicsScene.AssertInTaintTime("BSPrim.ForceVelocity");
543
543 _velocity = value; 544 _velocity = value;
544 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); 545 if (PhysBody.HasPhysicalBody)
546 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
545 } 547 }
546 } 548 }
547 public override OMV.Vector3 Torque { 549 public override OMV.Vector3 Torque {