aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorRobert Adams2013-02-17 20:11:40 -0800
committerRobert Adams2013-02-17 20:13:50 -0800
commit26421294f644b224234e874210bbfd2a1aabf451 (patch)
tree89cc2dfc4397de233f8e62e1b094e5fe44ce8769 /OpenSim
parentBulletSim: add calls for creating all the different Bullet constraint types. (diff)
downloadopensim-SC_OLD-26421294f644b224234e874210bbfd2a1aabf451.zip
opensim-SC_OLD-26421294f644b224234e874210bbfd2a1aabf451.tar.gz
opensim-SC_OLD-26421294f644b224234e874210bbfd2a1aabf451.tar.bz2
opensim-SC_OLD-26421294f644b224234e874210bbfd2a1aabf451.tar.xz
BulletSim: experimental lock axis code using constraints. Not enabled
by default. Like more debugging is needed.
Diffstat (limited to 'OpenSim')
-rwxr-xr-xOpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs4
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs92
2 files changed, 74 insertions, 22 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
index 4ce58c7..e05562a 100755
--- a/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSLinksetCompound.cs
@@ -485,8 +485,8 @@ public sealed class BSLinksetCompound : BSLinkset
485 } 485 }
486 OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement; 486 OMV.Vector3 offsetPos = (cPrim.RawPosition - LinksetRoot.RawPosition) * invRootOrientation - centerDisplacement;
487 OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation; 487 OMV.Quaternion offsetRot = cPrim.RawOrientation * invRootOrientation;
488 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); 488 PhysicsScene.PE.AddChildShapeToCompoundShape(LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot);
489 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addNonNative,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}", 489 DetailLog("{0},BSLinksetCompound.RecomputeLinksetCompound,addNonNative,indx={1},rShape={2},cShape={3},offPos={4},offRot={5}",
490 LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot); 490 LinksetRoot.LocalID, memberIndex, LinksetRoot.PhysShape, cPrim.PhysShape, offsetPos, offsetRot);
491 491
492 } 492 }
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index 4bb2a9e..4d61ad2 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -239,50 +239,98 @@ public class BSPrim : BSPhysObject
239 }); 239 });
240 } 240 }
241 241
242 bool TryExperimentalLockAxisCode = false;
243 BSConstraint LockAxisConstraint = null;
242 public override void LockAngularMotion(OMV.Vector3 axis) 244 public override void LockAngularMotion(OMV.Vector3 axis)
243 { 245 {
244 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); 246 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);
245 247
248 // "1" means free, "0" means locked
246 OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f); 249 OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f);
247 if (axis.X != 1) locking.X = 0f; 250 if (axis.X != 1) locking.X = 0f;
248 if (axis.Y != 1) locking.Y = 0f; 251 if (axis.Y != 1) locking.Y = 0f;
249 if (axis.Z != 1) locking.Z = 0f; 252 if (axis.Z != 1) locking.Z = 0f;
250 LockedAxis = locking; 253 LockedAxis = locking;
251 254
252 /* Not implemented yet 255 if (TryExperimentalLockAxisCode && LockedAxis != LockedAxisFree)
253 if (LockedAxis != LockedAxisFree)
254 { 256 {
255 // Something is locked so start the thingy that keeps that axis from changing 257 // Lock that axis by creating a 6DOF constraint that has one end in the world and
256 RegisterPreUpdatePropertyAction("BSPrim.LockAngularMotion", delegate(ref EntityProperties entprop) 258 // the other in the object.
259 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817
260 // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380
261
262 PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate()
257 { 263 {
258 if (LockedAxis != LockedAxisFree) 264 CleanUpLockAxisPhysicals(true /* inTaintTime */);
265
266 BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, PhysBody,
267 OMV.Vector3.Zero, OMV.Quaternion.Inverse(RawOrientation),
268 true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
269 LockAxisConstraint = axisConstrainer;
270 PhysicsScene.Constraints.AddConstraint(LockAxisConstraint);
271
272 // The constraint is tied to the world and oriented to the prim.
273
274 // Free to move linearly
275 OMV.Vector3 linearLow = OMV.Vector3.Zero;
276 OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize;
277 axisConstrainer.SetLinearLimits(linearLow, linearHigh);
278
279 // Angular with some axis locked
280 float f2PI = (float)Math.PI * 2f;
281 OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI);
282 OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI);
283 if (LockedAxis.X != 1f)
259 { 284 {
260 if (IsPhysicallyActive) 285 angularLow.X = 0f;
261 { 286 angularHigh.X = 0f;
262 // Bullet can lock axis but it only works for global axis.
263 // Check if this prim is aligned on global axis and use Bullet's
264 // system if so.
265
266 ForceOrientation = entprop.Rotation;
267 ForceRotationalVelocity = entprop.RotationalVelocity;
268 }
269 } 287 }
270 else 288 if (LockedAxis.Y != 1f)
271 { 289 {
272 UnRegisterPreUpdatePropertyAction("BSPrim.LockAngularMotion"); 290 angularLow.Y = 0f;
291 angularHigh.Y = 0f;
273 } 292 }
293 if (LockedAxis.Z != 1f)
294 {
295 angularLow.Z = 0f;
296 angularHigh.Z = 0f;
297 }
298 axisConstrainer.SetAngularLimits(angularLow, angularHigh);
299
300 DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}",
301 LocalID, linearLow, linearHigh, angularLow, angularHigh);
302
303 // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo.
304 axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f);
274 305
306 axisConstrainer.RecomputeConstraintVariables(RawMass);
275 }); 307 });
276 } 308 }
277 else 309 else
278 { 310 {
279 // Everything seems unlocked 311 // Everything seems unlocked
280 UnRegisterPreUpdatePropertyAction("BSPrim.LockAngularMotion"); 312 CleanUpLockAxisPhysicals(false /* inTaintTime */);
281 } 313 }
282 */
283 314
284 return; 315 return;
285 } 316 }
317 // Get rid of any constraint built for LockAxis
318 // Most often the constraint is removed when the constraint collection is cleaned for this prim.
319 private void CleanUpLockAxisPhysicals(bool inTaintTime)
320 {
321 if (LockAxisConstraint != null)
322 {
323 PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CleanUpLockAxisPhysicals", delegate()
324 {
325 if (LockAxisConstraint != null)
326 {
327 PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
328 LockAxisConstraint = null;
329 DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", LocalID);
330 }
331 });
332 }
333 }
286 334
287 public override OMV.Vector3 RawPosition 335 public override OMV.Vector3 RawPosition
288 { 336 {
@@ -762,6 +810,7 @@ public class BSPrim : BSPhysObject
762 SetObjectDynamic(true); 810 SetObjectDynamic(true);
763 // whether phys-to-static or static-to-phys, the object is not moving. 811 // whether phys-to-static or static-to-phys, the object is not moving.
764 ZeroMotion(true); 812 ZeroMotion(true);
813
765 }); 814 });
766 } 815 }
767 } 816 }
@@ -885,6 +934,8 @@ public class BSPrim : BSPhysObject
885 934
886 // For good measure, make sure the transform is set through to the motion state 935 // For good measure, make sure the transform is set through to the motion state
887 ForcePosition = _position; 936 ForcePosition = _position;
937 ForceVelocity = _velocity;
938 ForceRotationalVelocity = _rotationalVelocity;
888 939
889 // A dynamic object has mass 940 // A dynamic object has mass
890 UpdatePhysicalMassProperties(RawMass, false); 941 UpdatePhysicalMassProperties(RawMass, false);
@@ -1064,8 +1115,8 @@ public class BSPrim : BSPhysObject
1064 _buoyancy = value; 1115 _buoyancy = value;
1065 // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 1116 // DetailLog("{0},BSPrim.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
1066 // Force the recalculation of the various inertia,etc variables in the object 1117 // Force the recalculation of the various inertia,etc variables in the object
1067 DetailLog("{0},BSPrim.ForceBuoyancy,buoy={1},mass={2}", LocalID, _buoyancy, _mass); 1118 UpdatePhysicalMassProperties(RawMass, true);
1068 UpdatePhysicalMassProperties(_mass, true); 1119 DetailLog("{0},BSPrim.ForceBuoyancy,buoy={1},mass={2},grav={3}", LocalID, _buoyancy, RawMass, Gravity);
1069 ActivateIfPhysical(false); 1120 ActivateIfPhysical(false);
1070 } 1121 }
1071 } 1122 }
@@ -1303,6 +1354,7 @@ public class BSPrim : BSPhysObject
1303 { 1354 {
1304 if (PhysBody.HasPhysicalBody) 1355 if (PhysBody.HasPhysicalBody)
1305 { 1356 {
1357 DetailLog("{0},BSPrim.AddAngularForce,taint,angForce={1}", LocalID, angForce);
1306 PhysicsScene.PE.ApplyTorque(PhysBody, angForce); 1358 PhysicsScene.PE.ApplyTorque(PhysBody, angForce);
1307 ActivateIfPhysical(false); 1359 ActivateIfPhysical(false);
1308 } 1360 }