From f49897a4195df5fbd00e2c16461bcebb36ce8f72 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 11 Feb 2012 02:26:53 +0000
Subject: 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
---
OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 43 +++++++++++++++++++++++-
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 11 ++++++
2 files changed, 53 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics')
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
internal UUID m_uuid { get; private set; }
internal bool bad = false;
+ ///
+ /// ODE Avatar.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// Only used right now to return information to LSL. Not actually used to set mass in ODE!
+ ///
+ ///
+ ///
public OdeCharacter(
String avName, OdeScene parent_scene, Vector3 pos, Vector3 size, float pid_d, float pid_p,
float capsule_radius, float tensor, float density,
@@ -786,6 +802,10 @@ namespace OpenSim.Region.Physics.OdePlugin
Vector3 vec = Vector3.Zero;
d.Vector3 vel = d.BodyGetLinearVel(Body);
+// m_log.DebugFormat(
+// "[ODE CHARACTER]: Current velocity in Move() is <{0},{1},{2}>, target {3} for {4}",
+// vel.X, vel.Y, vel.Z, _target_velocity, Name);
+
float movementdivisor = 1f;
if (!m_alwaysRun)
@@ -884,18 +904,20 @@ namespace OpenSim.Region.Physics.OdePlugin
if (flying)
{
+ // This also acts as anti-gravity so that we hover when flying rather than fall.
vec.Z = (_target_velocity.Z - vel.Z) * (PID_D);
}
}
if (flying)
{
+ // Anti-gravity so that we hover when flying rather than fall.
vec.Z += ((-1 * _parent_scene.gravityz) * m_mass);
//Added for auto fly height. Kitto Flora
//d.Vector3 pos = d.BodyGetPosition(Body);
float target_altitude = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y) + MinimumGroundFlightOffset;
-
+
if (_position.Z < target_altitude)
{
vec.Z += (target_altitude - _position.Z) * PID_P * 5.0f;
@@ -921,6 +943,25 @@ namespace OpenSim.Region.Physics.OdePlugin
return;
}
+
+ d.Vector3 newVel = d.BodyGetLinearVel(Body);
+ if (newVel.X >= 256 || newVel.X <= 256 || newVel.Y >= 256 || newVel.Y <= 256 || newVel.Z >= 256 || newVel.Z <= 256)
+ {
+// m_log.DebugFormat(
+// "[ODE CHARACTER]: Limiting falling velocity from {0} to {1} for {2}", newVel.Z, -9.8, Name);
+
+ newVel.X = Util.Clamp(newVel.X, -255f, 255f);
+ newVel.Y = Util.Clamp(newVel.Y, -255f, 255f);
+
+ if (!flying)
+ newVel.Z
+ = Util.Clamp(
+ newVel.Z, -_parent_scene.AvatarTerminalVelocity, _parent_scene.AvatarTerminalVelocity);
+ else
+ newVel.Z = Util.Clamp(newVel.Z, -255f, 255f);
+
+ d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
+ }
}
///
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
public float gravityy = 0f;
public float gravityz = -9.8f;
+ public float AvatarTerminalVelocity { get; set; }
+
private float contactsurfacelayer = 0.001f;
private int worldHashspaceLow = -4;
@@ -459,6 +461,15 @@ namespace OpenSim.Region.Physics.OdePlugin
gravityy = physicsconfig.GetFloat("world_gravityy", 0f);
gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f);
+ float avatarTerminalVelocity = physicsconfig.GetFloat("avatar_terminal_velocity", 9f);
+ AvatarTerminalVelocity = Util.Clamp(avatarTerminalVelocity, 0, 255f);
+ if (AvatarTerminalVelocity != avatarTerminalVelocity)
+ {
+ m_log.WarnFormat(
+ "[ODE SCENE]: avatar_terminal_velocity of {0} is invalid. Clamping to {1}",
+ avatarTerminalVelocity, AvatarTerminalVelocity);
+ }
+
worldHashspaceLow = physicsconfig.GetInt("world_hashspace_size_low", -4);
worldHashspaceHigh = physicsconfig.GetInt("world_hashspace_size_high", 128);
--
cgit v1.1
From b92b9228ef5c7833dac019aba12babb5df954d35 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Sat, 11 Feb 2012 02:29:07 +0000
Subject: correct the default avatar_terminal_velocity value that I
accidentally left in whilst testing
---
OpenSim/Region/Physics/OdePlugin/OdeScene.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'OpenSim/Region/Physics')
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 7d1401c..598530c 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -461,7 +461,7 @@ namespace OpenSim.Region.Physics.OdePlugin
gravityy = physicsconfig.GetFloat("world_gravityy", 0f);
gravityz = physicsconfig.GetFloat("world_gravityz", -9.8f);
- float avatarTerminalVelocity = physicsconfig.GetFloat("avatar_terminal_velocity", 9f);
+ float avatarTerminalVelocity = physicsconfig.GetFloat("avatar_terminal_velocity", 54f);
AvatarTerminalVelocity = Util.Clamp(avatarTerminalVelocity, 0, 255f);
if (AvatarTerminalVelocity != avatarTerminalVelocity)
{
--
cgit v1.1