diff options
author | Justin Clark-Casey (justincc) | 2012-02-11 02:26:53 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-02-11 02:28:40 +0000 |
commit | f49897a4195df5fbd00e2c16461bcebb36ce8f72 (patch) | |
tree | 88de016a5c83a09130a0299faedc1ad947a50329 /OpenSim | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC_OLD-f49897a4195df5fbd00e2c16461bcebb36ce8f72.zip opensim-SC_OLD-f49897a4195df5fbd00e2c16461bcebb36ce8f72.tar.gz opensim-SC_OLD-f49897a4195df5fbd00e2c16461bcebb36ce8f72.tar.bz2 opensim-SC_OLD-f49897a4195df5fbd00e2c16461bcebb36ce8f72.tar.xz |
Clamp ODE character velocity. Make ODE falling character 54m/s by default.
If velocity reaches 256 in any vector then bad things happen with ODE, so we now clamp this value.
In addition, a falling avatar is clamped by default at 54 m/s, which is the same as a falling skydiver.
This also appears to be the value used on the linden lab grid.
This should resolve http://opensimulator.org/mantis/view.php?id=5882
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 43 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 11 |
2 files changed, 53 insertions, 1 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs index 7c1c046..6d1f41d 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | |||
@@ -156,6 +156,22 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
156 | internal UUID m_uuid { get; private set; } | 156 | internal UUID m_uuid { get; private set; } |
157 | internal bool bad = false; | 157 | internal bool bad = false; |
158 | 158 | ||
159 | /// <summary> | ||
160 | /// ODE Avatar. | ||
161 | /// </summary> | ||
162 | /// <param name="avName"></param> | ||
163 | /// <param name="parent_scene"></param> | ||
164 | /// <param name="pos"></param> | ||
165 | /// <param name="size"></param> | ||
166 | /// <param name="pid_d"></param> | ||
167 | /// <param name="pid_p"></param> | ||
168 | /// <param name="capsule_radius"></param> | ||
169 | /// <param name="tensor"></param> | ||
170 | /// <param name="density"> | ||
171 | /// Only used right now to return information to LSL. Not actually used to set mass in ODE! | ||
172 | /// </param> | ||
173 | /// <param name="walk_divisor"></param> | ||
174 | /// <param name="rundivisor"></param> | ||
159 | public OdeCharacter( | 175 | public OdeCharacter( |
160 | String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p, | 176 | String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p, |
161 | float capsule_radius, float tensor, float density, | 177 | float capsule_radius, float tensor, float density, |
@@ -786,6 +802,10 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
786 | Vector3 vec = Vector3.Zero; | 802 | Vector3 vec = Vector3.Zero; |
787 | d.Vector3 vel = d.BodyGetLinearVel(Body); | 803 | d.Vector3 vel = d.BodyGetLinearVel(Body); |
788 | 804 | ||
805 | // m_log.DebugFormat( | ||
806 | // "[ODE CHARACTER]: Current velocity in Move() is <{0},{1},{2}>, target {3} for {4}", | ||
807 | // vel.X, vel.Y, vel.Z, _target_velocity, Name); | ||
808 | |||
789 | float movementdivisor = 1f; | 809 | float movementdivisor = 1f; |
790 | 810 | ||
791 | if (!m_alwaysRun) | 811 | if (!m_alwaysRun) |
@@ -884,18 +904,20 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
884 | 904 | ||
885 | if (flying) | 905 | if (flying) |
886 | { | 906 | { |
907 | // This also acts as anti-gravity so that we hover when flying rather than fall. | ||
887 | vec.Z = (_target_velocity.Z - vel.Z) * (PID_D); | 908 | vec.Z = (_target_velocity.Z - vel.Z) * (PID_D); |
888 | } | 909 | } |
889 | } | 910 | } |
890 | 911 | ||
891 | if (flying) | 912 | if (flying) |
892 | { | 913 | { |
914 | // Anti-gravity so that we hover when flying rather than fall. | ||
893 | vec.Z += ((-1 * _parent_scene.gravityz) * m_mass); | 915 | vec.Z += ((-1 * _parent_scene.gravityz) * m_mass); |
894 | 916 | ||
895 | //Added for auto fly height. Kitto Flora | 917 | //Added for auto fly height. Kitto Flora |
896 | //d.Vector3 pos = d.BodyGetPosition(Body); | 918 | //d.Vector3 pos = d.BodyGetPosition(Body); |
897 | float target_altitude = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y) + MinimumGroundFlightOffset; | 919 | float target_altitude = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y) + MinimumGroundFlightOffset; |
898 | 920 | ||
899 | if (_position.Z < target_altitude) | 921 | if (_position.Z < target_altitude) |
900 | { | 922 | { |
901 | vec.Z += (target_altitude - _position.Z) * PID_P * 5.0f; | 923 | vec.Z += (target_altitude - _position.Z) * PID_P * 5.0f; |
@@ -921,6 +943,25 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
921 | 943 | ||
922 | return; | 944 | return; |
923 | } | 945 | } |
946 | |||
947 | d.Vector3 newVel = d.BodyGetLinearVel(Body); | ||
948 | if (newVel.X >= 256 || newVel.X <= 256 || newVel.Y >= 256 || newVel.Y <= 256 || newVel.Z >= 256 || newVel.Z <= 256) | ||
949 | { | ||
950 | // m_log.DebugFormat( | ||
951 | // "[ODE CHARACTER]: Limiting falling velocity from {0} to {1} for {2}", newVel.Z, -9.8, Name); | ||
952 | |||
953 | newVel.X = Util.Clamp<float>(newVel.X, -255f, 255f); | ||
954 | newVel.Y = Util.Clamp<float>(newVel.Y, -255f, 255f); | ||
955 | |||
956 | if (!flying) | ||
957 | newVel.Z | ||
958 | = Util.Clamp<float>( | ||
959 | newVel.Z, -_parent_scene.AvatarTerminalVelocity, _parent_scene.AvatarTerminalVelocity); | ||
960 | else | ||
961 | newVel.Z = Util.Clamp<float>(newVel.Z, -255f, 255f); | ||
962 | |||
963 | d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z); | ||
964 | } | ||
924 | } | 965 | } |
925 | 966 | ||
926 | /// <summary> | 967 | /// <summary> |
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs index 4530c09..7d1401c 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs | |||
@@ -144,6 +144,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
144 | public float gravityy = 0f; | 144 | public float gravityy = 0f; |
145 | public float gravityz = -9.8f; | 145 | public float gravityz = -9.8f; |
146 | 146 | ||
147 | public float AvatarTerminalVelocity { get; set; } | ||
148 | |||
147 | private float contactsurfacelayer = 0.001f; | 149 | private float contactsurfacelayer = 0.001f; |
148 | 150 | ||
149 | private int worldHashspaceLow = -4; | 151 | private int worldHashspaceLow = -4; |
@@ -459,6 +461,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
459 | gravityy = physicsconfig.GetFloat("world_gravityy", 0f); | 461 | gravityy = physicsconfig.GetFloat("world_gravityy", 0f); |
460 | gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f); | 462 | gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f); |
461 | 463 | ||
464 | float avatarTerminalVelocity = physicsconfig.GetFloat("avatar_terminal_velocity", 9f); | ||
465 | AvatarTerminalVelocity = Util.Clamp<float>(avatarTerminalVelocity, 0, 255f); | ||
466 | if (AvatarTerminalVelocity != avatarTerminalVelocity) | ||
467 | { | ||
468 | m_log.WarnFormat( | ||
469 | "[ODE SCENE]: avatar_terminal_velocity of {0} is invalid. Clamping to {1}", | ||
470 | avatarTerminalVelocity, AvatarTerminalVelocity); | ||
471 | } | ||
472 | |||
462 | worldHashspaceLow = physicsconfig.GetInt("world_hashspace_size_low", -4); | 473 | worldHashspaceLow = physicsconfig.GetInt("world_hashspace_size_low", -4); |
463 | worldHashspaceHigh = physicsconfig.GetInt("world_hashspace_size_high", 128); | 474 | worldHashspaceHigh = physicsconfig.GetInt("world_hashspace_size_high", 128); |
464 | 475 | ||