diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs new file mode 100644 index 0000000..0181d9d --- /dev/null +++ b/OpenSim/Region/Physics/BulletSNPlugin/BSConstraint6Dof.cs | |||
@@ -0,0 +1,153 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyrightD | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BulletSNPlugin | ||
33 | { | ||
34 | |||
35 | public sealed class BSConstraint6Dof : BSConstraint | ||
36 | { | ||
37 | private static string LogHeader = "[BULLETSIM 6DOF CONSTRAINT]"; | ||
38 | |||
39 | public override ConstraintType Type { get { return ConstraintType.D6_CONSTRAINT_TYPE; } } | ||
40 | |||
41 | // Create a btGeneric6DofConstraint | ||
42 | public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2, | ||
43 | Vector3 frame1, Quaternion frame1rot, | ||
44 | Vector3 frame2, Quaternion frame2rot, | ||
45 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
46 | { | ||
47 | m_world = world; | ||
48 | m_body1 = obj1; | ||
49 | m_body2 = obj2; | ||
50 | m_constraint = new BulletConstraint( | ||
51 | BulletSimAPI.Create6DofConstraint2(m_world.ptr, m_body1.ptr, m_body2.ptr, | ||
52 | frame1, frame1rot, | ||
53 | frame2, frame2rot, | ||
54 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
55 | m_enabled = true; | ||
56 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createFrame,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | ||
57 | BSScene.DetailLogZero, world.worldID, | ||
58 | obj1.ID, obj1.ptr.ToString(), obj2.ID, obj2.ptr.ToString()); | ||
59 | } | ||
60 | |||
61 | public BSConstraint6Dof(BulletSim world, BulletBody obj1, BulletBody obj2, | ||
62 | Vector3 joinPoint, | ||
63 | bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) | ||
64 | { | ||
65 | m_world = world; | ||
66 | m_body1 = obj1; | ||
67 | m_body2 = obj2; | ||
68 | if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody) | ||
69 | { | ||
70 | world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | ||
71 | BSScene.DetailLogZero, world.worldID, | ||
72 | obj1.ID, obj1.ptr.ToString(), obj2.ID, obj2.ptr.ToString()); | ||
73 | world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}", | ||
74 | LogHeader, world.worldID, obj1.ID, obj1.ptr.ToString(), obj2.ID, obj2.ptr.ToString()); | ||
75 | m_enabled = false; | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | m_constraint = new BulletConstraint( | ||
80 | BulletSimAPI.Create6DofConstraintToPoint2(m_world.ptr, m_body1.ptr, m_body2.ptr, | ||
81 | joinPoint, | ||
82 | useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies)); | ||
83 | world.physicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}", | ||
84 | BSScene.DetailLogZero, world.worldID, m_constraint.ptr.ToString(), | ||
85 | obj1.ID, obj1.ptr.ToString(), obj2.ID, obj2.ptr.ToString()); | ||
86 | if (!m_constraint.HasPhysicalConstraint) | ||
87 | { | ||
88 | world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}", | ||
89 | LogHeader, obj1.ID, obj2.ID); | ||
90 | m_enabled = false; | ||
91 | } | ||
92 | else | ||
93 | { | ||
94 | m_enabled = true; | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public bool SetFrames(Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot) | ||
100 | { | ||
101 | bool ret = false; | ||
102 | if (m_enabled) | ||
103 | { | ||
104 | BulletSimAPI.SetFrames2(m_constraint.ptr, frameA, frameArot, frameB, frameBrot); | ||
105 | ret = true; | ||
106 | } | ||
107 | return ret; | ||
108 | } | ||
109 | |||
110 | public bool SetCFMAndERP(float cfm, float erp) | ||
111 | { | ||
112 | bool ret = false; | ||
113 | if (m_enabled) | ||
114 | { | ||
115 | BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL); | ||
116 | BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL); | ||
117 | BulletSimAPI.SetConstraintParam2(m_constraint.ptr, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL); | ||
118 | ret = true; | ||
119 | } | ||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | public bool UseFrameOffset(bool useOffset) | ||
124 | { | ||
125 | bool ret = false; | ||
126 | float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; | ||
127 | if (m_enabled) | ||
128 | ret = BulletSimAPI.UseFrameOffset2(m_constraint.ptr, onOff); | ||
129 | return ret; | ||
130 | } | ||
131 | |||
132 | public bool TranslationalLimitMotor(bool enable, float targetVelocity, float maxMotorForce) | ||
133 | { | ||
134 | bool ret = false; | ||
135 | float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse; | ||
136 | if (m_enabled) | ||
137 | { | ||
138 | ret = BulletSimAPI.TranslationalLimitMotor2(m_constraint.ptr, onOff, targetVelocity, maxMotorForce); | ||
139 | m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}", | ||
140 | BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce); | ||
141 | } | ||
142 | return ret; | ||
143 | } | ||
144 | |||
145 | public bool SetBreakingImpulseThreshold(float threshold) | ||
146 | { | ||
147 | bool ret = false; | ||
148 | if (m_enabled) | ||
149 | ret = BulletSimAPI.SetBreakingImpulseThreshold2(m_constraint.ptr, threshold); | ||
150 | return ret; | ||
151 | } | ||
152 | } | ||
153 | } | ||