diff options
author | Robert Adams | 2016-01-02 17:36:42 -0800 |
---|---|---|
committer | Robert Adams | 2016-01-10 14:53:55 -0800 |
commit | d4e88f8883eca60021ec852a97507c2b94685452 (patch) | |
tree | 9722b54c85119556b516c79d3fa58359a56ee2f0 /OpenSim/Region/PhysicsModules/BulletS | |
parent | change muckwaddle name contributors.txt (diff) | |
download | opensim-SC_OLD-d4e88f8883eca60021ec852a97507c2b94685452.zip opensim-SC_OLD-d4e88f8883eca60021ec852a97507c2b94685452.tar.gz opensim-SC_OLD-d4e88f8883eca60021ec852a97507c2b94685452.tar.bz2 opensim-SC_OLD-d4e88f8883eca60021ec852a97507c2b94685452.tar.xz |
BulletSim: tweaking so avatar can be pushed. In particular, llPushObject,
which called BSCharacter.AddForce, can now move a character.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS')
5 files changed, 57 insertions, 18 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs index 0191893..12ffacb 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs | |||
@@ -187,12 +187,25 @@ public class BSActorAvatarMove : BSActor | |||
187 | 187 | ||
188 | if (m_controllingPrim.IsColliding) | 188 | if (m_controllingPrim.IsColliding) |
189 | { | 189 | { |
190 | // If we are colliding with a stationary object, presume we're standing and don't move around | 190 | // if colliding with something stationary and we're not doing volume detect . |
191 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) | 191 | if (!m_controllingPrim.ColliderIsMoving && !m_controllingPrim.ColliderIsVolumeDetect) |
192 | { | 192 | { |
193 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); | 193 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,totalForce={1}, vel={2}", /* DEBUG */ |
194 | m_controllingPrim.IsStationary = true; | 194 | m_controllingPrim.LocalID, m_physicsScene.PE.GetTotalForce(m_controllingPrim.PhysBody), m_controllingPrim.Velocity); /* DEBUG */ |
195 | m_controllingPrim.ZeroMotion(true /* inTaintTime */); | 195 | // If velocity is very small, assume it is movement creep and suppress it. |
196 | // Applying push forces (Character.AddForce) should move the avatar and that is only seen here as velocity. | ||
197 | if ( (m_controllingPrim.Velocity.LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) | ||
198 | && (m_physicsScene.PE.GetTotalForce(m_controllingPrim.PhysBody).LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) ) | ||
199 | { | ||
200 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,zeroingMotion", m_controllingPrim.LocalID); | ||
201 | m_controllingPrim.IsStationary = true; | ||
202 | m_controllingPrim.ZeroMotion(true /* inTaintTime */); | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,collidingWithStationary,not zeroing because velocity={1}", | ||
207 | m_controllingPrim.LocalID, m_controllingPrim.Velocity); | ||
208 | } | ||
196 | } | 209 | } |
197 | 210 | ||
198 | // Standing has more friction on the ground | 211 | // Standing has more friction on the ground |
@@ -222,8 +235,8 @@ public class BSActorAvatarMove : BSActor | |||
222 | } | 235 | } |
223 | } | 236 | } |
224 | 237 | ||
225 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1},colliding={2}", | 238 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,taint,stopping,target={1},colliding={2},isStationary={3}", |
226 | m_controllingPrim.LocalID, m_velocityMotor.TargetValue, m_controllingPrim.IsColliding); | 239 | m_controllingPrim.LocalID, m_velocityMotor.TargetValue, m_controllingPrim.IsColliding,m_controllingPrim.IsStationary); |
227 | } | 240 | } |
228 | else | 241 | else |
229 | { | 242 | { |
@@ -237,6 +250,8 @@ public class BSActorAvatarMove : BSActor | |||
237 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); | 250 | m_physicsScene.PE.SetFriction(m_controllingPrim.PhysBody, m_controllingPrim.Friction); |
238 | } | 251 | } |
239 | 252 | ||
253 | // If not flying and not colliding, assume falling and keep the downward motion component. | ||
254 | // This check is done here for the next jump test. | ||
240 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) | 255 | if (!m_controllingPrim.Flying && !m_controllingPrim.IsColliding) |
241 | { | 256 | { |
242 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; | 257 | stepVelocity.Z = m_controllingPrim.RawVelocity.Z; |
@@ -267,11 +282,9 @@ public class BSActorAvatarMove : BSActor | |||
267 | } | 282 | } |
268 | else | 283 | else |
269 | { | 284 | { |
270 | |||
271 | // Since we're not affected by anything, the avatar must be falling and we do not want that to be too fast. | 285 | // Since we're not affected by anything, the avatar must be falling and we do not want that to be too fast. |
272 | if (m_controllingPrim.RawVelocity.Z < BSParam.AvatarTerminalVelocity) | 286 | if (m_controllingPrim.RawVelocity.Z < BSParam.AvatarTerminalVelocity) |
273 | { | 287 | { |
274 | |||
275 | stepVelocity.Z = BSParam.AvatarTerminalVelocity; | 288 | stepVelocity.Z = BSParam.AvatarTerminalVelocity; |
276 | } | 289 | } |
277 | else | 290 | else |
@@ -315,7 +328,11 @@ public class BSActorAvatarMove : BSActor | |||
315 | if (m_controllingPrim.IsStationary) | 328 | if (m_controllingPrim.IsStationary) |
316 | { | 329 | { |
317 | entprop.Position = m_controllingPrim.RawPosition; | 330 | entprop.Position = m_controllingPrim.RawPosition; |
318 | entprop.Velocity = OMV.Vector3.Zero; | 331 | // Suppress small movement velocity |
332 | if (entprop.Velocity.LengthSquared() < BSParam.AvatarStopZeroThresholdSquared) { | ||
333 | m_physicsScene.DetailLog("{0},BSCharacter.MoveMotor,OnPreUpdate,zeroing velocity={1}", m_controllingPrim.LocalID, entprop.Velocity); | ||
334 | entprop.Velocity = OMV.Vector3.Zero; | ||
335 | } | ||
319 | m_physicsScene.PE.SetTranslation(m_controllingPrim.PhysBody, entprop.Position, entprop.Rotation); | 336 | m_physicsScene.PE.SetTranslation(m_controllingPrim.PhysBody, entprop.Position, entprop.Rotation); |
320 | } | 337 | } |
321 | 338 | ||
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs index bd3c7ac..ab9cc27 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs | |||
@@ -652,13 +652,16 @@ public sealed class BSCharacter : BSPhysObject | |||
652 | public override void AddForce(OMV.Vector3 force, bool pushforce) | 652 | public override void AddForce(OMV.Vector3 force, bool pushforce) |
653 | { | 653 | { |
654 | // Since this force is being applied in only one step, make this a force per second. | 654 | // Since this force is being applied in only one step, make this a force per second. |
655 | OMV.Vector3 addForce = force / PhysScene.LastTimeStep; | 655 | OMV.Vector3 addForce = force; |
656 | 656 | ||
657 | // compensate for density variation | 657 | // The interaction of this force with the simulator rate and collision occurance is tricky. |
658 | // with a adicional parameter to sync with old ode | 658 | // ODE multiplies the force by 100 |
659 | if(pushforce) | 659 | // ubODE multiplies the force by 5.3 |
660 | addForce = addForce * Density * BSParam.DensityScaleFactor * 0.08f;; | 660 | // BulletSim, after much in-world testing, thinks it gets a similar effect by multiplying mass*0.315f |
661 | // This number could be a feature of friction or timing, but it seems to move avatars the same as ubODE | ||
662 | addForce *= Mass * BSParam.AvatarAddForcePushFactor; | ||
661 | 663 | ||
664 | DetailLog("{0},BSCharacter.addForce,call,force={1},addForce={2},push={3},mass={4}", LocalID, force, addForce, pushforce, Mass); | ||
662 | AddForce(addForce, pushforce, false); | 665 | AddForce(addForce, pushforce, false); |
663 | } | 666 | } |
664 | 667 | ||
@@ -666,7 +669,7 @@ public sealed class BSCharacter : BSPhysObject | |||
666 | if (force.IsFinite()) | 669 | if (force.IsFinite()) |
667 | { | 670 | { |
668 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); | 671 | OMV.Vector3 addForce = Util.ClampV(force, BSParam.MaxAddForceMagnitude); |
669 | // DetailLog("{0},BSCharacter.addForce,call,force={1}", LocalID, addForce); | 672 | // DetailLog("{0},BSCharacter.addForce,call,force={1},push={2},inTaint={3}", LocalID, addForce, pushforce, inTaintTime); |
670 | 673 | ||
671 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.AddForce", delegate() | 674 | PhysScene.TaintedObject(inTaintTime, LocalID, "BSCharacter.AddForce", delegate() |
672 | { | 675 | { |
@@ -674,6 +677,9 @@ public sealed class BSCharacter : BSPhysObject | |||
674 | // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); | 677 | // DetailLog("{0},BSCharacter.addForce,taint,force={1}", LocalID, addForce); |
675 | if (PhysBody.HasPhysicalBody) | 678 | if (PhysBody.HasPhysicalBody) |
676 | { | 679 | { |
680 | // Bullet adds this central force to the total force for this tick. | ||
681 | // Deep down in Bullet: | ||
682 | // linearVelocity += totalForce / mass * timeStep; | ||
677 | PhysScene.PE.ApplyCentralForce(PhysBody, addForce); | 683 | PhysScene.PE.ApplyCentralForce(PhysBody, addForce); |
678 | PhysScene.PE.Activate(PhysBody, true); | 684 | PhysScene.PE.Activate(PhysBody, true); |
679 | } | 685 | } |
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs b/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs index c296008..aea69d7 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSParam.cs | |||
@@ -149,7 +149,9 @@ public static class BSParam | |||
149 | public static float AvatarFlyingGroundUpForce { get; private set; } | 149 | public static float AvatarFlyingGroundUpForce { get; private set; } |
150 | public static float AvatarTerminalVelocity { get; private set; } | 150 | public static float AvatarTerminalVelocity { get; private set; } |
151 | public static float AvatarContactProcessingThreshold { get; private set; } | 151 | public static float AvatarContactProcessingThreshold { get; private set; } |
152 | public static float AvatarAddForcePushFactor { get; private set; } | ||
152 | public static float AvatarStopZeroThreshold { get; private set; } | 153 | public static float AvatarStopZeroThreshold { get; private set; } |
154 | public static float AvatarStopZeroThresholdSquared { get; private set; } | ||
153 | public static int AvatarJumpFrames { get; private set; } | 155 | public static int AvatarJumpFrames { get; private set; } |
154 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } | 156 | public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } |
155 | public static float AvatarStepHeight { get; private set; } | 157 | public static float AvatarStepHeight { get; private set; } |
@@ -230,6 +232,8 @@ public static class BSParam | |||
230 | public static float PID_D { get; private set; } // derivative | 232 | public static float PID_D { get; private set; } // derivative |
231 | public static float PID_P { get; private set; } // proportional | 233 | public static float PID_P { get; private set; } // proportional |
232 | 234 | ||
235 | public static float DebugNumber { get; private set; } // A console setable number used for debugging | ||
236 | |||
233 | // Various constants that come from that other virtual world that shall not be named. | 237 | // Various constants that come from that other virtual world that shall not be named. |
234 | public const float MinGravityZ = -1f; | 238 | public const float MinGravityZ = -1f; |
235 | public const float MaxGravityZ = 28f; | 239 | public const float MaxGravityZ = 28f; |
@@ -601,7 +605,7 @@ public static class BSParam | |||
601 | 1.3f ), | 605 | 1.3f ), |
602 | // For historical reasons, density is reported * 100 | 606 | // For historical reasons, density is reported * 100 |
603 | new ParameterDefn<float>("AvatarDensity", "Density of an avatar. Changed on avatar recreation. Scaled times 100.", | 607 | new ParameterDefn<float>("AvatarDensity", "Density of an avatar. Changed on avatar recreation. Scaled times 100.", |
604 | 3500f) , // 3.5 * 100 | 608 | 350f) , // 3.5 * 100 |
605 | new ParameterDefn<float>("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", | 609 | new ParameterDefn<float>("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", |
606 | 0f ), | 610 | 0f ), |
607 | new ParameterDefn<int>("AvatarShape", "Code for avatar physical shape: 0:capsule, 1:cube, 2:ovoid, 2:mesh", | 611 | new ParameterDefn<int>("AvatarShape", "Code for avatar physical shape: 0:capsule, 1:cube, 2:ovoid, 2:mesh", |
@@ -626,8 +630,12 @@ public static class BSParam | |||
626 | -54.0f ), | 630 | -54.0f ), |
627 | new ParameterDefn<float>("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", | 631 | new ParameterDefn<float>("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", |
628 | 0.1f ), | 632 | 0.1f ), |
633 | new ParameterDefn<float>("AvatarAddForcePushFactor", "BSCharacter.AddForce is multiplied by this and mass to be like other physics engines", | ||
634 | 0.315f ), | ||
629 | new ParameterDefn<float>("AvatarStopZeroThreshold", "Movement velocity below which avatar is assumed to be stopped", | 635 | new ParameterDefn<float>("AvatarStopZeroThreshold", "Movement velocity below which avatar is assumed to be stopped", |
630 | 0.1f ), | 636 | 0.1f, |
637 | (s) => { return (float)AvatarStopZeroThreshold; }, | ||
638 | (s,v) => { AvatarStopZeroThreshold = v; AvatarStopZeroThresholdSquared = v * v; } ), | ||
631 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", | 639 | new ParameterDefn<float>("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", |
632 | 1.0f ), | 640 | 1.0f ), |
633 | new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.", | 641 | new ParameterDefn<int>("AvatarJumpFrames", "Number of frames to allow jump forces. Changes jump height.", |
@@ -812,6 +820,9 @@ public static class BSParam | |||
812 | new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", | 820 | new ParameterDefn<float>("LinkConstraintSolverIterations", "Number of solver iterations when computing constraint. (0 = Bullet default)", |
813 | 40 ), | 821 | 40 ), |
814 | 822 | ||
823 | new ParameterDefn<float>("DebugNumber", "A console setable number sometimes used for debugging", | ||
824 | 1.0f ), | ||
825 | |||
815 | new ParameterDefn<int>("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)", | 826 | new ParameterDefn<int>("PhysicsMetricFrames", "Frames between outputting detailed phys metrics. (0 is off)", |
816 | 0, | 827 | 0, |
817 | (s) => { return s.PhysicsMetricDumpFrames; }, | 828 | (s) => { return s.PhysicsMetricDumpFrames; }, |
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs index 0ad95c4..e8ea604 100755 --- a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs | |||
@@ -239,8 +239,10 @@ public abstract class BSPhysObject : PhysicsActor | |||
239 | public virtual OMV.Vector3 RawVelocity { get; set; } | 239 | public virtual OMV.Vector3 RawVelocity { get; set; } |
240 | public abstract OMV.Vector3 ForceVelocity { get; set; } | 240 | public abstract OMV.Vector3 ForceVelocity { get; set; } |
241 | 241 | ||
242 | // RawForce is a constant force applied to object (see Force { set; } ) | ||
242 | public OMV.Vector3 RawForce { get; set; } | 243 | public OMV.Vector3 RawForce { get; set; } |
243 | public OMV.Vector3 RawTorque { get; set; } | 244 | public OMV.Vector3 RawTorque { get; set; } |
245 | |||
244 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) | 246 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) |
245 | { | 247 | { |
246 | AddAngularForce(force, pushforce, false); | 248 | AddAngularForce(force, pushforce, false); |
@@ -570,7 +572,11 @@ public abstract class BSPhysObject : PhysicsActor | |||
570 | PhysScene.TaintedObject(LocalID, TypeName+".SubscribeEvents", delegate() | 572 | PhysScene.TaintedObject(LocalID, TypeName+".SubscribeEvents", delegate() |
571 | { | 573 | { |
572 | if (PhysBody.HasPhysicalBody) | 574 | if (PhysBody.HasPhysicalBody) |
575 | { | ||
573 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 576 | CurrentCollisionFlags = PhysScene.PE.AddToCollisionFlags(PhysBody, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
577 | DetailLog("{0},{1}.SubscribeEvents,setting collision. ms={2}, collisionFlags={3:x}", | ||
578 | LocalID, TypeName, ms, CurrentCollisionFlags); | ||
579 | } | ||
574 | }); | 580 | }); |
575 | } | 581 | } |
576 | else | 582 | else |
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs b/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs index f02104c..747bad5 100644 --- a/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs +++ b/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs | |||
@@ -679,7 +679,6 @@ namespace OpenSim.Region.PhysicsModule.BulletS | |||
679 | try | 679 | try |
680 | { | 680 | { |
681 | numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount); | 681 | numSubSteps = PE.PhysicsStep(World, timeStep, m_maxSubSteps, m_fixedTimeStep, out updatedEntityCount, out collidersCount); |
682 | |||
683 | } | 682 | } |
684 | catch (Exception e) | 683 | catch (Exception e) |
685 | { | 684 | { |