BulletSim: add parameters for setting linkset constraint factors

0.7.4.1
Robert Adams 2012-07-25 14:52:17 -07:00
parent 75f7721b0c
commit d7add2940a
3 changed files with 38 additions and 17 deletions

View File

@ -1295,10 +1295,9 @@ public sealed class BSPrim : PhysicsActor
// relative to each other. // relative to each other.
void CreateLinkset() void CreateLinkset()
{ {
DebugLog("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1); // DebugLog("{0}: CreateLinkset. Root prim={1}, prims={2}", LogHeader, LocalID, _childrenPrims.Count+1);
// remove any constraints that might be in place // remove any constraints that might be in place
DebugLog("{0}: CreateLinkset: RemoveConstraints between me and any children", LogHeader, LocalID);
UnlinkAllChildren(); UnlinkAllChildren();
// create constraints between the root prim and each of the children // create constraints between the root prim and each of the children
@ -1324,18 +1323,8 @@ public sealed class BSPrim : PhysicsActor
// create a constraint that allows no freedom of movement between the two objects // create a constraint that allows no freedom of movement between the two objects
// http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID); // DebugLog("{0}: CreateLinkset: Adding a constraint between root prim {1} and child prim {2}", LogHeader, LocalID, childPrim.LocalID);
DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID); DetailLog("{0},LinkAChildToMe,taint,root={1},child={2}", LocalID, LocalID, childPrim.LocalID);
/*
BulletSimAPI.AddConstraint(_scene.WorldID, LocalID, childPrim.LocalID,
childRelativePosition,
childRelativeRotation,
OMV.Vector3.Zero,
OMV.Quaternion.Identity,
OMV.Vector3.Zero, OMV.Vector3.Zero,
OMV.Vector3.Zero, OMV.Vector3.Zero);
*/
// BSConstraint constrain = new BSConstraint(_scene.World, this.Body, childPrim.Body,
BSConstraint constrain = _scene.Constraints.CreateConstraint( BSConstraint constrain = _scene.Constraints.CreateConstraint(
_scene.World, this.Body, childPrim.Body, _scene.World, this.Body, childPrim.Body,
childRelativePosition, childRelativePosition,
@ -1346,8 +1335,13 @@ public sealed class BSPrim : PhysicsActor
constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero); constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
// tweek the constraint to increase stability // tweek the constraint to increase stability
constrain.UseFrameOffset(true); constrain.UseFrameOffset(_scene.BoolNumeric(_scene.Params.linkConstraintUseFrameOffset));
constrain.TranslationalLimitMotor(true, 5f, 0.1f); if (_scene.BoolNumeric(_scene.Params.linkConstraintEnableTransMotor))
{
constrain.TranslationalLimitMotor(true,
_scene.Params.linkConstraintTransMotorMaxVel,
_scene.Params.linkConstraintTransMotorMaxForce);
}
} }
// Remove linkage between myself and a particular child // Remove linkage between myself and a particular child

View File

@ -1025,6 +1025,27 @@ public class BSScene : PhysicsScene, IPhysicsParameters
(s) => { return s.m_params[0].numberOfSolverIterations; }, (s) => { return s.m_params[0].numberOfSolverIterations; },
(s,p,l,v) => { s.m_params[0].numberOfSolverIterations = v; } ), (s,p,l,v) => { s.m_params[0].numberOfSolverIterations = v; } ),
new ParameterDefn("LinkConstraintUseFrameOffset", "For linksets built with constraints, enable frame offsetFor linksets built with constraints, enable frame offset.",
ConfigurationParameters.numericTrue,
(s,cf,p,v) => { s.m_params[0].linkConstraintUseFrameOffset = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); },
(s) => { return s.m_params[0].linkConstraintUseFrameOffset; },
(s,p,l,v) => { s.m_params[0].linkConstraintUseFrameOffset = v; } ),
new ParameterDefn("LinkConstraintEnableTransMotor", "Whether to enable translational motor on linkset constraints",
ConfigurationParameters.numericTrue,
(s,cf,p,v) => { s.m_params[0].linkConstraintEnableTransMotor = s.NumericBool(cf.GetBoolean(p, s.BoolNumeric(v))); },
(s) => { return s.m_params[0].linkConstraintEnableTransMotor; },
(s,p,l,v) => { s.m_params[0].linkConstraintEnableTransMotor = v; } ),
new ParameterDefn("LinkConstraintTransMotorMaxVel", "Maximum velocity to be applied by translational motor in linkset constraints",
5.0f,
(s,cf,p,v) => { s.m_params[0].linkConstraintTransMotorMaxVel = cf.GetFloat(p, v); },
(s) => { return s.m_params[0].linkConstraintTransMotorMaxVel; },
(s,p,l,v) => { s.m_params[0].linkConstraintTransMotorMaxVel = v; } ),
new ParameterDefn("LinkConstraintTransMotorMaxForce", "Maximum force to be applied by translational motor in linkset constraints",
0.1f,
(s,cf,p,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = cf.GetFloat(p, v); },
(s) => { return s.m_params[0].linkConstraintTransMotorMaxForce; },
(s,p,l,v) => { s.m_params[0].linkConstraintTransMotorMaxForce = v; } ),
new ParameterDefn("DetailedStats", "Frames between outputting detailed phys stats. (0 is off)", new ParameterDefn("DetailedStats", "Frames between outputting detailed phys stats. (0 is off)",
0f, 0f,
(s,cf,p,v) => { s.m_detailedStatsStep = cf.GetInt(p, (int)v); }, (s,cf,p,v) => { s.m_detailedStatsStep = cf.GetInt(p, (int)v); },
@ -1039,13 +1060,13 @@ public class BSScene : PhysicsScene, IPhysicsParameters
}; };
// Convert a boolean to our numeric true and false values // Convert a boolean to our numeric true and false values
protected float NumericBool(bool b) public float NumericBool(bool b)
{ {
return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse); return (b ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse);
} }
// Convert numeric true and false values to a boolean // Convert numeric true and false values to a boolean
protected bool BoolNumeric(float b) public bool BoolNumeric(float b)
{ {
return (b == ConfigurationParameters.numericTrue ? true : false); return (b == ConfigurationParameters.numericTrue ? true : false);
} }

View File

@ -914,6 +914,12 @@
ShouldEnableFrictionCaching = False; ShouldEnableFrictionCaching = False;
NumberOfSolverIterations = 0; NumberOfSolverIterations = 0;
; Linkset constraint parameters
LinkConstraintUseFrameOffset = True;
LinkConstraintEnableTransMotor = True;
LinkConstraintTransMotorMaxVel = 5.0;
LinkConstraintTransMotorMaxForce = 0.1;
; Whether to mesh sculpties ; Whether to mesh sculpties
MeshSculptedPrim = true MeshSculptedPrim = true