From 15360cbb6ba83e40f474cca84082c908af49c58e Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Mon, 13 May 2013 13:03:13 -0700 Subject: BulletSim: add adjustment for avatar capsule height scaling. Makes avatar standing on ground view better and enables tuning. --- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 27 ++++++++++++++++++---- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 9 ++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 542f732..3671fc2 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) Contributors, http://opensimulator.org/ * See CONTRIBUTORS.TXT for a full list of copyright holders. * @@ -649,12 +649,12 @@ public sealed class BSCharacter : BSPhysObject OMV.Vector3 newScale; // Bullet's capsule total height is the "passed height + radius * 2"; - // The base capsule is 1 diameter and 2 height (passed radius=0.5, passed height = 1) + // The base capsule is 1 unit in diameter and 2 units in height (passed radius=0.5, passed height = 1) // The number we pass in for 'scaling' is the multiplier to get that base // shape to be the size desired. // So, when creating the scale for the avatar height, we take the passed height // (size.Z) and remove the caps. - // Another oddity of the Bullet capsule implementation is that it presumes the Y + // An oddity of the Bullet capsule implementation is that it presumes the Y // dimension is the radius of the capsule. Even though some of the code allows // for a asymmetrical capsule, other parts of the code presume it is cylindrical. @@ -662,8 +662,27 @@ public sealed class BSCharacter : BSPhysObject newScale.X = size.X / 2f; newScale.Y = size.Y / 2f; + float heightAdjust = BSParam.AvatarHeightMidFudge; + if (BSParam.AvatarHeightLowFudge != 0f || BSParam.AvatarHeightHighFudge != 0f) + { + // An avatar is between 1.61 and 2.12 meters. Midpoint is 1.87m. + // The "times 4" relies on the fact that the difference from the midpoint to the extremes is exactly 0.25 + float midHeightOffset = size.Z - 1.87f; + if (midHeightOffset < 0f) + { + // Small avatar. Add the adjustment based on the distance from midheight + heightAdjust += -1f * midHeightOffset * 4f * BSParam.AvatarHeightLowFudge; + } + else + { + // Large avatar. Add the adjustment based on the distance from midheight + heightAdjust += midHeightOffset * 4f * BSParam.AvatarHeightHighFudge; + } + } // The total scale height is the central cylindar plus the caps on the two ends. - newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2)) / 2f; + newScale.Z = (size.Z + (Math.Min(size.X, size.Y) * 2) + heightAdjust) / 2f; + // m_log.DebugFormat("{0} ComputeAvatarScale: size={1},adj={2},scale={3}", LogHeader, size, heightAdjust, newScale); + // If smaller than the endcaps, just fake like we're almost that small if (newScale.Z < 0) newScale.Z = 0.1f; diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 5504478..d33292f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -125,6 +125,9 @@ public static class BSParam public static float AvatarCapsuleWidth { get; private set; } public static float AvatarCapsuleDepth { get; private set; } public static float AvatarCapsuleHeight { get; private set; } + public static float AvatarHeightLowFudge { get; private set; } + public static float AvatarHeightMidFudge { get; private set; } + public static float AvatarHeightHighFudge { get; private set; } public static float AvatarContactProcessingThreshold { get; private set; } public static float AvatarBelowGroundUpCorrectionMeters { get; private set; } public static float AvatarStepHeight { get; private set; } @@ -539,6 +542,12 @@ public static class BSParam 0.45f ), new ParameterDefn("AvatarCapsuleHeight", "Default height of space around avatar", 1.5f ), + new ParameterDefn("AvatarHeightLowFudge", "A fudge factor to make small avatars stand on the ground", + -0.2f ), + new ParameterDefn("AvatarHeightMidFudge", "A fudge distance to adjust average sized avatars to be standing on ground", + 0.1f ), + new ParameterDefn("AvatarHeightHighFudge", "A fudge factor to make tall avatars stand on the ground", + 0.1f ), new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", 0.1f ), new ParameterDefn("AvatarBelowGroundUpCorrectionMeters", "Meters to move avatar up if it seems to be below ground", -- cgit v1.1