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.

integration
Robert Adams 2012-11-01 10:53:55 -07:00
parent 39c02dcc8c
commit f53b4e7a21
5 changed files with 39 additions and 17 deletions

View File

@ -97,7 +97,7 @@ public sealed class BSCharacter : BSPhysObject
// set _avatarVolume and _mass based on capsule size, _density and Scale // set _avatarVolume and _mass based on capsule size, _density and Scale
ComputeAvatarVolumeAndMass(); ComputeAvatarVolumeAndMass();
DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", 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 // do actual create at taint time
PhysicsScene.TaintedObject("BSCharacter.create", delegate() PhysicsScene.TaintedObject("BSCharacter.create", delegate()
@ -141,7 +141,7 @@ public sealed class BSCharacter : BSPhysObject
BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius);
} }
UpdatePhysicalMassProperties(MassRaw); UpdatePhysicalMassProperties(RawMass);
// Make so capsule does not fall over // Make so capsule does not fall over
BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero); BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero);
@ -181,12 +181,12 @@ public sealed class BSCharacter : BSPhysObject
ComputeAvatarScale(_size); ComputeAvatarScale(_size);
ComputeAvatarVolumeAndMass(); ComputeAvatarVolumeAndMass();
DetailLog("{0},BSCharacter.setSize,call,scale={1},density={2},volume={3},mass={4}", 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() PhysicsScene.TaintedObject("BSCharacter.setSize", delegate()
{ {
BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale); 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 void LockAngularMotion(OMV.Vector3 axis) { return; }
public override OMV.Vector3 RawPosition
{
get { return _position; }
set { _position = value; }
}
public override OMV.Vector3 Position { public override OMV.Vector3 Position {
get { get {
// _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID); // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID);
@ -316,7 +321,7 @@ public sealed class BSCharacter : BSPhysObject
public override float Mass { get { return _mass; } } public override float Mass { get { return _mass; } }
// used when we only want this prim's mass and not the linkset thing // 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; } get {return _mass; }
} }
public override void UpdatePhysicalMassProperties(float physMass) public override void UpdatePhysicalMassProperties(float physMass)
@ -405,6 +410,11 @@ public sealed class BSCharacter : BSPhysObject
get { return _acceleration; } get { return _acceleration; }
set { _acceleration = value; } set { _acceleration = value; }
} }
public override OMV.Quaternion RawOrientation
{
get { return _orientation; }
set { _orientation = value; }
}
public override OMV.Quaternion Orientation { public override OMV.Quaternion Orientation {
get { return _orientation; } get { return _orientation; }
set { set {

View File

@ -106,7 +106,7 @@ public abstract class BSLinkset
PhysicsScene = scene; PhysicsScene = scene;
LinksetRoot = parent; LinksetRoot = parent;
m_children = new HashSet<BSPhysObject>(); m_children = new HashSet<BSPhysObject>();
m_mass = parent.MassRaw; m_mass = parent.RawMass;
} }
// Link to a linkset where the child knows the parent. // Link to a linkset where the child knows the parent.
@ -242,14 +242,14 @@ public abstract class BSLinkset
// ================================================================ // ================================================================
protected virtual float ComputeLinksetMass() protected virtual float ComputeLinksetMass()
{ {
float mass = LinksetRoot.MassRaw; float mass = LinksetRoot.RawMass;
if (HasAnyChildren) if (HasAnyChildren)
{ {
lock (m_linksetActivityLock) lock (m_linksetActivityLock)
{ {
foreach (BSPhysObject bp in m_children) foreach (BSPhysObject bp in m_children)
{ {
mass += bp.MassRaw; mass += bp.RawMass;
} }
} }
} }
@ -261,13 +261,13 @@ public abstract class BSLinkset
OMV.Vector3 com; OMV.Vector3 com;
lock (m_linksetActivityLock) lock (m_linksetActivityLock)
{ {
com = LinksetRoot.Position * LinksetRoot.MassRaw; com = LinksetRoot.Position * LinksetRoot.RawMass;
float totalMass = LinksetRoot.MassRaw; float totalMass = LinksetRoot.RawMass;
foreach (BSPhysObject bp in m_children) foreach (BSPhysObject bp in m_children)
{ {
com += bp.Position * bp.MassRaw; com += bp.Position * bp.RawMass;
totalMass += bp.MassRaw; totalMass += bp.RawMass;
} }
if (totalMass != 0f) if (totalMass != 0f)
com /= totalMass; com /= totalMass;
@ -285,7 +285,7 @@ public abstract class BSLinkset
foreach (BSPhysObject bp in m_children) foreach (BSPhysObject bp in m_children)
{ {
com += bp.Position * bp.MassRaw; com += bp.Position * bp.RawMass;
} }
com /= (m_children.Count + 1); com /= (m_children.Count + 1);
} }

View File

@ -63,7 +63,7 @@ public abstract class BSPhysObject : PhysicsActor
public BSLinkset Linkset { get; set; } public BSLinkset Linkset { get; set; }
// Return the object mass without calculating it or having side effects // 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, ...) // Set the raw mass but also update physical mass properties (inertia, ...)
public abstract void UpdatePhysicalMassProperties(float mass); public abstract void UpdatePhysicalMassProperties(float mass);
@ -105,8 +105,10 @@ public abstract class BSPhysObject : PhysicsActor
// Tell the object to clean up. // Tell the object to clean up.
public abstract void Destroy(); public abstract void Destroy();
public abstract OMV.Vector3 RawPosition { get; set; }
public abstract OMV.Vector3 ForcePosition { 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.Quaternion ForceOrientation { get; set; }
public abstract OMV.Vector3 ForceVelocity { get; set; } public abstract OMV.Vector3 ForceVelocity { get; set; }

View File

@ -256,6 +256,11 @@ public sealed class BSPrim : BSPhysObject
return; return;
} }
public override OMV.Vector3 RawPosition
{
get { return _position; }
set { _position = value; }
}
public override OMV.Vector3 Position { public override OMV.Vector3 Position {
get { get {
if (!Linkset.IsRoot(this)) 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 // 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; } get { return _mass; }
} }
// Set the physical mass to the passed mass. // Set the physical mass to the passed mass.
@ -530,6 +535,11 @@ public sealed class BSPrim : BSPhysObject
get { return _acceleration; } get { return _acceleration; }
set { _acceleration = value; } set { _acceleration = value; }
} }
public override OMV.Quaternion RawOrientation
{
get { return _orientation; }
set { _orientation = value; }
}
public override OMV.Quaternion Orientation { public override OMV.Quaternion Orientation {
get { get {
if (!Linkset.IsRoot(this)) if (!Linkset.IsRoot(this))
@ -703,7 +713,7 @@ public sealed class BSPrim : BSPhysObject
BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation); BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
// A dynamic object has mass // A dynamic object has mass
UpdatePhysicalMassProperties(MassRaw); UpdatePhysicalMassProperties(RawMass);
// Set collision detection parameters // Set collision detection parameters
if (PhysicsScene.Params.ccdMotionThreshold > 0f) if (PhysicsScene.Params.ccdMotionThreshold > 0f)

View File

@ -811,7 +811,7 @@ public sealed class BSShapeCollection : IDisposable
if (prim.IsSolid) if (prim.IsSolid)
{ {
bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, 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")); DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X"));
} }
else else