BulletSim: add LSL function and plumbing for setting a spring

equilibrium point in the physics engine constraint.
0.7.6-extended
Robert Adams 2013-09-09 14:53:16 -07:00 committed by Justin Clark-Casey (justincc)
parent bde8ac6a5c
commit 4179d8f651
4 changed files with 40 additions and 3 deletions

View File

@ -408,8 +408,10 @@ public class ExtendedPhysics : INonSharedRegionModule
public const int PHYS_PARAM_LINK_TYPE = 14419;
[ScriptConstant]
public const int PHYS_PARAM_USE_LINEAR_FRAMEA = 14420;
[ScriptConstant]
public const int PHYS_PARAM_SPRING_EQUILIBRIUM_POINT = 14421;
public const int PHYS_PARAM_MAX = 14420;
public const int PHYS_PARAM_MAX = 14421;
// Used when specifying a parameter that has settings for the three linear and three angular axis
[ScriptConstant]

View File

@ -64,7 +64,7 @@ public abstract class BSConstraint : IDisposable
{
bool success = PhysicsScene.PE.DestroyConstraint(m_world, m_constraint);
m_world.physicsScene.DetailLog("{0},BSConstraint.Dispose,taint,id1={1},body1={2},id2={3},body2={4},success={5}",
BSScene.DetailLogZero,
m_body1.ID,
m_body1.ID, m_body1.AddrString,
m_body2.ID, m_body2.AddrString,
success);
@ -77,7 +77,10 @@ public abstract class BSConstraint : IDisposable
{
bool ret = false;
if (m_enabled)
{
m_world.physicsScene.DetailLog("{0},BSConstraint.SetLinearLimits,taint,low={1},high={2}", m_body1.ID, low, high);
ret = PhysicsScene.PE.SetLinearLimits(m_constraint, low, high);
}
return ret;
}
@ -86,6 +89,7 @@ public abstract class BSConstraint : IDisposable
bool ret = false;
if (m_enabled)
{
m_world.physicsScene.DetailLog("{0},BSConstraint.SetAngularLimits,taint,low={1},high={2}", m_body1.ID, low, high);
ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high);
}
return ret;

View File

@ -85,6 +85,19 @@ public sealed class BSConstraintSpring : BSConstraint6Dof
return true;
}
public bool SetEquilibriumPoint(Vector3 linearEq, Vector3 angularEq)
{
PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},linearEq={3},angularEq={4}",
m_body1.ID, m_body1.ID, m_body2.ID, linearEq, angularEq);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 0, linearEq.X);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 1, linearEq.Y);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 2, linearEq.Z);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 3, angularEq.X);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 4, angularEq.Y);
PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 5, angularEq.Z);
return true;
}
}
}

View File

@ -63,6 +63,8 @@ public sealed class BSLinksetConstraints : BSLinkset
public bool[] springAxisEnable;
public float[] springDamping;
public float[] springStiffness;
public OMV.Vector3 springLinearEquilibriumPoint;
public OMV.Vector3 springAngularEquilibriumPoint;
public BSLinkInfoConstraint(BSPrimLinkable pMember)
: base(pMember)
@ -102,6 +104,8 @@ public sealed class BSLinksetConstraints : BSLinkset
springDamping[ii] = BSAPITemplate.SPRING_NOT_SPECIFIED;
springStiffness[ii] = BSAPITemplate.SPRING_NOT_SPECIFIED;
}
springLinearEquilibriumPoint = OMV.Vector3.Zero;
springAngularEquilibriumPoint = OMV.Vector3.Zero;
member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.ResetLink", member.LocalID);
}
@ -155,7 +159,12 @@ public sealed class BSLinksetConstraints : BSLinkset
if (springStiffness[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED)
constrainSpring.SetStiffness(ii, springStiffness[ii]);
}
constrainSpring.SetEquilibriumPoint(BSAPITemplate.SPRING_NOT_SPECIFIED, BSAPITemplate.SPRING_NOT_SPECIFIED);
constrainSpring.CalculateTransforms();
if (springLinearEquilibriumPoint != OMV.Vector3.Zero)
constrainSpring.SetEquilibriumPoint(springLinearEquilibriumPoint, springAngularEquilibriumPoint);
else
constrainSpring.SetEquilibriumPoint(BSAPITemplate.SPRING_NOT_SPECIFIED, BSAPITemplate.SPRING_NOT_SPECIFIED);
}
break;
default:
@ -618,6 +627,7 @@ public sealed class BSLinksetConstraints : BSLinkset
float valueFloat;
bool valueBool;
OMV.Vector3 valueVector;
OMV.Vector3 valueVector2;
OMV.Quaternion valueQuaternion;
int axisLow, axisHigh;
@ -764,6 +774,14 @@ public sealed class BSLinksetConstraints : BSLinkset
linkInfo.springStiffness[ii] = valueFloat;
opIndex += 3;
break;
case ExtendedPhysics.PHYS_PARAM_SPRING_EQUILIBRIUM_POINT:
errMsg = "PHYS_PARAM_SPRING_EQUILIBRIUM_POINT takes two parameters of type vector";
valueVector = (OMV.Vector3)pParams[opIndex + 1];
valueVector2 = (OMV.Vector3)pParams[opIndex + 2];
linkInfo.springLinearEquilibriumPoint = valueVector;
linkInfo.springAngularEquilibriumPoint = valueVector2;
opIndex += 3;
break;
case ExtendedPhysics.PHYS_PARAM_USE_LINEAR_FRAMEA:
errMsg = "PHYS_PARAM_USE_LINEAR_FRAMEA takes one parameter of type integer (bool)";
valueBool = ((int)pParams[opIndex + 1]) != 0;