BulletSim: Add calls to linkset class when object going static or dynamic.
Reset center of mass on an object when going dynamic.connector_plugin
parent
d86cbe6379
commit
7c347f4c5c
|
@ -202,6 +202,24 @@ public class BSLinkset
|
||||||
return com;
|
return com;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The object is going dynamic (physical). Do any setup necessary
|
||||||
|
// for a dynamic linkset.
|
||||||
|
// Return 'true' if any properties updated on the passed object.
|
||||||
|
// Called at taint-time!
|
||||||
|
public bool MakeDynamic(BSPhysObject child)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The object is going static (non-physical). Do any setup necessary
|
||||||
|
// for a static linkset.
|
||||||
|
// Return 'true' if any properties updated on the passed object.
|
||||||
|
// Called at taint-time!
|
||||||
|
public bool MakeStatic(BSPhysObject child)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// When physical properties are changed the linkset needs to recalculate
|
// When physical properties are changed the linkset needs to recalculate
|
||||||
// its internal properties.
|
// its internal properties.
|
||||||
public void Refresh(BSPhysObject requestor)
|
public void Refresh(BSPhysObject requestor)
|
||||||
|
@ -255,13 +273,11 @@ public class BSLinkset
|
||||||
if (!somethingMissing)
|
if (!somethingMissing)
|
||||||
{
|
{
|
||||||
// The root prim takes on the weight of the whole linkset
|
// The root prim takes on the weight of the whole linkset
|
||||||
/*
|
|
||||||
OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(LinksetRoot.BSShape.Ptr, linksetMass);
|
OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(LinksetRoot.BSShape.Ptr, linksetMass);
|
||||||
BulletSimAPI.SetMassProps2(LinksetRoot.BSBody.Ptr, linksetMass, inertia);
|
BulletSimAPI.SetMassProps2(LinksetRoot.BSBody.Ptr, linksetMass, inertia);
|
||||||
OMV.Vector3 centerOfMass = ComputeLinksetCenterOfMass();
|
OMV.Vector3 centerOfMass = ComputeLinksetCenterOfMass();
|
||||||
BulletSimAPI.SetCenterOfMassByPosRot2(LinksetRoot.BSBody.Ptr, centerOfMass, OMV.Quaternion.Identity);
|
BulletSimAPI.SetCenterOfMassByPosRot2(LinksetRoot.BSBody.Ptr, centerOfMass, OMV.Quaternion.Identity);
|
||||||
BulletSimAPI.UpdateInertiaTensor2(LinksetRoot.BSBody.Ptr);
|
BulletSimAPI.UpdateInertiaTensor2(LinksetRoot.BSBody.Ptr);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -530,10 +530,14 @@ public sealed class BSPrim : BSPhysObject
|
||||||
m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
|
m_currentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
|
||||||
// Stop all movement
|
// Stop all movement
|
||||||
BulletSimAPI.ClearAllForces2(BSBody.Ptr);
|
BulletSimAPI.ClearAllForces2(BSBody.Ptr);
|
||||||
|
// Center of mass is at the center of the object
|
||||||
|
BulletSimAPI.SetCenterOfMassByPosRot2(Linkset.LinksetRoot.BSBody.Ptr, _position, _orientation);
|
||||||
// Mass is zero which disables a bunch of physics stuff in Bullet
|
// Mass is zero which disables a bunch of physics stuff in Bullet
|
||||||
BulletSimAPI.SetMassProps2(BSBody.Ptr, 0f, OMV.Vector3.Zero);
|
BulletSimAPI.SetMassProps2(BSBody.Ptr, 0f, OMV.Vector3.Zero);
|
||||||
// There is no inertia in a static object
|
// There is no inertia in a static object
|
||||||
BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
|
BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
|
||||||
|
// There can be special things needed for implementing linksets
|
||||||
|
Linkset.MakeStatic(this);
|
||||||
// The activation state is 'sleeping' so Bullet will not try to act on it
|
// The activation state is 'sleeping' so Bullet will not try to act on it
|
||||||
BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.ISLAND_SLEEPING);
|
BulletSimAPI.ForceActivationState2(BSBody.Ptr, ActivationState.ISLAND_SLEEPING);
|
||||||
}
|
}
|
||||||
|
@ -543,10 +547,12 @@ public sealed class BSPrim : BSPhysObject
|
||||||
m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
|
m_currentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_STATIC_OBJECT);
|
||||||
// A dynamic object has mass
|
// A dynamic object has mass
|
||||||
IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.Ptr);
|
IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.Ptr);
|
||||||
OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, _mass);
|
OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass);
|
||||||
BulletSimAPI.SetMassProps2(BSBody.Ptr, _mass, inertia);
|
BulletSimAPI.SetMassProps2(BSBody.Ptr, _mass, inertia);
|
||||||
// Inertia is based on our new mass
|
// Inertia is based on our new mass
|
||||||
BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
|
BulletSimAPI.UpdateInertiaTensor2(BSBody.Ptr);
|
||||||
|
// There can be special things needed for implementing linksets
|
||||||
|
Linkset.MakeDynamic(this);
|
||||||
// Force activation of the object so Bullet will act on it.
|
// Force activation of the object so Bullet will act on it.
|
||||||
BulletSimAPI.Activate2(BSBody.Ptr, true);
|
BulletSimAPI.Activate2(BSBody.Ptr, true);
|
||||||
}
|
}
|
||||||
|
@ -1055,11 +1061,12 @@ public sealed class BSPrim : BSPhysObject
|
||||||
}// end CalculateMass
|
}// end CalculateMass
|
||||||
#endregion Mass Calculation
|
#endregion Mass Calculation
|
||||||
|
|
||||||
// Create the geometry information in Bullet for later use
|
// Create the geometry information in Bullet for later use.
|
||||||
// The objects needs a hull if it's physical otherwise a mesh is enough
|
// The objects needs a hull if it's physical otherwise a mesh is enough.
|
||||||
// No locking here because this is done when we know physics is not simulating
|
// No locking here because this is done when we know physics is not simulating.
|
||||||
// if 'forceRebuild' is true, the geometry is rebuilt. Otherwise a previously built version is used
|
// if 'forceRebuild' is true, the geometry is rebuilt. Otherwise a previously built version is used.
|
||||||
// Returns 'true' if the geometry was rebuilt
|
// Returns 'true' if the geometry was rebuilt.
|
||||||
|
// Called at taint-time!
|
||||||
private bool CreateGeom(bool forceRebuild)
|
private bool CreateGeom(bool forceRebuild)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -1128,6 +1135,7 @@ public sealed class BSPrim : BSPhysObject
|
||||||
|
|
||||||
// No locking here because this is done when we know physics is not simulating
|
// No locking here because this is done when we know physics is not simulating
|
||||||
// Returns 'true' of a mesh was actually rebuild (we could also have one of these specs).
|
// Returns 'true' of a mesh was actually rebuild (we could also have one of these specs).
|
||||||
|
// Called at taint-time!
|
||||||
private bool CreateGeomMesh()
|
private bool CreateGeomMesh()
|
||||||
{
|
{
|
||||||
// level of detail based on size and type of the object
|
// level of detail based on size and type of the object
|
||||||
|
|
Loading…
Reference in New Issue