From 993bcec088ce5c3ec2f76f61842f19cbdcc89384 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 7 Aug 2013 10:15:28 -0700 Subject: BulletSim: add unmanaged and XNA functions for hinge, slider and spring constraints. --- OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 45 ++++++ OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs | 174 ++++++++++++++++++++- .../Region/Physics/BulletSPlugin/BSApiTemplate.cs | 24 +++ 3 files changed, 241 insertions(+), 2 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs index 6c36485..8dfb01c 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs @@ -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; @@ -1625,6 +1655,9 @@ public static extern bool TranslationalLimitMotor2(IntPtr constrain, float enabl 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); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] @@ -1637,6 +1670,18 @@ public static extern bool ConstraintSpringSetStiffness2(IntPtr constrain, int in 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); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs index 9ad12a9..ff2b497 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs @@ -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) { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs index 8cca29f..b241059 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs @@ -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); -- cgit v1.1