diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 113 |
1 files changed, 58 insertions, 55 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 57c5898..8e059ee 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -88,8 +88,8 @@ public sealed class BSCharacter : BSPhysObject | |||
88 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, | 88 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, |
89 | // replace with the default values. | 89 | // replace with the default values. |
90 | _size = size; | 90 | _size = size; |
91 | if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth; | 91 | if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth; |
92 | if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth; | 92 | if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth; |
93 | 93 | ||
94 | // A motor to control the acceleration and deceleration of the avatar movement. | 94 | // A motor to control the acceleration and deceleration of the avatar movement. |
95 | // _velocityMotor = new BSVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f); | 95 | // _velocityMotor = new BSVMotor("BSCharacter.Velocity", 3f, 5f, BSMotor.InfiniteVector, 1f); |
@@ -108,8 +108,8 @@ public sealed class BSCharacter : BSPhysObject | |||
108 | _velocity = OMV.Vector3.Zero; | 108 | _velocity = OMV.Vector3.Zero; |
109 | _appliedVelocity = OMV.Vector3.Zero; | 109 | _appliedVelocity = OMV.Vector3.Zero; |
110 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); | 110 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); |
111 | _currentFriction = PhysicsScene.Params.avatarStandingFriction; | 111 | _currentFriction = BSParam.AvatarStandingFriction; |
112 | _avatarDensity = PhysicsScene.Params.avatarDensity; | 112 | _avatarDensity = BSParam.AvatarDensity; |
113 | 113 | ||
114 | // The dimensions of the avatar capsule are kept in the scale. | 114 | // The dimensions of the avatar capsule are kept in the scale. |
115 | // Physics creates a unit capsule which is scaled by the physics engine. | 115 | // Physics creates a unit capsule which is scaled by the physics engine. |
@@ -134,6 +134,8 @@ public sealed class BSCharacter : BSPhysObject | |||
134 | // called when this character is being destroyed and the resources should be released | 134 | // called when this character is being destroyed and the resources should be released |
135 | public override void Destroy() | 135 | public override void Destroy() |
136 | { | 136 | { |
137 | base.Destroy(); | ||
138 | |||
137 | DetailLog("{0},BSCharacter.Destroy", LocalID); | 139 | DetailLog("{0},BSCharacter.Destroy", LocalID); |
138 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() | 140 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() |
139 | { | 141 | { |
@@ -156,19 +158,20 @@ public sealed class BSCharacter : BSPhysObject | |||
156 | _velocityMotor.Reset(); | 158 | _velocityMotor.Reset(); |
157 | _velocityMotor.SetCurrent(_velocity); | 159 | _velocityMotor.SetCurrent(_velocity); |
158 | _velocityMotor.SetTarget(_velocity); | 160 | _velocityMotor.SetTarget(_velocity); |
161 | _velocityMotor.Enabled = false; | ||
159 | 162 | ||
160 | // This will enable or disable the flying buoyancy of the avatar. | 163 | // This will enable or disable the flying buoyancy of the avatar. |
161 | // 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. |
162 | Flying = _flying; | 165 | Flying = _flying; |
163 | 166 | ||
164 | BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.avatarRestitution); | 167 | BulletSimAPI.SetRestitution2(PhysBody.ptr, BSParam.AvatarRestitution); |
165 | BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin); | 168 | BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin); |
166 | BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); | 169 | BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); |
167 | BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold); | 170 | BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, BSParam.ContactProcessingThreshold); |
168 | if (PhysicsScene.Params.ccdMotionThreshold > 0f) | 171 | if (BSParam.CcdMotionThreshold > 0f) |
169 | { | 172 | { |
170 | BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold); | 173 | BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, BSParam.CcdMotionThreshold); |
171 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); | 174 | BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, BSParam.CcdSweptSphereRadius); |
172 | } | 175 | } |
173 | 176 | ||
174 | UpdatePhysicalMassProperties(RawMass); | 177 | UpdatePhysicalMassProperties(RawMass); |
@@ -208,8 +211,8 @@ public sealed class BSCharacter : BSPhysObject | |||
208 | _size = value; | 211 | _size = value; |
209 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, | 212 | // Old versions of ScenePresence passed only the height. If width and/or depth are zero, |
210 | // replace with the default values. | 213 | // replace with the default values. |
211 | if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth; | 214 | if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth; |
212 | if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth; | 215 | if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth; |
213 | 216 | ||
214 | ComputeAvatarScale(_size); | 217 | ComputeAvatarScale(_size); |
215 | ComputeAvatarVolumeAndMass(); | 218 | ComputeAvatarVolumeAndMass(); |
@@ -433,13 +436,13 @@ public sealed class BSCharacter : BSPhysObject | |||
433 | OMV.Vector3 targetVel = value; | 436 | OMV.Vector3 targetVel = value; |
434 | PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate() | 437 | PhysicsScene.TaintedObject("BSCharacter.setTargetVelocity", delegate() |
435 | { | 438 | { |
436 | float timeStep = 0.089f; // DEBUG DEBUG FIX FIX FIX | ||
437 | _velocityMotor.Reset(); | 439 | _velocityMotor.Reset(); |
438 | _velocityMotor.SetTarget(targetVel); | 440 | _velocityMotor.SetTarget(targetVel); |
439 | _velocityMotor.SetCurrent(_velocity); | 441 | _velocityMotor.SetCurrent(_velocity); |
440 | // Compute a velocity value and make sure it gets pushed into the avatar. | 442 | _velocityMotor.Enabled = true; |
441 | // This makes sure the avatar will start from a stop. | 443 | |
442 | ForceVelocity = _velocityMotor.Step(timeStep); | 444 | // Make sure a property update happens next step so the motor gets incorporated. |
445 | BulletSimAPI.PushUpdate2(PhysBody.ptr); | ||
443 | }); | 446 | }); |
444 | } | 447 | } |
445 | } | 448 | } |
@@ -448,12 +451,15 @@ public sealed class BSCharacter : BSPhysObject | |||
448 | get { return _velocity; } | 451 | get { return _velocity; } |
449 | set { | 452 | set { |
450 | _velocity = value; | 453 | _velocity = value; |
451 | _velocityMotor.Reset(); | ||
452 | _velocityMotor.SetCurrent(_velocity); | ||
453 | _velocityMotor.SetTarget(_velocity); | ||
454 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 454 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
455 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() | 455 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() |
456 | { | 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 | |||
457 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 463 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
458 | ForceVelocity = _velocity; | 464 | ForceVelocity = _velocity; |
459 | }); | 465 | }); |
@@ -464,27 +470,27 @@ public sealed class BSCharacter : BSPhysObject | |||
464 | set { | 470 | set { |
465 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); | 471 | PhysicsScene.AssertInTaintTime("BSCharacter.ForceVelocity"); |
466 | 472 | ||
473 | _velocity = value; | ||
467 | // 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 |
468 | // to keep the avatar from slipping around | 475 | // to keep the avatar from slipping around |
469 | if (_velocity.Length() == 0) | 476 | if (_velocity.Length() == 0) |
470 | { | 477 | { |
471 | if (_currentFriction != PhysicsScene.Params.avatarStandingFriction) | 478 | if (_currentFriction != BSParam.AvatarStandingFriction) |
472 | { | 479 | { |
473 | _currentFriction = PhysicsScene.Params.avatarStandingFriction; | 480 | _currentFriction = BSParam.AvatarStandingFriction; |
474 | if (PhysBody.HasPhysicalBody) | 481 | if (PhysBody.HasPhysicalBody) |
475 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); | 482 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); |
476 | } | 483 | } |
477 | } | 484 | } |
478 | else | 485 | else |
479 | { | 486 | { |
480 | if (_currentFriction != PhysicsScene.Params.avatarFriction) | 487 | if (_currentFriction != BSParam.AvatarFriction) |
481 | { | 488 | { |
482 | _currentFriction = PhysicsScene.Params.avatarFriction; | 489 | _currentFriction = BSParam.AvatarFriction; |
483 | if (PhysBody.HasPhysicalBody) | 490 | if (PhysBody.HasPhysicalBody) |
484 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); | 491 | BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction); |
485 | } | 492 | } |
486 | } | 493 | } |
487 | _velocity = value; | ||
488 | // 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, ... |
489 | _appliedVelocity = value; | 495 | _appliedVelocity = value; |
490 | 496 | ||
@@ -561,12 +567,6 @@ public sealed class BSCharacter : BSPhysObject | |||
561 | set { | 567 | set { |
562 | _flying = value; | 568 | _flying = value; |
563 | 569 | ||
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 | |||
570 | // simulate flying by changing the effect of gravity | 570 | // simulate flying by changing the effect of gravity |
571 | Buoyancy = ComputeBuoyancyFromFlying(_flying); | 571 | Buoyancy = ComputeBuoyancyFromFlying(_flying); |
572 | } | 572 | } |
@@ -750,39 +750,42 @@ public sealed class BSCharacter : BSPhysObject | |||
750 | _velocity = entprop.Velocity; | 750 | _velocity = entprop.Velocity; |
751 | _acceleration = entprop.Acceleration; | 751 | _acceleration = entprop.Acceleration; |
752 | _rotationalVelocity = entprop.RotationalVelocity; | 752 | _rotationalVelocity = entprop.RotationalVelocity; |
753 | |||
753 | // 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. |
754 | PositionSanityCheck(true); | 755 | PositionSanityCheck(true); |
755 | 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 | |||
756 | // remember the current and last set values | 785 | // remember the current and last set values |
757 | LastEntityProperties = CurrentEntityProperties; | 786 | LastEntityProperties = CurrentEntityProperties; |
758 | CurrentEntityProperties = entprop; | 787 | CurrentEntityProperties = entprop; |
759 | 788 | ||
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 | // Remove next line so avatars don't fly up forever. DEBUG DEBUG this is only temporary. | ||
767 | // stepVelocity.Z += entprop.Velocity.Z; | ||
768 | _velocity = stepVelocity; | ||
769 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity); | ||
770 | /* | ||
771 | OMV.Vector3 stepVelocity = _velocityMotor.Step(timeStep); | ||
772 | OMV.Vector3 avVel = new OMV.Vector3(stepVelocity.X, stepVelocity.Y, entprop.Velocity.Z); | ||
773 | _velocity = avVel; | ||
774 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel); | ||
775 | |||
776 | if (entprop.Velocity != LastEntityProperties.Velocity) | ||
777 | { | ||
778 | // Changes in the velocity are suppressed in avatars. | ||
779 | // That's just the way they are defined. | ||
780 | OMV.Vector3 avVel = new OMV.Vector3(_appliedVelocity.X, _appliedVelocity.Y, entprop.Velocity.Z); | ||
781 | _velocity = avVel; | ||
782 | BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel); | ||
783 | } | ||
784 | */ | ||
785 | |||
786 | // Tell the linkset about value changes | 789 | // Tell the linkset about value changes |
787 | Linkset.UpdateProperties(this, true); | 790 | Linkset.UpdateProperties(this, true); |
788 | 791 | ||