From 65c4cb48ac49bd6aa9e813a401411be5226d01a7 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 2 Apr 2014 21:53:58 -0700 Subject: BulletSim: make avatar physical shape to be a rectangle rather than a capsule. Set the default to be the rectangle shape and adjust the parameters in OpenSimDefaults.ini for the new shape. The rectangle shape will perform better and avatar height can be computed more accurately. --- .../EntityTransfer/EntityTransferModule.cs | 6 +--- .../Region/Physics/BulletSPlugin/BSCharacter.cs | 17 ++++++++---- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 9 ++++-- .../Physics/BulletSPlugin/BSShapeCollection.cs | 32 ++++++++++++++++++++-- 4 files changed, 48 insertions(+), 16 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs index 62b5a01..caeb4f8 100644 --- a/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs +++ b/OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs @@ -1765,11 +1765,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer // Next, let's close the child agent connections that are too far away. uint neighbourx; uint neighboury; - - Utils.LongToUInts(neighbourRegion.RegionHandle, out neighbourx, out neighboury); - - neighbourx /= Constants.RegionSize; - neighboury /= Constants.RegionSize; + Util.RegionHandleToRegionLoc(neighbourRegion.RegionHandle, out neighbourx, out neighboury); agent.CloseChildAgents(neighbourx, neighboury); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index c9b134c..dfcd2bf 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs @@ -657,7 +657,7 @@ public sealed class BSCharacter : BSPhysObject private OMV.Vector3 ComputeAvatarScale(OMV.Vector3 size) { - OMV.Vector3 newScale; + OMV.Vector3 newScale = size; // Bullet's capsule total height is the "passed height + radius * 2"; // The base capsule is 1 unit in diameter and 2 units in height (passed radius=0.5, passed height = 1) @@ -670,8 +670,6 @@ public sealed class BSCharacter : BSPhysObject // for a asymmetrical capsule, other parts of the code presume it is cylindrical. // Scale is multiplier of radius with one of "0.5" - newScale.X = size.X / 2f; - newScale.Y = size.Y / 2f; float heightAdjust = BSParam.AvatarHeightMidFudge; if (BSParam.AvatarHeightLowFudge != 0f || BSParam.AvatarHeightHighFudge != 0f) @@ -692,8 +690,17 @@ public sealed class BSCharacter : BSPhysObject heightAdjust += ((midHeightOffset) / (AVATAR_HI - AVATAR_MID)) * 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) + heightAdjust) / 2f; + if (BSParam.AvatarShape == BSShapeCollection.AvatarShapeCapsule) + { + newScale.X = size.X / 2f; + newScale.Y = size.Y / 2f; + // 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) + heightAdjust) / 2f; + } + else + { + newScale.Z = size.Z + heightAdjust; + } // 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 diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 860193f..4d14a9e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -128,6 +128,7 @@ public static class BSParam public static float AvatarAlwaysRunFactor { get; private set; } public static float AvatarDensity { get; private set; } public static float AvatarRestitution { get; private set; } + public static int AvatarShape { get; private set; } public static float AvatarCapsuleWidth { get; private set; } public static float AvatarCapsuleDepth { get; private set; } public static float AvatarCapsuleHeight { get; private set; } @@ -565,6 +566,8 @@ public static class BSParam 3500f) , // 3.5 * 100 new ParameterDefn("AvatarRestitution", "Bouncyness. Changed on avatar recreation.", 0f ), + new ParameterDefn("AvatarShape", "Code for avatar physical shape: 0:capsule, 1:cube, 2:ovoid, 2:mesh", + BSShapeCollection.AvatarShapeCube ) , new ParameterDefn("AvatarCapsuleWidth", "The distance between the sides of the avatar capsule", 0.6f ) , new ParameterDefn("AvatarCapsuleDepth", "The distance between the front and back of the avatar capsule", @@ -572,11 +575,11 @@ public static class BSParam 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 ), + 0f ), new ParameterDefn("AvatarHeightMidFudge", "A fudge distance to adjust average sized avatars to be standing on ground", - 0.1f ), + -0.1f ), new ParameterDefn("AvatarHeightHighFudge", "A fudge factor to make tall avatars stand on the ground", - 0.1f ), + 0f ), new ParameterDefn("AvatarContactProcessingThreshold", "Distance from capsule to check for collisions", 0.1f ), new ParameterDefn("AvatarStopZeroThreshold", "Movement velocity below which avatar is assumed to be stopped", diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 32bbc8f..721a8eb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -124,6 +124,10 @@ public sealed class BSShapeCollection : IDisposable // Info in prim.BSShape is updated to the new shape. // Returns 'true' if the geometry was rebuilt. // Called at taint-time! + public const int AvatarShapeCapsule = 0; + public const int AvatarShapeCube = 1; + public const int AvatarShapeOvoid = 2; + public const int AvatarShapeMesh = 3; private bool CreateGeom(bool forceRebuild, BSPhysObject prim, PhysicalDestructionCallback shapeCallback) { bool ret = false; @@ -137,10 +141,32 @@ public sealed class BSShapeCollection : IDisposable if (theChar != null) { DereferenceExistingShape(prim, shapeCallback); - prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, + switch (BSParam.AvatarShape) + { + case AvatarShapeCapsule: + prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, BSPhysicsShapeType.SHAPE_CAPSULE, FixedShapeKey.KEY_CAPSULE); - ret = true; - haveShape = true; + ret = true; + haveShape = true; + break; + case AvatarShapeCube: + prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, + BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_CAPSULE); + ret = true; + haveShape = true; + break; + case AvatarShapeOvoid: + // Saddly, Bullet doesn't scale spheres so this doesn't work as an avatar shape + prim.PhysShape = BSShapeNative.GetReference(m_physicsScene, prim, + BSPhysicsShapeType.SHAPE_SPHERE, FixedShapeKey.KEY_CAPSULE); + ret = true; + haveShape = true; + break; + case AvatarShapeMesh: + break; + default: + break; + } } // If the prim attributes are simple, this could be a simple Bullet native shape -- cgit v1.1