aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs312
1 files changed, 0 insertions, 312 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
deleted file mode 100755
index d0b2a56..0000000
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetConstraints.cs
+++ /dev/null
@@ -1,312 +0,0 @@
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;
30
31using OMV = OpenMetaverse;
32
33namespace OpenSim.Region.Physics.BulletSPlugin
34{
35public sealed class BSLinksetConstraints : BSLinkset
36{
37 // private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
38
39 public BSLinksetConstraints(BSScene scene, BSPhysObject parent) : base(scene, parent)
40 {
41 }
42
43 // When physical properties are changed the linkset needs to recalculate
44 // its internal properties.
45 // This is queued in the 'post taint' queue so the
46 // refresh will happen once after all the other taints are applied.
47 public override void Refresh(BSPhysObject requestor)
48 {
49 base.Refresh(requestor);
50
51 if (HasAnyChildren && IsRoot(requestor))
52 {
53 // Queue to happen after all the other taint processing
54 PhysicsScene.PostTaintObject("BSLinksetContraints.Refresh", requestor.LocalID, delegate()
55 {
56 if (HasAnyChildren && IsRoot(requestor))
57 RecomputeLinksetConstraints();
58 });
59 }
60 }
61
62 // The object is going dynamic (physical). Do any setup necessary
63 // for a dynamic linkset.
64 // Only the state of the passed object can be modified. The rest of the linkset
65 // has not yet been fully constructed.
66 // Return 'true' if any properties updated on the passed object.
67 // Called at taint-time!
68 public override bool MakeDynamic(BSPhysObject child)
69 {
70 // What is done for each object in BSPrim is what we want.
71 return false;
72 }
73
74 // The object is going static (non-physical). Do any setup necessary for a static linkset.
75 // Return 'true' if any properties updated on the passed object.
76 // This doesn't normally happen -- OpenSim removes the objects from the physical
77 // world if it is a static linkset.
78 // Called at taint-time!
79 public override bool MakeStatic(BSPhysObject child)
80 {
81 // What is done for each object in BSPrim is what we want.
82 return false;
83 }
84
85 // Called at taint-time!!
86 public override void UpdateProperties(BSPhysObject updated, bool inTaintTime)
87 {
88 // Nothing to do for constraints on property updates
89 }
90
91 // Routine called when rebuilding the body of some member of the linkset.
92 // Destroy all the constraints have have been made to root and set
93 // up to rebuild the constraints before the next simulation step.
94 // Returns 'true' of something was actually removed and would need restoring
95 // Called at taint-time!!
96 public override bool RemoveBodyDependencies(BSPrim child)
97 {
98 bool ret = false;
99
100 DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
101 child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString);
102
103 lock (m_linksetActivityLock)
104 {
105 // Just undo all the constraints for this linkset. Rebuild at the end of the step.
106 ret = PhysicallyUnlinkAllChildrenFromRoot(LinksetRoot);
107 // Cause the constraints, et al to be rebuilt before the next simulation step.
108 Refresh(LinksetRoot);
109 }
110 return ret;
111 }
112
113 // Companion to RemoveBodyDependencies(). If RemoveBodyDependencies() returns 'true',
114 // this routine will restore the removed constraints.
115 // Called at taint-time!!
116 public override void RestoreBodyDependencies(BSPrim child)
117 {
118 // The Refresh operation queued by RemoveBodyDependencies() will build any missing constraints.
119 }
120
121 // ================================================================
122
123 // Add a new child to the linkset.
124 // Called while LinkActivity is locked.
125 protected override void AddChildToLinkset(BSPhysObject child)
126 {
127 if (!HasChild(child))
128 {
129 m_children.Add(child);
130
131 DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
132
133 // Cause constraints and assorted properties to be recomputed before the next simulation step.
134 Refresh(LinksetRoot);
135 }
136 return;
137 }
138
139 // Remove the specified child from the linkset.
140 // Safe to call even if the child is not really in my linkset.
141 protected override void RemoveChildFromLinkset(BSPhysObject child)
142 {
143 if (m_children.Remove(child))
144 {
145 BSPhysObject rootx = LinksetRoot; // capture the root and body as of now
146 BSPhysObject childx = child;
147
148 DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
149 childx.LocalID,
150 rootx.LocalID, rootx.PhysBody.AddrString,
151 childx.LocalID, childx.PhysBody.AddrString);
152
153 PhysicsScene.TaintedObject("BSLinksetConstraints.RemoveChildFromLinkset", delegate()
154 {
155 PhysicallyUnlinkAChildFromRoot(rootx, childx);
156 });
157 // See that the linkset parameters are recomputed at the end of the taint time.
158 Refresh(LinksetRoot);
159 }
160 else
161 {
162 // Non-fatal occurance.
163 // PhysicsScene.Logger.ErrorFormat("{0}: Asked to remove child from linkset that was not in linkset", LogHeader);
164 }
165 return;
166 }
167
168 // Create a constraint between me (root of linkset) and the passed prim (the child).
169 // Called at taint time!
170 private void PhysicallyLinkAChildToRoot(BSPhysObject rootPrim, BSPhysObject childPrim)
171 {
172 // Don't build the constraint when asked. Put it off until just before the simulation step.
173 Refresh(rootPrim);
174 }
175
176 private BSConstraint BuildConstraint(BSPhysObject rootPrim, BSPhysObject childPrim)
177 {
178 // Zero motion for children so they don't interpolate
179 childPrim.ZeroMotion(true);
180
181 // Relative position normalized to the root prim
182 // Essentually a vector pointing from center of rootPrim to center of childPrim
183 OMV.Vector3 childRelativePosition = childPrim.Position - rootPrim.Position;
184
185 // real world coordinate of midpoint between the two objects
186 OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);
187
188 DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
189 rootPrim.LocalID,
190 rootPrim.LocalID, rootPrim.PhysBody.AddrString,
191 childPrim.LocalID, childPrim.PhysBody.AddrString,
192 rootPrim.Position, childPrim.Position, midPoint);
193
194 // create a constraint that allows no freedom of movement between the two objects
195 // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
196
197 BSConstraint6Dof constrain = new BSConstraint6Dof(
198 PhysicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true );
199 // PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true );
200
201 /* NOTE: below is an attempt to build constraint with full frame computation, etc.
202 * Using the midpoint is easier since it lets the Bullet code manipulate the transforms
203 * of the objects.
204 * Code left for future programmers.
205 // ==================================================================================
206 // relative position normalized to the root prim
207 OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
208 OMV.Vector3 childRelativePosition = (childPrim.Position - rootPrim.Position) * invThisOrientation;
209
210 // relative rotation of the child to the parent
211 OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation;
212 OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation);
213
214 DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID);
215 BS6DofConstraint constrain = new BS6DofConstraint(
216 PhysicsScene.World, rootPrim.Body, childPrim.Body,
217 OMV.Vector3.Zero,
218 OMV.Quaternion.Inverse(rootPrim.Orientation),
219 OMV.Vector3.Zero,
220 OMV.Quaternion.Inverse(childPrim.Orientation),
221 true,
222 true
223 );
224 // ==================================================================================
225 */
226
227 PhysicsScene.Constraints.AddConstraint(constrain);
228
229 // zero linear and angular limits makes the objects unable to move in relation to each other
230 constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
231 constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
232
233 // tweek the constraint to increase stability
234 constrain.UseFrameOffset(BSParam.BoolNumeric(BSParam.LinkConstraintUseFrameOffset));
235 constrain.TranslationalLimitMotor(BSParam.BoolNumeric(BSParam.LinkConstraintEnableTransMotor),
236 BSParam.LinkConstraintTransMotorMaxVel,
237 BSParam.LinkConstraintTransMotorMaxForce);
238 constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP);
239 if (BSParam.LinkConstraintSolverIterations != 0f)
240 {
241 constrain.SetSolverIterations(BSParam.LinkConstraintSolverIterations);
242 }
243 return constrain;
244 }
245
246 // Remove linkage between the linkset root and a particular child
247 // The root and child bodies are passed in because we need to remove the constraint between
248 // the bodies that were present at unlink time.
249 // Called at taint time!
250 private bool PhysicallyUnlinkAChildFromRoot(BSPhysObject rootPrim, BSPhysObject childPrim)
251 {
252 bool ret = false;
253 DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
254 rootPrim.LocalID,
255 rootPrim.LocalID, rootPrim.PhysBody.AddrString,
256 childPrim.LocalID, childPrim.PhysBody.AddrString);
257
258 // Find the constraint for this link and get rid of it from the overall collection and from my list
259 if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
260 {
261 // Make the child refresh its location
262 PhysicsScene.PE.PushUpdate(childPrim.PhysBody);
263 ret = true;
264 }
265
266 return ret;
267 }
268
269 // Remove linkage between myself and any possible children I might have.
270 // Returns 'true' of any constraints were destroyed.
271 // Called at taint time!
272 private bool PhysicallyUnlinkAllChildrenFromRoot(BSPhysObject rootPrim)
273 {
274 DetailLog("{0},BSLinksetConstraint.PhysicallyUnlinkAllChildren,taint", rootPrim.LocalID);
275
276 return PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody);
277 }
278
279 // Call each of the constraints that make up this linkset and recompute the
280 // various transforms and variables. Create constraints of not created yet.
281 // Called before the simulation step to make sure the constraint based linkset
282 // is all initialized.
283 // Called at taint time!!
284 private void RecomputeLinksetConstraints()
285 {
286 float linksetMass = LinksetMass;
287 LinksetRoot.UpdatePhysicalMassProperties(linksetMass, true);
288
289 DetailLog("{0},BSLinksetConstraint.RecomputeLinksetConstraints,set,rBody={1},linksetMass={2}",
290 LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString, linksetMass);
291
292 foreach (BSPhysObject child in m_children)
293 {
294 // A child in the linkset physically shows the mass of the whole linkset.
295 // This allows Bullet to apply enough force on the child to move the whole linkset.
296 // (Also do the mass stuff before recomputing the constraint so mass is not zero.)
297 child.UpdatePhysicalMassProperties(linksetMass, true);
298
299 BSConstraint constrain;
300 if (!PhysicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain))
301 {
302 // If constraint doesn't exist yet, create it.
303 constrain = BuildConstraint(LinksetRoot, child);
304 }
305 constrain.RecomputeConstraintVariables(linksetMass);
306
307 // PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG
308 }
309
310 }
311}
312}