aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs
diff options
context:
space:
mode:
authorDiva Canto2015-08-30 20:06:53 -0700
committerDiva Canto2015-08-30 20:06:53 -0700
commit1d6b33bc2da3b312cff1d1802a73aacdf72b0385 (patch)
tree393736b501aac3b31eb0810bb72d926c7f14fbf8 /OpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs
parentMoved instantiation of SceneCommunicationService object to inside the scene c... (diff)
downloadopensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.zip
opensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.gz
opensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.bz2
opensim-SC-1d6b33bc2da3b312cff1d1802a73aacdf72b0385.tar.xz
Major renaming of Physics dlls / folders. No functional changes, just renames.
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs')
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs180
1 files changed, 180 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs b/OpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs
new file mode 100755
index 0000000..7fcb75c
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSConstraint6Dof.cs
@@ -0,0 +1,180 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30using OpenMetaverse;
31
32namespace OpenSim.Region.Physics.BulletSPlugin
33{
34
35public 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 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2) :base(world)
42 {
43 m_body1 = obj1;
44 m_body2 = obj2;
45 m_enabled = false;
46 }
47
48 // Create a btGeneric6DofConstraint
49 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
50 Vector3 frame1, Quaternion frame1rot,
51 Vector3 frame2, Quaternion frame2rot,
52 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
53 : base(world)
54 {
55 m_body1 = obj1;
56 m_body2 = obj2;
57 m_constraint = PhysicsScene.PE.Create6DofConstraint(m_world, m_body1, m_body2,
58 frame1, frame1rot,
59 frame2, frame2rot,
60 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
61 m_enabled = true;
62 PhysicsScene.DetailLog("{0},BS6DofConstraint,create,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
63 m_body1.ID, world.worldID,
64 obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
65 PhysicsScene.DetailLog("{0},BS6DofConstraint,create, f1Loc={1},f1Rot={2},f2Loc={3},f2Rot={4},usefA={5},disCol={6}",
66 m_body1.ID, frame1, frame1rot, frame2, frame2rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
67 }
68
69 // 6 Dof constraint based on a midpoint between the two constrained bodies
70 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, BulletBody obj2,
71 Vector3 joinPoint,
72 bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
73 : base(world)
74 {
75 m_body1 = obj1;
76 m_body2 = obj2;
77 if (!obj1.HasPhysicalBody || !obj2.HasPhysicalBody)
78 {
79 world.physicsScene.DetailLog("{0},BS6DOFConstraint,badBodyPtr,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
80 BSScene.DetailLogZero, world.worldID,
81 obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
82 world.physicsScene.Logger.ErrorFormat("{0} Attempt to build 6DOF constraint with missing bodies: wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
83 LogHeader, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
84 m_enabled = false;
85 }
86 else
87 {
88 m_constraint = PhysicsScene.PE.Create6DofConstraintToPoint(m_world, m_body1, m_body2,
89 joinPoint,
90 useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
91
92 PhysicsScene.DetailLog("{0},BS6DofConstraint,createMidPoint,wID={1}, csrt={2}, rID={3}, rBody={4}, cID={5}, cBody={6}",
93 m_body1.ID, world.worldID, m_constraint.AddrString,
94 obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
95
96 if (!m_constraint.HasPhysicalConstraint)
97 {
98 world.physicsScene.Logger.ErrorFormat("{0} Failed creation of 6Dof constraint. rootID={1}, childID={2}",
99 LogHeader, obj1.ID, obj2.ID);
100 m_enabled = false;
101 }
102 else
103 {
104 m_enabled = true;
105 }
106 }
107 }
108
109 // A 6 Dof constraint that is fixed in the world and constrained to a on-the-fly created static object
110 public BSConstraint6Dof(BulletWorld world, BulletBody obj1, Vector3 frameInBloc, Quaternion frameInBrot,
111 bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies)
112 : base(world)
113 {
114 m_body1 = obj1;
115 m_body2 = obj1; // Look out for confusion down the road
116 m_constraint = PhysicsScene.PE.Create6DofConstraintFixed(m_world, m_body1,
117 frameInBloc, frameInBrot,
118 useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies);
119 m_enabled = true;
120 PhysicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}",
121 m_body1.ID, world.worldID, obj1.ID, obj1.AddrString);
122 PhysicsScene.DetailLog("{0},BS6DofConstraint,createFixed, fBLoc={1},fBRot={2},usefA={3},disCol={4}",
123 m_body1.ID, frameInBloc, frameInBrot, useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies);
124 }
125
126 public bool SetFrames(Vector3 frameA, Quaternion frameArot, Vector3 frameB, Quaternion frameBrot)
127 {
128 bool ret = false;
129 if (m_enabled)
130 {
131 PhysicsScene.PE.SetFrames(m_constraint, frameA, frameArot, frameB, frameBrot);
132 ret = true;
133 }
134 return ret;
135 }
136
137 public bool SetCFMAndERP(float cfm, float erp)
138 {
139 bool ret = false;
140 if (m_enabled)
141 {
142 PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
143 PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_STOP_ERP, erp, ConstraintParamAxis.AXIS_ALL);
144 PhysicsScene.PE.SetConstraintParam(m_constraint, ConstraintParams.BT_CONSTRAINT_CFM, cfm, ConstraintParamAxis.AXIS_ALL);
145 ret = true;
146 }
147 return ret;
148 }
149
150 public bool UseFrameOffset(bool useOffset)
151 {
152 bool ret = false;
153 float onOff = useOffset ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
154 if (m_enabled)
155 ret = PhysicsScene.PE.UseFrameOffset(m_constraint, onOff);
156 return ret;
157 }
158
159 public bool TranslationalLimitMotor(bool enable, float targetVelocity, float maxMotorForce)
160 {
161 bool ret = false;
162 float onOff = enable ? ConfigurationParameters.numericTrue : ConfigurationParameters.numericFalse;
163 if (m_enabled)
164 {
165 ret = PhysicsScene.PE.TranslationalLimitMotor(m_constraint, onOff, targetVelocity, maxMotorForce);
166 m_world.physicsScene.DetailLog("{0},BS6DOFConstraint,TransLimitMotor,enable={1},vel={2},maxForce={3}",
167 BSScene.DetailLogZero, enable, targetVelocity, maxMotorForce);
168 }
169 return ret;
170 }
171
172 public bool SetBreakingImpulseThreshold(float threshold)
173 {
174 bool ret = false;
175 if (m_enabled)
176 ret = PhysicsScene.PE.SetBreakingImpulseThreshold(m_constraint, threshold);
177 return ret;
178 }
179}
180}