BulletSim: use the new 'setAvatarSize' physics call introduced in 0.9.
This disables all the avatar size fudge numbers previously used by BulletSim. If you have your region tuned to the old way, set "[BulletSim]AvatarUseBefore09SizeComputation=true" in your INI files.LSLKeyTest
parent
b65a18ef3f
commit
be43fc2234
|
@ -40,7 +40,6 @@ public sealed class BSCharacter : BSPhysObject
|
|||
private static readonly string LogHeader = "[BULLETS CHAR]";
|
||||
|
||||
// private bool _stopped;
|
||||
private OMV.Vector3 _size;
|
||||
private bool _grabbed;
|
||||
private bool _selected;
|
||||
private float _mass;
|
||||
|
@ -57,6 +56,9 @@ public sealed class BSCharacter : BSPhysObject
|
|||
private bool _kinematic;
|
||||
private float _buoyancy;
|
||||
|
||||
private OMV.Vector3 _size;
|
||||
private float _footOffset;
|
||||
|
||||
private BSActorAvatarMove m_moveActor;
|
||||
private const string AvatarMoveActorName = "BSCharacter.AvatarMove";
|
||||
|
||||
|
@ -76,7 +78,7 @@ public sealed class BSCharacter : BSPhysObject
|
|||
public override bool IsIncomplete { get { return false; } }
|
||||
|
||||
public BSCharacter(
|
||||
uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, bool isFlying)
|
||||
uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 vel, OMV.Vector3 size, float footOffset, bool isFlying)
|
||||
|
||||
: base(parent_scene, localID, avName, "BSCharacter")
|
||||
{
|
||||
|
@ -91,21 +93,13 @@ public sealed class BSCharacter : BSPhysObject
|
|||
Density = BSParam.AvatarDensity;
|
||||
_isPhysical = true;
|
||||
|
||||
// Old versions of ScenePresence passed only the height. If width and/or depth are zero,
|
||||
// replace with the default values.
|
||||
_size = size;
|
||||
if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth;
|
||||
if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth;
|
||||
|
||||
// The dimensions of the physical capsule are kept in the scale.
|
||||
// Physics creates a unit capsule which is scaled by the physics engine.
|
||||
Scale = ComputeAvatarScale(_size);
|
||||
// set _avatarVolume and _mass based on capsule size, _density and Scale
|
||||
ComputeAvatarVolumeAndMass();
|
||||
// Adjustments for zero X and Y made in Size()
|
||||
// This also computes avatar scale, volume, and mass
|
||||
SetAvatarSize(size, footOffset, true /* initializing */);
|
||||
|
||||
DetailLog(
|
||||
"{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5},pos={6},vel={7}",
|
||||
LocalID, _size, Scale, Density, _avatarVolume, RawMass, pos, vel);
|
||||
LocalID, Size, Scale, Density, _avatarVolume, RawMass, pos, vel);
|
||||
|
||||
// do actual creation in taint time
|
||||
PhysScene.TaintedObject(LocalID, "BSCharacter.create", delegate()
|
||||
|
@ -209,22 +203,47 @@ public sealed class BSCharacter : BSPhysObject
|
|||
public override OMV.Vector3 Size {
|
||||
get
|
||||
{
|
||||
// Avatar capsule size is kept in the scale parameter.
|
||||
return _size;
|
||||
}
|
||||
|
||||
set {
|
||||
// This is how much the avatar size is changing. Positive means getting bigger.
|
||||
// The avatar altitude must be adjusted for this change.
|
||||
float heightChange = value.Z - _size.Z;
|
||||
setAvatarSize(value, _footOffset);
|
||||
}
|
||||
}
|
||||
|
||||
_size = value;
|
||||
// OpenSim 0.9 introduces a common avatar size computation
|
||||
public override void setAvatarSize(OMV.Vector3 size, float feetOffset)
|
||||
{
|
||||
SetAvatarSize(size, feetOffset, false /* initializing */);
|
||||
}
|
||||
|
||||
// Internal version that, if initializing, doesn't do all the updating of the physics engine
|
||||
public void SetAvatarSize(OMV.Vector3 size, float feetOffset, bool initializing)
|
||||
{
|
||||
OMV.Vector3 newSize = size;
|
||||
if (newSize.IsFinite())
|
||||
{
|
||||
// Old versions of ScenePresence passed only the height. If width and/or depth are zero,
|
||||
// replace with the default values.
|
||||
if (_size.X == 0f) _size.X = BSParam.AvatarCapsuleDepth;
|
||||
if (_size.Y == 0f) _size.Y = BSParam.AvatarCapsuleWidth;
|
||||
if (newSize.X == 0f) newSize.X = BSParam.AvatarCapsuleDepth;
|
||||
if (newSize.Y == 0f) newSize.Y = BSParam.AvatarCapsuleWidth;
|
||||
|
||||
Scale = ComputeAvatarScale(_size);
|
||||
if (newSize.X < 0.01f) newSize.X = 0.01f;
|
||||
if (newSize.Y < 0.01f) newSize.Y = 0.01f;
|
||||
if (newSize.Z < 0.01f) newSize.Z = BSParam.AvatarCapsuleHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
newSize = new OMV.Vector3(BSParam.AvatarCapsuleDepth, BSParam.AvatarCapsuleWidth, BSParam.AvatarCapsuleHeight);
|
||||
}
|
||||
|
||||
// This is how much the avatar size is changing. Positive means getting bigger.
|
||||
// The avatar altitude must be adjusted for this change.
|
||||
float heightChange = newSize.Z - Size.Z;
|
||||
|
||||
_size = newSize;
|
||||
|
||||
Scale = ComputeAvatarScale(Size);
|
||||
ComputeAvatarVolumeAndMass();
|
||||
DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}",
|
||||
LocalID, _size, Scale, Density, _avatarVolume, RawMass);
|
||||
|
@ -243,8 +262,6 @@ public sealed class BSCharacter : BSPhysObject
|
|||
PhysScene.PE.PushUpdate(PhysBody);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override PrimitiveBaseShape Shape
|
||||
|
@ -702,10 +719,15 @@ public sealed class BSCharacter : BSPhysObject
|
|||
public override void SetMomentum(OMV.Vector3 momentum) {
|
||||
}
|
||||
|
||||
// The avatar's physical shape (whether capsule or cube) is unit sized. BulletSim sets
|
||||
// the scale of that unit shape to create the avatars full size.
|
||||
private OMV.Vector3 ComputeAvatarScale(OMV.Vector3 size)
|
||||
{
|
||||
OMV.Vector3 newScale = size;
|
||||
|
||||
if (BSParam.AvatarUseBefore09SizeComputation)
|
||||
{
|
||||
|
||||
// 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)
|
||||
// The number we pass in for 'scaling' is the multiplier to get that base
|
||||
|
@ -754,14 +776,22 @@ public sealed class BSCharacter : BSPhysObject
|
|||
if (newScale.Z < 0)
|
||||
newScale.Z = 0.1f;
|
||||
|
||||
DetailLog("{0},BSCharacter.ComputerAvatarScale,size={1},lowF={2},midF={3},hiF={4},adj={5},newScale={6}",
|
||||
DetailLog("{0},BSCharacter.ComputeAvatarScale,size={1},lowF={2},midF={3},hiF={4},adj={5},newScale={6}",
|
||||
LocalID, size, BSParam.AvatarHeightLowFudge, BSParam.AvatarHeightMidFudge, BSParam.AvatarHeightHighFudge, heightAdjust, newScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
newScale.Z = size.Z + _footOffset;
|
||||
DetailLog("{0},BSCharacter.ComputeAvatarScale,using newScale={1}, footOffset={2}", LocalID, newScale, _footOffset);
|
||||
}
|
||||
|
||||
return newScale;
|
||||
}
|
||||
|
||||
// set _avatarVolume and _mass based on capsule size, _density and Scale
|
||||
private void ComputeAvatarVolumeAndMass()
|
||||
{
|
||||
if (BSParam.AvatarShape == BSShapeCollection.AvatarShapeCapsule)
|
||||
{
|
||||
_avatarVolume = (float)(
|
||||
Math.PI
|
||||
|
@ -774,6 +804,11 @@ public sealed class BSCharacter : BSPhysObject
|
|||
* Math.Min(Size.X, Size.Y) / 2
|
||||
* Size.Y / 2f // plus the volume of the capsule end caps
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
_avatarVolume = Size.X * Size.Y * Size.Z;
|
||||
}
|
||||
_mass = Density * BSParam.DensityScaleFactor * _avatarVolume;
|
||||
}
|
||||
|
||||
|
|
|
@ -142,6 +142,7 @@ 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 bool AvatarUseBefore09SizeComputation { get; private set; }
|
||||
public static float AvatarHeightLowFudge { get; private set; }
|
||||
public static float AvatarHeightMidFudge { get; private set; }
|
||||
public static float AvatarHeightHighFudge { get; private set; }
|
||||
|
@ -616,6 +617,8 @@ public static class BSParam
|
|||
0.45f ),
|
||||
new ParameterDefn<float>("AvatarCapsuleHeight", "Default height of space around avatar",
|
||||
1.5f ),
|
||||
new ParameterDefn<bool>("AvatarUseBefore09SizeComputation", "Use the old fudge method of computing avatar capsule size",
|
||||
true ),
|
||||
new ParameterDefn<float>("AvatarHeightLowFudge", "A fudge factor to make small avatars stand on the ground",
|
||||
0f ),
|
||||
new ParameterDefn<float>("AvatarHeightMidFudge", "A fudge distance to adjust average sized avatars to be standing on ground",
|
||||
|
|
|
@ -523,13 +523,13 @@ namespace OpenSim.Region.PhysicsModule.BulletS
|
|||
return null;
|
||||
}
|
||||
|
||||
public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
|
||||
public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, float footOffset, bool isFlying)
|
||||
{
|
||||
// m_log.DebugFormat("{0}: AddAvatar: {1}", LogHeader, avName);
|
||||
|
||||
if (!m_initialized) return null;
|
||||
|
||||
BSCharacter actor = new BSCharacter(localID, avName, this, position, velocity, size, isFlying);
|
||||
BSCharacter actor = new BSCharacter(localID, avName, this, position, Vector3.Zero, size, footOffset, isFlying);
|
||||
lock (PhysObjects)
|
||||
PhysObjects.Add(localID, actor);
|
||||
|
||||
|
|
Loading…
Reference in New Issue