From 0acde92af969b3251aec95e4ea08d618da39d184 Mon Sep 17 00:00:00 2001
From: Robert Adams
Date: Wed, 7 Aug 2013 07:54:47 -0700
Subject: BulletSim: add API and calls for spring constraint parameters.

---
 OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs | 36 ++++++++++++++++++++
 OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs   | 38 ++++++++++++++++++++++
 .../Region/Physics/BulletSPlugin/BSApiTemplate.cs  |  8 +++++
 3 files changed, 82 insertions(+)

diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
index 12a0c17..6c36485 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIUnman.cs
@@ -596,6 +596,30 @@ public override bool SetBreakingImpulseThreshold(BulletConstraint constrain, flo
     return BSAPICPP.SetBreakingImpulseThreshold2(constrainu.ptr, threshold);
 }
 
+public override bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse)
+{
+    BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+    return BSAPICPP.ConstraintSpringEnable2(constrainu.ptr, index, numericTrueFalse);
+}
+
+public override bool SpringSetEquilibriumPoint(BulletConstraint constrain, int index, float equilibriumPoint)
+{
+    BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+    return BSAPICPP.ConstraintSpringSetEquilibriumPoint2(constrainu.ptr, index, equilibriumPoint);
+}
+
+public override bool SpringSetStiffness(BulletConstraint constrain, int index, float stiffnesss)
+{
+    BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+    return BSAPICPP.ConstraintSpringSetStiffness2(constrainu.ptr, index, stiffnesss);
+}
+
+public override bool SpringSetDamping(BulletConstraint constrain, int index, float damping)
+{
+    BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
+    return BSAPICPP.ConstraintSpringSetDamping2(constrainu.ptr, index, damping);
+}
+
 public override bool CalculateTransforms(BulletConstraint constrain)
 {
     BulletConstraintUnman constrainu = constrain as BulletConstraintUnman;
@@ -1601,6 +1625,18 @@ 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 ConstraintSpringEnable2(IntPtr constrain, int index, float numericTrueFalse);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool ConstraintSpringSetEquilibriumPoint2(IntPtr constrain, int index, float equilibriumPoint);
+
+[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
+public static extern bool ConstraintSpringSetStiffness2(IntPtr constrain, int index, float stiffness);
+
+[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 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 2a820be..9ad12a9 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSAPIXNA.cs
@@ -752,6 +752,44 @@ private sealed class BulletConstraintXNA : BulletConstraint
         constraint.SetBreakingImpulseThreshold(threshold);
         return true;
     }
+    public override bool SpringEnable(BulletConstraint pConstraint, int index, float numericTrueFalse)
+    {
+        Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint;
+        constraint.EnableSpring(index, (numericTrueFalse == 0f ? false : true));
+        return true;
+    }
+
+    public override bool SpringSetEquilibriumPoint(BulletConstraint pConstraint, int index, float equilibriumPoint)
+    {
+        Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint;
+        if (index == -1)
+        {
+            constraint.SetEquilibriumPoint();
+        }
+        else
+        {
+            if (equilibriumPoint == -1)
+                constraint.SetEquilibriumPoint(index);
+            else
+                constraint.SetEquilibriumPoint(index, equilibriumPoint);
+        }
+        return true;
+    }
+
+    public override bool SpringSetStiffness(BulletConstraint pConstraint, int index, float stiffness)
+    {
+        Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint;
+        constraint.SetStiffness(index, stiffness);
+        return true;
+    }
+
+    public override bool SpringSetDamping(BulletConstraint pConstraint, int index, float damping)
+    {
+        Generic6DofSpringConstraint constraint = (pConstraint as BulletConstraintXNA).constrain as Generic6DofSpringConstraint;
+        constraint.SetDamping(index, damping);
+        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 6cdc112..8cca29f 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSApiTemplate.cs
@@ -441,6 +441,14 @@ public abstract bool TranslationalLimitMotor(BulletConstraint constrain, float e
 
 public abstract bool SetBreakingImpulseThreshold(BulletConstraint constrain, float threshold);
 
+public abstract bool SpringEnable(BulletConstraint constrain, int index, float numericTrueFalse);
+
+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 abstract bool CalculateTransforms(BulletConstraint constrain);
 
 public abstract bool SetConstraintParam(BulletConstraint constrain, ConstraintParams paramIndex, float value, ConstraintParamAxis axis);
-- 
cgit v1.1