BulletSim: Add RawPosition and RawOrientation to BSPhysObject and rename MassRaw to RawMass. Fix BSShapeCollection to use Raw* for creating the body to eliminate exception from referencing the physical body before it has been created.
parent
39c02dcc8c
commit
f53b4e7a21
|
@ -97,7 +97,7 @@ public sealed class BSCharacter : BSPhysObject
|
|||
// set _avatarVolume and _mass based on capsule size, _density and Scale
|
||||
ComputeAvatarVolumeAndMass();
|
||||
DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}",
|
||||
LocalID, _size, Scale, _avatarDensity, _avatarVolume, MassRaw);
|
||||
LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
|
||||
|
||||
// do actual create at taint time
|
||||
PhysicsScene.TaintedObject("BSCharacter.create", delegate()
|
||||
|
@ -141,7 +141,7 @@ public sealed class BSCharacter : BSPhysObject
|
|||
BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius);
|
||||
}
|
||||
|
||||
UpdatePhysicalMassProperties(MassRaw);
|
||||
UpdatePhysicalMassProperties(RawMass);
|
||||
|
||||
// Make so capsule does not fall over
|
||||
BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero);
|
||||
|
@ -181,12 +181,12 @@ public sealed class BSCharacter : BSPhysObject
|
|||
ComputeAvatarScale(_size);
|
||||
ComputeAvatarVolumeAndMass();
|
||||
DetailLog("{0},BSCharacter.setSize,call,scale={1},density={2},volume={3},mass={4}",
|
||||
LocalID, Scale, _avatarDensity, _avatarVolume, MassRaw);
|
||||
LocalID, Scale, _avatarDensity, _avatarVolume, RawMass);
|
||||
|
||||
PhysicsScene.TaintedObject("BSCharacter.setSize", delegate()
|
||||
{
|
||||
BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
|
||||
UpdatePhysicalMassProperties(MassRaw);
|
||||
UpdatePhysicalMassProperties(RawMass);
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -231,6 +231,11 @@ public sealed class BSCharacter : BSPhysObject
|
|||
|
||||
public override void LockAngularMotion(OMV.Vector3 axis) { return; }
|
||||
|
||||
public override OMV.Vector3 RawPosition
|
||||
{
|
||||
get { return _position; }
|
||||
set { _position = value; }
|
||||
}
|
||||
public override OMV.Vector3 Position {
|
||||
get {
|
||||
// _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID);
|
||||
|
@ -316,7 +321,7 @@ public sealed class BSCharacter : BSPhysObject
|
|||
public override float Mass { get { return _mass; } }
|
||||
|
||||
// used when we only want this prim's mass and not the linkset thing
|
||||
public override float MassRaw {
|
||||
public override float RawMass {
|
||||
get {return _mass; }
|
||||
}
|
||||
public override void UpdatePhysicalMassProperties(float physMass)
|
||||
|
@ -405,6 +410,11 @@ public sealed class BSCharacter : BSPhysObject
|
|||
get { return _acceleration; }
|
||||
set { _acceleration = value; }
|
||||
}
|
||||
public override OMV.Quaternion RawOrientation
|
||||
{
|
||||
get { return _orientation; }
|
||||
set { _orientation = value; }
|
||||
}
|
||||
public override OMV.Quaternion Orientation {
|
||||
get { return _orientation; }
|
||||
set {
|
||||
|
|
|
@ -106,7 +106,7 @@ public abstract class BSLinkset
|
|||
PhysicsScene = scene;
|
||||
LinksetRoot = parent;
|
||||
m_children = new HashSet<BSPhysObject>();
|
||||
m_mass = parent.MassRaw;
|
||||
m_mass = parent.RawMass;
|
||||
}
|
||||
|
||||
// Link to a linkset where the child knows the parent.
|
||||
|
@ -242,14 +242,14 @@ public abstract class BSLinkset
|
|||
// ================================================================
|
||||
protected virtual float ComputeLinksetMass()
|
||||
{
|
||||
float mass = LinksetRoot.MassRaw;
|
||||
float mass = LinksetRoot.RawMass;
|
||||
if (HasAnyChildren)
|
||||
{
|
||||
lock (m_linksetActivityLock)
|
||||
{
|
||||
foreach (BSPhysObject bp in m_children)
|
||||
{
|
||||
mass += bp.MassRaw;
|
||||
mass += bp.RawMass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,13 +261,13 @@ public abstract class BSLinkset
|
|||
OMV.Vector3 com;
|
||||
lock (m_linksetActivityLock)
|
||||
{
|
||||
com = LinksetRoot.Position * LinksetRoot.MassRaw;
|
||||
float totalMass = LinksetRoot.MassRaw;
|
||||
com = LinksetRoot.Position * LinksetRoot.RawMass;
|
||||
float totalMass = LinksetRoot.RawMass;
|
||||
|
||||
foreach (BSPhysObject bp in m_children)
|
||||
{
|
||||
com += bp.Position * bp.MassRaw;
|
||||
totalMass += bp.MassRaw;
|
||||
com += bp.Position * bp.RawMass;
|
||||
totalMass += bp.RawMass;
|
||||
}
|
||||
if (totalMass != 0f)
|
||||
com /= totalMass;
|
||||
|
@ -285,7 +285,7 @@ public abstract class BSLinkset
|
|||
|
||||
foreach (BSPhysObject bp in m_children)
|
||||
{
|
||||
com += bp.Position * bp.MassRaw;
|
||||
com += bp.Position * bp.RawMass;
|
||||
}
|
||||
com /= (m_children.Count + 1);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public abstract class BSPhysObject : PhysicsActor
|
|||
public BSLinkset Linkset { get; set; }
|
||||
|
||||
// Return the object mass without calculating it or having side effects
|
||||
public abstract float MassRaw { get; }
|
||||
public abstract float RawMass { get; }
|
||||
// Set the raw mass but also update physical mass properties (inertia, ...)
|
||||
public abstract void UpdatePhysicalMassProperties(float mass);
|
||||
|
||||
|
@ -105,8 +105,10 @@ public abstract class BSPhysObject : PhysicsActor
|
|||
// Tell the object to clean up.
|
||||
public abstract void Destroy();
|
||||
|
||||
public abstract OMV.Vector3 RawPosition { get; set; }
|
||||
public abstract OMV.Vector3 ForcePosition { get; set; }
|
||||
|
||||
public abstract OMV.Quaternion RawOrientation { get; set; }
|
||||
public abstract OMV.Quaternion ForceOrientation { get; set; }
|
||||
|
||||
public abstract OMV.Vector3 ForceVelocity { get; set; }
|
||||
|
|
|
@ -256,6 +256,11 @@ public sealed class BSPrim : BSPhysObject
|
|||
return;
|
||||
}
|
||||
|
||||
public override OMV.Vector3 RawPosition
|
||||
{
|
||||
get { return _position; }
|
||||
set { _position = value; }
|
||||
}
|
||||
public override OMV.Vector3 Position {
|
||||
get {
|
||||
if (!Linkset.IsRoot(this))
|
||||
|
@ -366,7 +371,7 @@ public sealed class BSPrim : BSPhysObject
|
|||
}
|
||||
|
||||
// used when we only want this prim's mass and not the linkset thing
|
||||
public override float MassRaw {
|
||||
public override float RawMass {
|
||||
get { return _mass; }
|
||||
}
|
||||
// Set the physical mass to the passed mass.
|
||||
|
@ -530,6 +535,11 @@ public sealed class BSPrim : BSPhysObject
|
|||
get { return _acceleration; }
|
||||
set { _acceleration = value; }
|
||||
}
|
||||
public override OMV.Quaternion RawOrientation
|
||||
{
|
||||
get { return _orientation; }
|
||||
set { _orientation = value; }
|
||||
}
|
||||
public override OMV.Quaternion Orientation {
|
||||
get {
|
||||
if (!Linkset.IsRoot(this))
|
||||
|
@ -703,7 +713,7 @@ public sealed class BSPrim : BSPhysObject
|
|||
BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
|
||||
|
||||
// A dynamic object has mass
|
||||
UpdatePhysicalMassProperties(MassRaw);
|
||||
UpdatePhysicalMassProperties(RawMass);
|
||||
|
||||
// Set collision detection parameters
|
||||
if (PhysicsScene.Params.ccdMotionThreshold > 0f)
|
||||
|
|
|
@ -811,7 +811,7 @@ public sealed class BSShapeCollection : IDisposable
|
|||
if (prim.IsSolid)
|
||||
{
|
||||
bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr,
|
||||
prim.LocalID, prim.ForcePosition, prim.ForceOrientation);
|
||||
prim.LocalID, prim.RawPosition, prim.RawOrientation);
|
||||
DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue