From 56edbe9b60e5ed5f1388e2d1d4d2a0d82cdeaf6d Mon Sep 17 00:00:00 2001
From: nlin
Date: Fri, 18 Sep 2009 11:26:52 +0900
Subject: Alternate algorithm for fixing avatar capsule tilt (Mantis #2905)
Eliminate dynamic capsule wobble. Instead introduce a small, fixed
tilt, and allow the tilt to rotate with the avatar while moving; the
tilt always faces away from the direction of avatar movement. The
rotation while moving should eliminate direction-dependent behavior
(e.g. only being able to climb on top of prims from certain directions).
Falling animation is still too frequently invoked.
Ideally the tilt should be completely eliminated, but doing so
currently causes the avatar to fall through the terrain.
---
OpenSim/Region/Physics/OdePlugin/ODECharacter.cs | 132 ++++++++++++-----------
1 file changed, 72 insertions(+), 60 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index dd58a4e..a00ba11 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -107,6 +107,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public float MinimumGroundFlightOffset = 3f;
private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
+ private float m_tiltMagnitudeWhenProjectedOnXYPlane = 0.1131371f; // used to introduce a fixed tilt because a straight-up capsule falls through terrain, probably a bug in terrain collider
private float m_buoyancy = 0f;
@@ -477,7 +478,71 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
}
-
+
+ private void AlignAvatarTiltWithCurrentDirectionOfMovement(PhysicsVector movementVector)
+ {
+ movementVector.Z = 0f;
+ float magnitude = (float)Math.Sqrt((double)(movementVector.X * movementVector.X + movementVector.Y * movementVector.Y));
+ if (magnitude < 0.1f) return;
+
+ // normalize the velocity vector
+ float invMagnitude = 1.0f / magnitude;
+ movementVector.X *= invMagnitude;
+ movementVector.Y *= invMagnitude;
+
+ // if we change the capsule heading too often, the capsule can fall down
+ // therefore we snap movement vector to just 1 of 4 predefined directions (ne, nw, se, sw),
+ // meaning only 4 possible capsule tilt orientations
+ if (movementVector.X > 0)
+ {
+ // east
+ if (movementVector.Y > 0)
+ {
+ // northeast
+ movementVector.X = (float)Math.Sqrt(2.0);
+ movementVector.Y = (float)Math.Sqrt(2.0);
+ }
+ else
+ {
+ // southeast
+ movementVector.X = (float)Math.Sqrt(2.0);
+ movementVector.Y = -(float)Math.Sqrt(2.0);
+ }
+ }
+ else
+ {
+ // west
+ if (movementVector.Y > 0)
+ {
+ // northwest
+ movementVector.X = -(float)Math.Sqrt(2.0);
+ movementVector.Y = (float)Math.Sqrt(2.0);
+ }
+ else
+ {
+ // southwest
+ movementVector.X = -(float)Math.Sqrt(2.0);
+ movementVector.Y = -(float)Math.Sqrt(2.0);
+ }
+ }
+
+
+ // movementVector.Z is zero
+
+ // calculate tilt components based on desired amount of tilt and current (snapped) heading.
+ // the "-" sign is to force the tilt to be OPPOSITE the direction of movement.
+ float xTiltComponent = -movementVector.X * m_tiltMagnitudeWhenProjectedOnXYPlane;
+ float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane;
+
+ //m_log.Debug("[PHYSICS] changing avatar tilt");
+ d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent);
+ d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced
+ d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent);
+ d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop
+ d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
+ d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
+ }
+
///
/// This creates the Avatar's physical Surrogate at the position supplied
///
@@ -576,71 +641,13 @@ namespace OpenSim.Region.Physics.OdePlugin
// (with -0..0 motor stops) falls into the terrain for reasons yet
// to be comprehended in their entirety.
#endregion
+ AlignAvatarTiltWithCurrentDirectionOfMovement(new PhysicsVector(0,0,0));
d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop
- #region Documentation of capsule motor StopERP and StopCFM parameters
- // In addition to the above tilt, we allow a dynamic tilt, or
- // wobble, to emerge as the capsule is pushed around the environment.
- // We do this with an experimentally determined combination of
- // StopERP and StopCFM which make the above motor stops soft.
- // The softness of the stops should be tweaked according to two
- // requirements:
- //
- // 1. Motor stops should be weak enough to allow enough wobble such
- // that the capsule can tilt slightly more when moving, to allow
- // "gliding" over obstacles:
- //
- //
- // .-.
- // / /
- // / /
- // _ / / _
- // / \ .-. / / / \
- // | | ----> / / / / | |
- // | | / / `-' | |
- // | | / / +------+ | |
- // | | / / | | | |
- // | | / / | | | |
- // \_/ `-' +------+ \_/
- // ----------------------------------------------------------
- //
- // Note that requirement 1 is made complicated by the ever-present
- // slight avatar tilt (assigned in the above code to prevent avatar
- // from falling through terrain), which introduces a direction-dependent
- // bias into the wobble (wobbling against the existing tilt is harder
- // than wobbling with the tilt), which makes it easier to walk over
- // prims from some directions. I have tried to minimize this effect by
- // minimizing the avatar tilt to the minimum that prevents the avatar from
- // falling through the terrain.
- //
- // 2. Motor stops should be strong enough to prevent the capsule
- // from being forced all the way to the ground; otherwise the
- // capsule could slip underneath obstacles like this:
- // _ _
- // / \ +------+ / \
- // | | ----> | | | |
- // | | | | | |
- // | | .--.___ +------+ | |
- // | | `--.__`--.__ | |
- // | | `--.__`--. | |
- // \_/ `--' \_/
- // ----------------------------------------------------------
- //
- //
- // It is strongly recommended you enable USE_DRAWSTUFF if you want to
- // tweak these values, to see how the capsule is reacting in various
- // situations.
- #endregion
- d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0.0035f);
- d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0.0035f);
- d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0.0035f);
- d.JointSetAMotorParam(Amotor, (int)dParam.StopERP, 0.8f);
- d.JointSetAMotorParam(Amotor, (int)dParam.StopERP2, 0.8f);
- d.JointSetAMotorParam(Amotor, (int)dParam.StopERP3, 0.8f);
}
// Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the
@@ -939,6 +946,7 @@ namespace OpenSim.Region.Physics.OdePlugin
PhysicsVector vec = new PhysicsVector();
d.Vector3 vel = d.BodyGetLinearVel(Body);
+
float movementdivisor = 1f;
if (!m_alwaysRun)
@@ -1052,6 +1060,10 @@ namespace OpenSim.Region.Physics.OdePlugin
if (PhysicsVector.isFinite(vec))
{
doForce(vec);
+ if (!_zeroFlag)
+ {
+ AlignAvatarTiltWithCurrentDirectionOfMovement(new PhysicsVector(vec.X, vec.Y, vec.Z));
+ }
}
else
{
--
cgit v1.1
From 1b2828f5d859d2941167b0457158142e683efe39 Mon Sep 17 00:00:00 2001
From: Dan Lake
Date: Thu, 24 Sep 2009 10:00:31 -0700
Subject: Meshmerizer stores dictionary of unique Meshes keyed on construction
parameters. CreateMesh() returns a Mesh from the dictionary or creates a new
Mesh if it has not been created before. Meshes are never purged from the
dictionary. The raw Mesh data is discarded once the memory is pinned for ODE
use. All copies of the same prim/mesh use the same pinned memory. ONLY
IMPLEMENTED AND TESTED WITH MESHMERIZER AND ODE
Signed-off-by: dahlia
---
OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 673ae39..032b5df 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -82,7 +82,6 @@ namespace OpenSim.Region.Physics.OdePlugin
// private float m_tensor = 5f;
private int body_autodisable_frames = 20;
- private IMesh primMesh = null;
private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom
@@ -814,14 +813,10 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
- IMesh oldMesh = primMesh;
+ float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
+ int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
- primMesh = mesh;
-
- float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
- int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
-
- primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory
+ mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
int VertexCount = vertexList.GetLength(0)/3;
int IndexCount = indexList.GetLength(0);
@@ -847,12 +842,6 @@ namespace OpenSim.Region.Physics.OdePlugin
return;
}
- if (oldMesh != null)
- {
- oldMesh.releasePinned();
- oldMesh = null;
- }
-
// if (IsPhysical && Body == (IntPtr) 0)
// {
// Recreate the body
--
cgit v1.1
From ee205e7e812e170f670e690a4e0fa9caa652f226 Mon Sep 17 00:00:00 2001
From: Jeff Ames
Date: Thu, 1 Oct 2009 01:00:09 +0900
Subject: Formatting cleanup.
---
OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs | 2 +-
OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
(limited to 'OpenSim/Region/Physics/OdePlugin')
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
index d9f4951..c8ae229 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
@@ -228,7 +228,7 @@ namespace OpenSim.Region.Physics.OdePlugin
mono [0x81d28b6]
mono [0x81ea2c6]
/lib/i686/cmov/libpthread.so.0 [0xb7e744c0]
- /lib/i686/cmov/libc.so.6(clone+0x5e) [0xb7dcd6de]
+ /lib/i686/cmov/libc.so.6(clone+0x5e) [0xb7dcd6de]
*/
// Exclude heightfield geom
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 94223d8..0769c90 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -2536,7 +2536,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (iPropertiesNotSupportedDefault == 0)
{
-#if SPAM
+#if SPAM
m_log.Warn("NonMesh");
#endif
return false;
@@ -3334,7 +3334,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{
// this._heightmap[i] = (double)heightMap[i];
// dbm (danx0r) -- creating a buffer zone of one extra sample all around
- //_origheightmap = heightMap;
+ //_origheightmap = heightMap;
float[] _heightmap;
@@ -3520,16 +3520,16 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomDestroy(g);
//removingHeightField = new float[0];
- }
+ }
}
}
else
{
m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
}
- }
+ }
}
- }
+ }
public override void SetWaterLevel(float baseheight)
{
--
cgit v1.1