diff options
author | Robert Adams | 2012-12-22 17:09:40 -0800 |
---|---|---|
committer | Robert Adams | 2012-12-22 17:09:40 -0800 |
commit | 30807b81cc9f91917fd3b4bf8dc24a1622013afa (patch) | |
tree | e3e4984f6f8af806c7da6801640e4832ecd88ff8 /OpenSim | |
parent | BulletSim: remove post step one-time taints (doesn't make any sense). Rename ... (diff) | |
download | opensim-SC-30807b81cc9f91917fd3b4bf8dc24a1622013afa.zip opensim-SC-30807b81cc9f91917fd3b4bf8dc24a1622013afa.tar.gz opensim-SC-30807b81cc9f91917fd3b4bf8dc24a1622013afa.tar.bz2 opensim-SC-30807b81cc9f91917fd3b4bf8dc24a1622013afa.tar.xz |
BulletSim: modify avatar motor code to make falling movement better. Clean up some usages. Disable motor when done.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 75 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 2 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | 3 |
3 files changed, 45 insertions, 35 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 01cd279..8e059ee 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -158,6 +158,7 @@ public sealed class BSCharacter : BSPhysObject | |||
158 | _velocityMotor.Reset(); | 158 | _velocityMotor.Reset(); |
159 | _velocityMotor.SetCurrent(_velocity); | 159 | _velocityMotor.SetCurrent(_velocity); |
160 | _velocityMotor.SetTarget(_velocity); | 160 | _velocityMotor.SetTarget(_velocity); |
161 | _velocityMotor.Enabled = false; | ||
161 | 162 | ||
162 | // This will enable or disable the flying buoyancy of the avatar. | 163 | // This will enable or disable the flying buoyancy of the avatar. |
163 | // Needs to be reset especially when an avatar is recreated after crossing a region boundry. | 164 | // Needs to be reset especially when an avatar is recreated after crossing a region boundry. |
@@ -435,13 +436,13 @@ public sealed class BSCharacter : BSPhysObject | |||
435 | OMV.Vector3 targetVel = value; | 436 | OMV.Vector3 targetVel = value; |
436 | PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate() | 437 | PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate() |
437 | { | 438 | { |
438 | float timeStep = 0.089f; // DEBUG DEBUG FIX FIX FIX | ||
439 | _velocityMotor.Reset(); | 439 | _velocityMotor.Reset(); |
440 | _velocityMotor.SetTarget(targetVel); | 440 | _velocityMotor.SetTarget(targetVel); |
441 | _velocityMotor.SetCurrent(_velocity); | 441 | _velocityMotor.SetCurrent(_velocity); |
442 | // Compute a velocity value and make sure it gets pushed into the avatar. | 442 | _velocityMotor.Enabled = true; |
443 | // This makes sure the avatar will start from a stop. | 443 | |
444 | ForceVelocity = _velocityMotor.Step(timeStep); | 444 | // Make sure a property update happens next step so the motor gets incorporated. |
445 | BulletSimAPI.PushUpdate2(PhysBody.ptr); | ||
445 | }); | 446 | }); |
446 | } | 447 | } |
447 | } | 448 | } |
@@ -450,12 +451,15 @@ public sealed class BSCharacter : BSPhysObject | |||
450 | get { return _velocity; } | 451 | get { return _velocity; } |
451 | set { | 452 | set { |
452 | _velocity = value; | 453 | _velocity = value; |
453 | _velocityMotor.Reset(); | ||
454 | _velocityMotor.SetCurrent(_velocity); | ||
455 | _velocityMotor.SetTarget(_velocity); | ||
456 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 454 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
457 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() | 455 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() |
458 | { | 456 | { |
457 | _velocityMotor.Reset(); | ||
458 | _velocityMotor.SetCurrent(_velocity); | ||
459 | _velocityMotor.SetTarget(_velocity); | ||
460 | // Even though the motor is initialized, it's not used and the velocity goes straight into the avatar. | ||
461 | _velocityMotor.Enabled = false; | ||
462 | |||
459 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 463 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
460 | ForceVelocity = _velocity; | 464 | ForceVelocity = _velocity; |
461 | }); | 465 | }); |
@@ -466,6 +470,7 @@ public sealed class BSCharacter : BSPhysObject | |||
466 | set { | 470 | set { |
467 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); | 471 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); |
468 | 472 | ||
473 | _velocity = value; | ||
469 | // Depending on whether the avatar is moving or not, change the friction | 474 | // Depending on whether the avatar is moving or not, change the friction |
470 | // to keep the avatar from slipping around | 475 | // to keep the avatar from slipping around |
471 | if (_velocity.Length() == 0) | 476 | if (_velocity.Length() == 0) |
@@ -486,7 +491,6 @@ public sealed class BSCharacter : BSPhysObject | |||
486 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); | 491 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); |
487 | } | 492 | } |
488 | } | 493 | } |
489 | _velocity = value; | ||
490 | // Remember the set velocity so we can suppress the reduction by friction, ... | 494 | // Remember the set velocity so we can suppress the reduction by friction, ... |
491 | _appliedVelocity = value; | 495 | _appliedVelocity = value; |
492 | 496 | ||
@@ -746,39 +750,42 @@ public sealed class BSCharacter : BSPhysObject | |||
746 | _velocity = entprop.Velocity; | 750 | _velocity = entprop.Velocity; |
747 | _acceleration = entprop.Acceleration; | 751 | _acceleration = entprop.Acceleration; |
748 | _rotationalVelocity = entprop.RotationalVelocity; | 752 | _rotationalVelocity = entprop.RotationalVelocity; |
753 | |||
749 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. | 754 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. |
750 | PositionSanityCheck(true); | 755 | PositionSanityCheck(true); |
751 | 756 | ||
757 | if (_velocityMotor.Enabled) | ||
758 | { | ||
759 | // TODO: Decide if the step parameters should be changed depending on the avatar's | ||
760 | // state (flying, colliding, ...). | ||
761 | |||
762 | OMV.Vector3 stepVelocity = _velocityMotor.Step(PhysicsScene.LastTimeStep); | ||
763 | |||
764 | // If falling, we keep the world's downward vector no matter what the other axis specify. | ||
765 | if (!Flying && !IsColliding) | ||
766 | { | ||
767 | stepVelocity.Z = entprop.Velocity.Z; | ||
768 | DetailLog("{0},BSCharacter.UpdateProperties,taint,overrideStepZWithWorldZ,stepVel={1}", LocalID, stepVelocity); | ||
769 | } | ||
770 | |||
771 | // If the user has said stop and we've stopped applying velocity correction, | ||
772 | // the motor can be turned off. Set the velocity to zero so the zero motion is sent to the viewer. | ||
773 | if (_velocityMotor.TargetValue.ApproxEquals(OMV.Vector3.Zero, 0.01f) && _velocityMotor.ErrorIsZero) | ||
774 | { | ||
775 | stepVelocity = OMV.Vector3.Zero; | ||
776 | _velocityMotor.Enabled = false; | ||
777 | DetailLog("{0},BSCharacter.UpdateProperties,taint,disableVelocityMotor,m={1}", LocalID, _velocityMotor); | ||
778 | } | ||
779 | |||
780 | _velocity = stepVelocity; | ||
781 | entprop.Velocity = _velocity; | ||
782 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); | ||
783 | } | ||
784 | |||
752 | // remember the current and last set values | 785 | // remember the current and last set values |
753 | LastEntityProperties = CurrentEntityProperties; | 786 | LastEntityProperties = CurrentEntityProperties; |
754 | CurrentEntityProperties = entprop; | 787 | CurrentEntityProperties = entprop; |
755 | 788 | ||
756 | // Avatars don't respond to world friction, etc. They only go the speed I tell them too. | ||
757 | // Special kludge here for falling. Even though the target velocity might not have a | ||
758 | // Z component, the avatar could be falling (walked off a ledge, stopped flying, ...) | ||
759 | // and that velocity component must be retained. | ||
760 | float timeStep = 0.089f; // DEBUG DEBUG FIX FIX FIX | ||
761 | OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep); | ||
762 | // Remove next line so avatars don't fly up forever. DEBUG DEBUG this is only temporary. | ||
763 | // stepVelocity.Z += entprop.Velocity.Z; | ||
764 | _velocity = stepVelocity; | ||
765 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); | ||
766 | /* | ||
767 | OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep); | ||
768 | OMV.Vector3 avVel = new OMV.Vector3(stepVelocity.X, stepVelocity.Y, entprop.Velocity.Z); | ||
769 | _velocity = avVel; | ||
770 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel); | ||
771 | |||
772 | if (entprop.Velocity != LastEntityProperties.Velocity) | ||
773 | { | ||
774 | // Changes in the velocity are suppressed in avatars. | ||
775 | // That's just the way they are defined. | ||
776 | OMV.Vector3 avVel = new OMV.Vector3(_appliedVelocity.X, _appliedVelocity.Y, entprop.Velocity.Z); | ||
777 | _velocity = avVel; | ||
778 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel); | ||
779 | } | ||
780 | */ | ||
781 | |||
782 | // Tell the linkset about value changes | 789 | // Tell the linkset about value changes |
783 | Linkset.UpdateProperties(this, true); | 790 | Linkset.UpdateProperties(this, true); |
784 | 791 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 19de1e5..c76f869 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -153,7 +153,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
153 | public abstract OMV.Quaternion ForceOrientation { get; set; } | 153 | public abstract OMV.Quaternion ForceOrientation { get; set; } |
154 | 154 | ||
155 | // The system is telling us the velocity it wants to move at. | 155 | // The system is telling us the velocity it wants to move at. |
156 | protected OMV.Vector3 m_targetVelocity; | 156 | // protected OMV.Vector3 m_targetVelocity; // use the definition in PhysicsActor |
157 | public override OMV.Vector3 TargetVelocity | 157 | public override OMV.Vector3 TargetVelocity |
158 | { | 158 | { |
159 | get { return m_targetVelocity; } | 159 | get { return m_targetVelocity; } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index c084ab4..9a7e965 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt | |||
@@ -112,6 +112,9 @@ Test avatar walking up stairs. How does compare with SL. | |||
112 | Debounce avatar contact so legs don't keep folding up when standing. | 112 | Debounce avatar contact so legs don't keep folding up when standing. |
113 | Implement LSL physics controls. Like STATUS_ROTATE_X. | 113 | Implement LSL physics controls. Like STATUS_ROTATE_X. |
114 | Add border extensions to terrain to help region crossings and objects leaving region. | 114 | Add border extensions to terrain to help region crossings and objects leaving region. |
115 | Use a different capsule shape for avatar when sitting | ||
116 | LL uses a pyrimidal shape scaled by the avatar's bounding box | ||
117 | http://wiki.secondlife.com/wiki/File:Avmeshforms.png | ||
115 | 118 | ||
116 | Performance test with lots of avatars. Can BulletSim support a thousand? | 119 | Performance test with lots of avatars. Can BulletSim support a thousand? |
117 | Optimize collisions in C++: only send up to the object subscribed to collisions. | 120 | Optimize collisions in C++: only send up to the object subscribed to collisions. |