BulletSim: add unmanaged and XNA functions for hinge, slider and spring constraints.

0.7.6-extended
Robert Adams 2013-08-07 10:15:28 -07:00 committed by Justin Clark-Casey (justincc)
parent 87aedc44a0
commit 785171109e
3 changed files with 241 additions and 2 deletions

View File

@ -596,6 +596,12 @@ public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, flo
return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold);
}
public override bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.HingeSetLimits2(constrainu.ptr, low, high, softness, bias, relaxation);
}
public override bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
@ -620,6 +626,30 @@ public override bool SpringSetDamping(BulletConstraint constrain, int index, flo
return BSAPICPP.ConstraintSpringSetDamping2(constrainu.ptr, index, damping);
}
public override bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.SliderSetLimits2(constrainu.ptr, lowerUpper, linAng, val);
}
public override bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.SliderSet2(constrainu.ptr, softRestDamp, dirLimOrtho, linAng, val);
}
public override bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.SliderMotorEnable2(constrainu.ptr, linAng, numericTrueFalse);
}
public override bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
return BSAPICPP.SliderMotor2(constrainu.ptr, forceVel, linAng, val);
}
public override bool CalculateTransforms(BulletConstraint constrain)
{
BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
@ -1624,6 +1654,9 @@ public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enabl
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SetBreakingImpulseThreshold2(IntPtr constrain, float threshold);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool HingeSetLimits2(IntPtr constrain, float low, float high, float softness, float bias, float relaxation);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool ConstraintSpringEnable2(IntPtr constrain, int index, float numericTrueFalse);
@ -1636,6 +1669,18 @@ public static extern bool ConstraintSpringSetStiffness2(IntPtr constrain, int in
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool ConstraintSpringSetDamping2(IntPtr constrain, int index, float damping);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SliderSetLimits2(IntPtr constrain, int lowerUpper, int linAng, float val);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SliderSet2(IntPtr constrain, int softRestDamp, int dirLimOrtho, int linAng, float val);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SliderMotorEnable2(IntPtr constrain, int linAng, float numericTrueFalse);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool SliderMotor2(IntPtr constrain, int forceVel, int linAng, float val);
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern bool CalculateTransforms2(IntPtr constrain);

View File

@ -752,6 +752,15 @@ private sealed class BulletConstraintXNA : BulletConstraint
constraint.SetBreakingImpulseThreshold(threshold);
return true;
}
public override bool HingeSetLimits(BulletConstraint pConstraint, float low, float high, float softness, float bias, float relaxation)
{
HingeConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as HingeConstraint;
if (softness == HINGE_NOT_SPECIFIED)
constraint.SetLimit(low, high);
else
constraint.SetLimit(low, high, softness, bias, relaxation);
return true;
}
public override bool SpringEnable(BulletConstraint pConstraint, int index, float numericTrueFalse)
{
Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint;
@ -762,13 +771,13 @@ private sealed class BulletConstraintXNA : BulletConstraint
public override bool SpringSetEquilibriumPoint(BulletConstraint pConstraint, int index, float equilibriumPoint)
{
Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint;
if (index == -1)
if (index == SPRING_NOT_SPECIFIED)
{
constraint.SetEquilibriumPoint();
}
else
{
if (equilibriumPoint == -1)
if (equilibriumPoint == SPRING_NOT_SPECIFIED)
constraint.SetEquilibriumPoint(index);
else
constraint.SetEquilibriumPoint(index, equilibriumPoint);
@ -790,6 +799,167 @@ private sealed class BulletConstraintXNA : BulletConstraint
return true;
}
public override bool SliderSetLimits(BulletConstraint pConstraint, int lowerUpper, int linAng, float val)
{
SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint;
switch (lowerUpper)
{
case SLIDER_LOWER_LIMIT:
switch (linAng)
{
case SLIDER_LINEAR:
constraint.SetLowerLinLimit(val);
break;
case SLIDER_ANGULAR:
constraint.SetLowerAngLimit(val);
break;
}
break;
case SLIDER_UPPER_LIMIT:
switch (linAng)
{
case SLIDER_LINEAR:
constraint.SetUpperLinLimit(val);
break;
case SLIDER_ANGULAR:
constraint.SetUpperAngLimit(val);
break;
}
break;
}
return true;
}
public override bool SliderSet(BulletConstraint pConstraint, int softRestDamp, int dirLimOrtho, int linAng, float val)
{
SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint;
switch (softRestDamp)
{
case SLIDER_SET_SOFTNESS:
switch (dirLimOrtho)
{
case SLIDER_SET_DIRECTION:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetSoftnessDirLin(val); break;
case SLIDER_ANGULAR: constraint.SetSoftnessDirAng(val); break;
}
break;
case SLIDER_SET_LIMIT:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetSoftnessLimLin(val); break;
case SLIDER_ANGULAR: constraint.SetSoftnessLimAng(val); break;
}
break;
case SLIDER_SET_ORTHO:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetSoftnessOrthoLin(val); break;
case SLIDER_ANGULAR: constraint.SetSoftnessOrthoAng(val); break;
}
break;
}
break;
case SLIDER_SET_RESTITUTION:
switch (dirLimOrtho)
{
case SLIDER_SET_DIRECTION:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetRestitutionDirLin(val); break;
case SLIDER_ANGULAR: constraint.SetRestitutionDirAng(val); break;
}
break;
case SLIDER_SET_LIMIT:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetRestitutionLimLin(val); break;
case SLIDER_ANGULAR: constraint.SetRestitutionLimAng(val); break;
}
break;
case SLIDER_SET_ORTHO:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetRestitutionOrthoLin(val); break;
case SLIDER_ANGULAR: constraint.SetRestitutionOrthoAng(val); break;
}
break;
}
break;
case SLIDER_SET_DAMPING:
switch (dirLimOrtho)
{
case SLIDER_SET_DIRECTION:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetDampingDirLin(val); break;
case SLIDER_ANGULAR: constraint.SetDampingDirAng(val); break;
}
break;
case SLIDER_SET_LIMIT:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetDampingLimLin(val); break;
case SLIDER_ANGULAR: constraint.SetDampingLimAng(val); break;
}
break;
case SLIDER_SET_ORTHO:
switch (linAng)
{
case SLIDER_LINEAR: constraint.SetDampingOrthoLin(val); break;
case SLIDER_ANGULAR: constraint.SetDampingOrthoAng(val); break;
}
break;
}
break;
}
return true;
}
public override bool SliderMotorEnable(BulletConstraint pConstraint, int linAng, float numericTrueFalse)
{
SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint;
switch (linAng)
{
case SLIDER_LINEAR:
constraint.SetPoweredLinMotor(numericTrueFalse == 0.0 ? false : true);
break;
case SLIDER_ANGULAR:
constraint.SetPoweredAngMotor(numericTrueFalse == 0.0 ? false : true);
break;
}
return true;
}
public override bool SliderMotor(BulletConstraint pConstraint, int forceVel, int linAng, float val)
{
SliderConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as SliderConstraint;
switch (forceVel)
{
case SLIDER_MOTOR_VELOCITY:
switch (linAng)
{
case SLIDER_LINEAR:
constraint.SetTargetLinMotorVelocity(val);
break;
case SLIDER_ANGULAR:
constraint.SetTargetAngMotorVelocity(val);
break;
}
break;
case SLIDER_MAX_MOTOR_FORCE:
switch (linAng)
{
case SLIDER_LINEAR:
constraint.SetMaxLinMotorForce(val);
break;
case SLIDER_ANGULAR:
constraint.SetMaxAngMotorForce(val);
break;
}
break;
}
return true;
}
//BulletSimAPI.SetAngularDamping(Prim.PhysBody.ptr, angularDamping);
public override void SetAngularDamping(BulletBody pBody, float angularDamping)
{

View File

@ -441,14 +441,38 @@ public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float e
public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
public const int HINGE_NOT_SPECIFIED = -1;
public abstract bool HingeSetLimits(BulletConstraint constrain, float low, float high, float softness, float bias, float relaxation);
public abstract bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse);
public const int SPRING_NOT_SPECIFIED = -1;
public abstract bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint);
public abstract bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss);
public abstract bool SpringSetDamping(BulletConstraint constrain, int index, float damping);
public const int SLIDER_LOWER_LIMIT = 0;
public const int SLIDER_UPPER_LIMIT = 1;
public const int SLIDER_LINEAR = 2;
public const int SLIDER_ANGULAR = 3;
public abstract bool SliderSetLimits(BulletConstraint constrain, int lowerUpper, int linAng, float val);
public const int SLIDER_SET_SOFTNESS = 4;
public const int SLIDER_SET_RESTITUTION = 5;
public const int SLIDER_SET_DAMPING = 6;
public const int SLIDER_SET_DIRECTION = 7;
public const int SLIDER_SET_LIMIT = 8;
public const int SLIDER_SET_ORTHO = 9;
public abstract bool SliderSet(BulletConstraint constrain, int softRestDamp, int dirLimOrtho, int linAng, float val);
public abstract bool SliderMotorEnable(BulletConstraint constrain, int linAng, float numericTrueFalse);
public const int SLIDER_MOTOR_VELOCITY = 10;
public const int SLIDER_MAX_MOTOR_FORCE = 11;
public abstract bool SliderMotor(BulletConstraint constrain, int forceVel, int linAng, float val);
public abstract bool CalculateTransforms(BulletConstraint constrain);
public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);