BulletSim: fix problem of avatar's floating off the ground after unsitting. Reworked size/scale logic so physical scale is kept in Bullet and physObject scale is the preferred size -- usually same as size but avatars are computed differently.

0.7.5-pf-bulletsim
Robert Adams 2012-12-12 16:29:03 -08:00
parent 6f1f7f0206
commit e1814aa827
4 changed files with 27 additions and 24 deletions

View File

@ -105,12 +105,12 @@ public sealed class BSCharacter : BSPhysObject
DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}",
LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
// do actual create at taint time
// do actual creation in taint time
PhysicsScene.TaintedObject("BSCharacter.create", delegate()
{
DetailLog("{0},BSCharacter.create,taint", LocalID);
// New body and shape into PhysBody and PhysShape
PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, null, null);
PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this);
SetPhysicalProperties();
});
@ -189,6 +189,11 @@ public sealed class BSCharacter : BSPhysObject
set {
// When an avatar's size is set, only the height is changed.
_size = value;
// 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 = PhysicsScene.Params.avatarCapsuleDepth;
if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth;
ComputeAvatarScale(_size);
ComputeAvatarVolumeAndMass();
DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}",
@ -196,18 +201,18 @@ public sealed class BSCharacter : BSPhysObject
PhysicsScene.TaintedObject("BSCharacter.setSize", delegate()
{
if (PhysShape.HasPhysicalShape)
if (PhysBody.HasPhysicalBody && PhysShape.HasPhysicalShape)
{
BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
UpdatePhysicalMassProperties(RawMass);
// Make sure this change appears as a property update event
BulletSimAPI.PushUpdate2(PhysBody.ptr);
}
});
}
}
public override OMV.Vector3 Scale { get; set; }
public override PrimitiveBaseShape Shape
{
set { BaseShape = value; }
@ -638,9 +643,6 @@ public sealed class BSCharacter : BSPhysObject
private void ComputeAvatarScale(OMV.Vector3 size)
{
// The 'size' given by the simulator is the mid-point of the avatar
// and X and Y are unspecified.
OMV.Vector3 newScale = size;
// newScale.X = PhysicsScene.Params.avatarCapsuleWidth;
// newScale.Y = PhysicsScene.Params.avatarCapsuleDepth;

View File

@ -109,7 +109,7 @@ public abstract class BSPhysObject : PhysicsActor
public EntityProperties CurrentEntityProperties { get; set; }
public EntityProperties LastEntityProperties { get; set; }
public abstract OMV.Vector3 Scale { get; set; }
public virtual OMV.Vector3 Scale { get; set; }
public abstract bool IsSolid { get; }
public abstract bool IsStatic { get; }

View File

@ -45,7 +45,6 @@ public sealed class BSPrim : BSPhysObject
private static readonly string LogHeader = "[BULLETS PRIM]";
// _size is what the user passed. Scale is what we pass to the physics engine with the mesh.
// Often Scale is unity because the meshmerizer will apply _size when creating the mesh.
private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user
private bool _grabbed;
@ -93,7 +92,7 @@ public sealed class BSPrim : BSPhysObject
_physicsActorType = (int)ActorTypes.Prim;
_position = pos;
_size = size;
Scale = size; // the scale will be set by CreateGeom depending on object type
Scale = size; // prims are the size the user wants them to be (different for BSCharactes).
_orientation = rotation;
_buoyancy = 1f;
_velocity = OMV.Vector3.Zero;
@ -159,12 +158,10 @@ public sealed class BSPrim : BSPhysObject
// We presume the scale and size are the same. If scale must be changed for
// the physical shape, that is done when the geometry is built.
_size = value;
Scale = _size;
ForceBodyShapeRebuild(false);
}
}
// Scale is what we set in the physics engine. It is different than 'size' in that
// 'size' can be encorporated into the mesh. In that case, the scale is <1,1,1>.
public override OMV.Vector3 Scale { get; set; }
public override PrimitiveBaseShape Shape {
set {
@ -1369,7 +1366,6 @@ public sealed class BSPrim : BSPhysObject
// Create the correct physical representation for this type of object.
// Updates PhysBody and PhysShape with the new information.
// Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary.
// Returns 'true' if either the body or the shape was changed.
PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, null, delegate(BulletBody dBody)
{
// Called if the current prim body is about to be destroyed.

View File

@ -126,6 +126,11 @@ public sealed class BSShapeCollection : IDisposable
return ret;
}
public bool GetBodyAndShape(bool forceRebuild, BulletSim sim, BSPhysObject prim)
{
return GetBodyAndShape(forceRebuild, sim, prim, null, null);
}
// Track another user of a body.
// We presume the caller has allocated the body.
// Bodies only have one user so the body is just put into the world if not already there.
@ -460,6 +465,11 @@ public sealed class BSShapeCollection : IDisposable
&& pbs.PathScaleX == 100 && pbs.PathScaleY == 100
&& pbs.PathShearX == 0 && pbs.PathShearY == 0) ) )
{
// Get the scale of any existing shape so we can see if the new shape is same native type and same size.
OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero;
if (prim.PhysShape.HasPhysicalShape)
scaleOfExistingShape = BulletSimAPI.GetLocalScaling2(prim.PhysShape.ptr);
if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}",
prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.type);
@ -469,7 +479,7 @@ public sealed class BSShapeCollection : IDisposable
{
haveShape = true;
if (forceRebuild
|| prim.Scale != prim.Size
|| prim.Scale != scaleOfExistingShape
|| prim.PhysShape.type != BSPhysicsShapeType.SHAPE_SPHERE
)
{
@ -483,7 +493,7 @@ public sealed class BSShapeCollection : IDisposable
{
haveShape = true;
if (forceRebuild
|| prim.Scale != prim.Size
|| prim.Scale != scaleOfExistingShape
|| prim.PhysShape.type != BSPhysicsShapeType.SHAPE_BOX
)
{
@ -542,7 +552,6 @@ public sealed class BSShapeCollection : IDisposable
prim.LocalID, newShape, prim.Scale);
// native shapes are scaled by Bullet
prim.Scale = prim.Size;
prim.PhysShape = newShape;
return true;
}
@ -555,8 +564,8 @@ public sealed class BSShapeCollection : IDisposable
ShapeData nativeShapeData = new ShapeData();
nativeShapeData.Type = shapeType;
nativeShapeData.ID = prim.LocalID;
nativeShapeData.Scale = prim.Size;
nativeShapeData.Size = prim.Size; // unneeded, I think.
nativeShapeData.Scale = prim.Scale;
nativeShapeData.Size = prim.Scale; // unneeded, I think.
nativeShapeData.MeshKey = (ulong)shapeKey;
nativeShapeData.HullKey = (ulong)shapeKey;
@ -611,8 +620,6 @@ public sealed class BSShapeCollection : IDisposable
ReferenceShape(newShape);
// meshes are already scaled by the meshmerizer
prim.Scale = new OMV.Vector3(1f, 1f, 1f);
prim.PhysShape = newShape;
return true; // 'true' means a new shape has been added to this prim
@ -683,8 +690,6 @@ public sealed class BSShapeCollection : IDisposable
ReferenceShape(newShape);
// hulls are already scaled by the meshmerizer
prim.Scale = new OMV.Vector3(1f, 1f, 1f);
prim.PhysShape = newShape;
return true; // 'true' means a new shape has been added to this prim
}