diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 83 |
1 files changed, 9 insertions, 74 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 6a5461a..68a6c41 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -126,7 +126,7 @@ public class BSPrim : BSPhysObject | |||
126 | // Undo any vehicle properties | 126 | // Undo any vehicle properties |
127 | this.VehicleType = (int)Vehicle.TYPE_NONE; | 127 | this.VehicleType = (int)Vehicle.TYPE_NONE; |
128 | 128 | ||
129 | PhysicsScene.TaintedObject("BSPrim.destroy", delegate() | 129 | PhysicsScene.TaintedObject("BSPrim.Destroy", delegate() |
130 | { | 130 | { |
131 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); | 131 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); |
132 | // If there are physical body and shape, release my use of same. | 132 | // If there are physical body and shape, release my use of same. |
@@ -257,98 +257,31 @@ public class BSPrim : BSPhysObject | |||
257 | }); | 257 | }); |
258 | } | 258 | } |
259 | 259 | ||
260 | bool TryExperimentalLockAxisCode = false; | ||
261 | BSConstraint LockAxisConstraint = null; | ||
262 | public override void LockAngularMotion(OMV.Vector3 axis) | 260 | public override void LockAngularMotion(OMV.Vector3 axis) |
263 | { | 261 | { |
264 | DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); | 262 | DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); |
265 | 263 | ||
266 | // "1" means free, "0" means locked | 264 | // "1" means free, "0" means locked |
267 | OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f); | 265 | OMV.Vector3 locking = LockedAxisFree; |
268 | if (axis.X != 1) locking.X = 0f; | 266 | if (axis.X != 1) locking.X = 0f; |
269 | if (axis.Y != 1) locking.Y = 0f; | 267 | if (axis.Y != 1) locking.Y = 0f; |
270 | if (axis.Z != 1) locking.Z = 0f; | 268 | if (axis.Z != 1) locking.Z = 0f; |
271 | LockedAxis = locking; | 269 | LockedAxis = locking; |
272 | 270 | ||
273 | if (TryExperimentalLockAxisCode && LockedAxis != LockedAxisFree) | 271 | if (LockedAxis != LockedAxisFree) |
274 | { | 272 | { |
275 | // Lock that axis by creating a 6DOF constraint that has one end in the world and | ||
276 | // the other in the object. | ||
277 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817 | ||
278 | // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380 | ||
279 | |||
280 | PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() | 273 | PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() |
281 | { | 274 | { |
282 | CleanUpLockAxisPhysicals(true /* inTaintTime */); | 275 | // If there is not already an axis locker, make one |
283 | 276 | if (!PhysicalActors.HasActor(LockedAxisActorName)) | |
284 | BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, PhysBody, | ||
285 | OMV.Vector3.Zero, OMV.Quaternion.Inverse(RawOrientation), | ||
286 | true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); | ||
287 | LockAxisConstraint = axisConstrainer; | ||
288 | PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); | ||
289 | |||
290 | // The constraint is tied to the world and oriented to the prim. | ||
291 | |||
292 | // Free to move linearly | ||
293 | OMV.Vector3 linearLow = OMV.Vector3.Zero; | ||
294 | OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; | ||
295 | axisConstrainer.SetLinearLimits(linearLow, linearHigh); | ||
296 | |||
297 | // Angular with some axis locked | ||
298 | float f2PI = (float)Math.PI * 2f; | ||
299 | OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); | ||
300 | OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); | ||
301 | if (LockedAxis.X != 1f) | ||
302 | { | ||
303 | angularLow.X = 0f; | ||
304 | angularHigh.X = 0f; | ||
305 | } | ||
306 | if (LockedAxis.Y != 1f) | ||
307 | { | ||
308 | angularLow.Y = 0f; | ||
309 | angularHigh.Y = 0f; | ||
310 | } | ||
311 | if (LockedAxis.Z != 1f) | ||
312 | { | 277 | { |
313 | angularLow.Z = 0f; | 278 | PhysicalActors.Add(LockedAxisActorName, new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName)); |
314 | angularHigh.Z = 0f; | ||
315 | } | 279 | } |
316 | axisConstrainer.SetAngularLimits(angularLow, angularHigh); | 280 | UpdatePhysicalParameters(); |
317 | |||
318 | DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", | ||
319 | LocalID, linearLow, linearHigh, angularLow, angularHigh); | ||
320 | |||
321 | // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. | ||
322 | axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); | ||
323 | |||
324 | axisConstrainer.RecomputeConstraintVariables(RawMass); | ||
325 | }); | 281 | }); |
326 | } | 282 | } |
327 | else | ||
328 | { | ||
329 | // Everything seems unlocked | ||
330 | CleanUpLockAxisPhysicals(false /* inTaintTime */); | ||
331 | } | ||
332 | |||
333 | return; | 283 | return; |
334 | } | 284 | } |
335 | // Get rid of any constraint built for LockAxis | ||
336 | // Most often the constraint is removed when the constraint collection is cleaned for this prim. | ||
337 | private void CleanUpLockAxisPhysicals(bool inTaintTime) | ||
338 | { | ||
339 | if (LockAxisConstraint != null) | ||
340 | { | ||
341 | PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CleanUpLockAxisPhysicals", delegate() | ||
342 | { | ||
343 | if (LockAxisConstraint != null) | ||
344 | { | ||
345 | PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); | ||
346 | LockAxisConstraint = null; | ||
347 | DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", LocalID); | ||
348 | } | ||
349 | }); | ||
350 | } | ||
351 | } | ||
352 | 285 | ||
353 | public override OMV.Vector3 RawPosition | 286 | public override OMV.Vector3 RawPosition |
354 | { | 287 | { |
@@ -916,6 +849,7 @@ public class BSPrim : BSPhysObject | |||
916 | 849 | ||
917 | // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) | 850 | // Update vehicle specific parameters (after MakeDynamic() so can change physical parameters) |
918 | VehicleController.Refresh(); | 851 | VehicleController.Refresh(); |
852 | PhysicalActors.Refresh(); | ||
919 | 853 | ||
920 | // Arrange for collision events if the simulator wants them | 854 | // Arrange for collision events if the simulator wants them |
921 | EnableCollisions(SubscribedEvents()); | 855 | EnableCollisions(SubscribedEvents()); |
@@ -1753,6 +1687,7 @@ public class BSPrim : BSPhysObject | |||
1753 | protected virtual void RemoveBodyDependencies() | 1687 | protected virtual void RemoveBodyDependencies() |
1754 | { | 1688 | { |
1755 | VehicleController.RemoveBodyDependencies(this); | 1689 | VehicleController.RemoveBodyDependencies(this); |
1690 | PhysicalActors.RemoveBodyDependencies(); | ||
1756 | } | 1691 | } |
1757 | 1692 | ||
1758 | // The physics engine says that properties have updated. Update same and inform | 1693 | // The physics engine says that properties have updated. Update same and inform |