BulletSim: improvements to LinksetCompound and PrimDisplaced. Not all working yet.
parent
d322625f90
commit
7cdb07b386
|
@ -395,7 +395,8 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
// Constraint linksets are rebuilt every time.
|
// Constraint linksets are rebuilt every time.
|
||||||
// Note that this works for rebuilding just the root after a linkset is taken apart.
|
// Note that this works for rebuilding just the root after a linkset is taken apart.
|
||||||
// Called at taint time!!
|
// Called at taint time!!
|
||||||
private bool disableCOM = true; // DEBUG DEBUG: disable until we get this debugged
|
private bool UseBulletSimRootOffsetHack = false;
|
||||||
|
private bool disableCOM = true; // For basic linkset debugging, turn off the center-of-mass setting
|
||||||
private void RecomputeLinksetCompound()
|
private void RecomputeLinksetCompound()
|
||||||
{
|
{
|
||||||
if (!LinksetRoot.IsPhysicallyActive)
|
if (!LinksetRoot.IsPhysicallyActive)
|
||||||
|
@ -428,11 +429,19 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
|
|
||||||
// 'centerDisplacement' is the value to subtract from children to give physical offset position
|
// 'centerDisplacement' is the value to subtract from children to give physical offset position
|
||||||
OMV.Vector3 centerDisplacement = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation;
|
OMV.Vector3 centerDisplacement = (centerOfMassW - LinksetRoot.RawPosition) * invRootOrientation;
|
||||||
LinksetRoot.SetEffectiveCenterOfMassW(centerDisplacement);
|
if (UseBulletSimRootOffsetHack || disableCOM)
|
||||||
|
{
|
||||||
|
centerDisplacement = OMV.Vector3.Zero;
|
||||||
|
LinksetRoot.ClearDisplacement();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LinksetRoot.SetEffectiveCenterOfMassDisplacement(centerDisplacement);
|
||||||
|
}
|
||||||
|
DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,COM,rootPos={1},com={2},comDisp={3}",
|
||||||
|
LinksetRoot.LocalID, LinksetRoot.RawPosition, centerOfMassW, centerDisplacement);
|
||||||
|
|
||||||
// TODO: add phantom root shape to be the center-of-mass
|
// Add the shapes of all the components of the linkset
|
||||||
|
|
||||||
// Add a shape for each of the other children in the linkset
|
|
||||||
int memberIndex = 1;
|
int memberIndex = 1;
|
||||||
ForEachMember(delegate(BSPrimLinkable cPrim)
|
ForEachMember(delegate(BSPrimLinkable cPrim)
|
||||||
{
|
{
|
||||||
|
@ -449,8 +458,8 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement;
|
OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement;
|
||||||
OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation;
|
OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation;
|
||||||
m_physicsScene.PE.AddChildShapeToCompoundShape(LinksetShape.physShapeInfo, childShape.physShapeInfo, offsetPos, offsetRot);
|
m_physicsScene.PE.AddChildShapeToCompoundShape(LinksetShape.physShapeInfo, childShape.physShapeInfo, offsetPos, offsetRot);
|
||||||
DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addChild,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}",
|
DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addChild,indx={1}cShape={2},offPos={3},offRot={4}",
|
||||||
LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot);
|
LinksetRoot.LocalID, memberIndex, cPrim.PhysShape, offsetPos, offsetRot);
|
||||||
|
|
||||||
memberIndex++;
|
memberIndex++;
|
||||||
|
|
||||||
|
@ -463,21 +472,29 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, LinksetRoot.PhysBody);
|
m_physicsScene.PE.RemoveObjectFromWorld(m_physicsScene.World, LinksetRoot.PhysBody);
|
||||||
m_physicsScene.PE.SetCollisionShape(m_physicsScene.World, LinksetRoot.PhysBody, LinksetShape.physShapeInfo);
|
m_physicsScene.PE.SetCollisionShape(m_physicsScene.World, LinksetRoot.PhysBody, LinksetShape.physShapeInfo);
|
||||||
m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, LinksetRoot.PhysBody);
|
m_physicsScene.PE.AddObjectToWorld(m_physicsScene.World, LinksetRoot.PhysBody);
|
||||||
|
DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addBody,body={1},shape={2}",
|
||||||
|
LinksetRoot.LocalID, LinksetRoot.PhysBody, LinksetShape);
|
||||||
|
|
||||||
// With all of the linkset packed into the root prim, it has the mass of everyone.
|
// With all of the linkset packed into the root prim, it has the mass of everyone.
|
||||||
LinksetMass = ComputeLinksetMass();
|
LinksetMass = ComputeLinksetMass();
|
||||||
LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true);
|
LinksetRoot.UpdatePhysicalMassProperties(LinksetMass, true);
|
||||||
|
|
||||||
// Enable the physical position updator to return the position and rotation of the root shape
|
if (UseBulletSimRootOffsetHack)
|
||||||
|
{
|
||||||
|
// Enable the physical position updator to return the position and rotation of the root shape.
|
||||||
|
// This enables a feature in the C++ code to return the world coordinates of the first shape in the
|
||||||
|
// compound shape. This eleviates the need to offset the returned physical position by the
|
||||||
|
// center-of-mass offset.
|
||||||
m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE);
|
m_physicsScene.PE.AddToCollisionFlags(LinksetRoot.PhysBody, CollisionFlags.BS_RETURN_ROOT_COMPOUND_SHAPE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Rebuilding = false;
|
Rebuilding = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See that the Aabb surrounds the new shape
|
// See that the Aabb surrounds the new shape
|
||||||
m_physicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetRoot.PhysShape.physShapeInfo);
|
m_physicsScene.PE.RecalculateCompoundShapeLocalAabb(LinksetShape.physShapeInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -259,7 +259,8 @@ public abstract class BSPhysObject : PhysicsActor
|
||||||
|
|
||||||
// The user can optionally set the center of mass. The user's setting will override any
|
// The user can optionally set the center of mass. The user's setting will override any
|
||||||
// computed center-of-mass (like in linksets).
|
// computed center-of-mass (like in linksets).
|
||||||
public OMV.Vector3? UserSetCenterOfMass { get; set; }
|
// Note this is a displacement from the root's coordinates. Zero means use the root prim as center-of-mass.
|
||||||
|
public OMV.Vector3? UserSetCenterOfMassDisplacement { get; set; }
|
||||||
|
|
||||||
public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free.
|
public OMV.Vector3 LockedAxis { get; set; } // zero means locked. one means free.
|
||||||
public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free
|
public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(1f, 1f, 1f); // All axis are free
|
||||||
|
|
|
@ -78,14 +78,16 @@ public class BSPrimDisplaced : BSPrim
|
||||||
// Set this sets and computes the displacement from the passed prim to the center-of-mass.
|
// Set this sets and computes the displacement from the passed prim to the center-of-mass.
|
||||||
// A user set value for center-of-mass overrides whatever might be passed in here.
|
// A user set value for center-of-mass overrides whatever might be passed in here.
|
||||||
// The displacement is in local coordinates (relative to root prim in linkset oriented coordinates).
|
// The displacement is in local coordinates (relative to root prim in linkset oriented coordinates).
|
||||||
public virtual void SetEffectiveCenterOfMassW(Vector3 centerOfMassDisplacement)
|
public virtual void SetEffectiveCenterOfMassDisplacement(Vector3 centerOfMassDisplacement)
|
||||||
{
|
{
|
||||||
Vector3 comDisp;
|
Vector3 comDisp;
|
||||||
if (UserSetCenterOfMass.HasValue)
|
if (UserSetCenterOfMassDisplacement.HasValue)
|
||||||
comDisp = (OMV.Vector3)UserSetCenterOfMass;
|
comDisp = (OMV.Vector3)UserSetCenterOfMassDisplacement;
|
||||||
else
|
else
|
||||||
comDisp = centerOfMassDisplacement;
|
comDisp = centerOfMassDisplacement;
|
||||||
|
|
||||||
|
DetailLog("{0},BSPrimDisplaced.SetEffectiveCenterOfMassDisplacement,userSet={1},comDisp={2}",
|
||||||
|
LocalID, UserSetCenterOfMassDisplacement.HasValue, comDisp);
|
||||||
if (comDisp == Vector3.Zero)
|
if (comDisp == Vector3.Zero)
|
||||||
{
|
{
|
||||||
// If there is no diplacement. Things get reset.
|
// If there is no diplacement. Things get reset.
|
||||||
|
@ -107,17 +109,24 @@ public class BSPrimDisplaced : BSPrim
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (PositionDisplacement != OMV.Vector3.Zero)
|
if (PositionDisplacement != OMV.Vector3.Zero)
|
||||||
base.ForcePosition = value - (PositionDisplacement * RawOrientation);
|
{
|
||||||
|
OMV.Vector3 displacedPos = value - (PositionDisplacement * RawOrientation);
|
||||||
|
DetailLog("{0},BSPrimDisplaced.ForcePosition,val={1},disp={2},newPos={3}", LocalID, value, PositionDisplacement, displacedPos);
|
||||||
|
base.ForcePosition = displacedPos;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
base.ForcePosition = value;
|
base.ForcePosition = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override Quaternion ForceOrientation
|
public override Quaternion ForceOrientation
|
||||||
{
|
{
|
||||||
get { return base.ForceOrientation; }
|
get { return base.ForceOrientation; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
// TODO:
|
||||||
base.ForceOrientation = value;
|
base.ForceOrientation = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +152,10 @@ public class BSPrimDisplaced : BSPrim
|
||||||
{
|
{
|
||||||
// Correct for any rotation around the center-of-mass
|
// Correct for any rotation around the center-of-mass
|
||||||
// TODO!!!
|
// TODO!!!
|
||||||
entprop.Position = entprop.Position + (PositionDisplacement * entprop.Rotation);
|
|
||||||
|
OMV.Vector3 displacedPos = entprop.Position + (PositionDisplacement * entprop.Rotation);
|
||||||
|
DetailLog("{0},BSPrimDisplaced.ForcePosition,physPos={1},disp={2},newPos={3}", LocalID, entprop.Position, PositionDisplacement, displacedPos);
|
||||||
|
entprop.Position = displacedPos;
|
||||||
// entprop.Rotation = something;
|
// entprop.Rotation = something;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ public abstract class BSShape
|
||||||
StringBuilder buff = new StringBuilder();
|
StringBuilder buff = new StringBuilder();
|
||||||
buff.Append("<t=");
|
buff.Append("<t=");
|
||||||
buff.Append(ShapeType.ToString());
|
buff.Append(ShapeType.ToString());
|
||||||
buff.Append("<p=");
|
buff.Append(",p=");
|
||||||
buff.Append(AddrString);
|
buff.Append(AddrString);
|
||||||
buff.Append(",c=");
|
buff.Append(",c=");
|
||||||
buff.Append(referenceCount.ToString());
|
buff.Append(referenceCount.ToString());
|
||||||
|
|
|
@ -52,6 +52,9 @@ One sided meshes? Should terrain be built into a closed shape?
|
||||||
|
|
||||||
VEHICLES TODO LIST:
|
VEHICLES TODO LIST:
|
||||||
=================================================
|
=================================================
|
||||||
|
LINEAR_MOTOR_DIRECTION values should be clamped to reasonable numbers.
|
||||||
|
What are the limits in SL?
|
||||||
|
Same for other velocity settings.
|
||||||
UBit improvements to remove rubber-banding of avatars sitting on vehicle child prims:
|
UBit improvements to remove rubber-banding of avatars sitting on vehicle child prims:
|
||||||
https://github.com/UbitUmarov/Ubit-opensim
|
https://github.com/UbitUmarov/Ubit-opensim
|
||||||
Border crossing with linked vehicle causes crash
|
Border crossing with linked vehicle causes crash
|
||||||
|
|
Loading…
Reference in New Issue