From 933ac607468fb160636af601ce83ee1011794ec3 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Sun, 31 Mar 2013 22:06:02 -0700 Subject: BulletSim: not quite functional axis lock code. --- .../Physics/BulletSPlugin/BSActorLockAxis.cs | 62 ++++++++++++---------- OpenSim/Region/Physics/BulletSPlugin/BSActors.cs | 8 +-- .../Region/Physics/BulletSPlugin/BSConstraint.cs | 2 + .../Physics/BulletSPlugin/BSConstraint6Dof.cs | 4 +- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs index 5f74a14..aa75663 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActorLockAxis.cs @@ -42,14 +42,14 @@ public class BSActorLockAxis : BSActor public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName) : base(physicsScene, pObj,actorName) { - PhysicsScene.DetailLog("{0},BSActorLockAxis,constructor", Prim.LocalID); + m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID); LockAxisConstraint = null; } // BSActor.isActive public override bool isActive { - get { return Enabled && Prim.IsPhysicallyActive; } + get { return Enabled && m_controllingPrim.IsPhysicallyActive; } } // Release any connections and resources used by the actor. @@ -64,21 +64,22 @@ public class BSActorLockAxis : BSActor // BSActor.Refresh() public override void Refresh() { - PhysicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", - Prim.LocalID, Prim.LockedAxis, Enabled, Prim.IsPhysicallyActive); + m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,lockedAxis={1},enabled={2},pActive={3}", + m_controllingPrim.LocalID, m_controllingPrim.LockedAxis, Enabled, m_controllingPrim.IsPhysicallyActive); // If all the axis are free, we don't need to exist - if (Prim.LockedAxis == Prim.LockedAxisFree) + if (m_controllingPrim.LockedAxis == m_controllingPrim.LockedAxisFree) { - Prim.PhysicalActors.RemoveAndRelease(ActorName); + m_physicsScene.DetailLog("{0},BSActorLockAxis,refresh,allAxisFree,removing={1}", m_controllingPrim.LocalID, ActorName); + m_controllingPrim.PhysicalActors.RemoveAndRelease(ActorName); return; } // If the object is physically active, add the axis locking constraint if (Enabled - && Prim.IsPhysicallyActive + && m_controllingPrim.IsPhysicallyActive && TryExperimentalLockAxisCode - && Prim.LockedAxis != Prim.LockedAxisFree) + && m_controllingPrim.LockedAxis != m_controllingPrim.LockedAxisFree) { - if (LockAxisConstraint != null) + if (LockAxisConstraint == null) AddAxisLockConstraint(); } else @@ -98,7 +99,7 @@ public class BSActorLockAxis : BSActor // If a constraint is set up, remove it from the physical scene RemoveAxisLockConstraint(); // Schedule a call before the next simulation step to restore the constraint. - PhysicsScene.PostTaintObject(Prim.LockedAxisActorName, Prim.LocalID, delegate() + m_physicsScene.PostTaintObject(m_controllingPrim.LockedAxisActorName, m_controllingPrim.LocalID, delegate() { Refresh(); }); @@ -115,56 +116,61 @@ public class BSActorLockAxis : BSActor // Remove any existing axis constraint (just to be sure) RemoveAxisLockConstraint(); - BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, Prim.PhysBody, - OMV.Vector3.Zero, OMV.Quaternion.Inverse(Prim.RawOrientation), - true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); + BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody, + // OMV.Vector3.Zero, OMV.Quaternion.Identity, + OMV.Vector3.Zero, OMV.Quaternion.Inverse(m_controllingPrim.RawOrientation), + // OMV.Vector3.Zero, m_controllingPrim.RawOrientation, + false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */); LockAxisConstraint = axisConstrainer; - PhysicsScene.Constraints.AddConstraint(LockAxisConstraint); + m_physicsScene.Constraints.AddConstraint(LockAxisConstraint); // The constraint is tied to the world and oriented to the prim. - // Free to move linearly + // Free to move linearly in the region OMV.Vector3 linearLow = OMV.Vector3.Zero; - OMV.Vector3 linearHigh = PhysicsScene.TerrainManager.DefaultRegionSize; + OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.DefaultRegionSize; axisConstrainer.SetLinearLimits(linearLow, linearHigh); // Angular with some axis locked - float f2PI = (float)Math.PI * 2f; - OMV.Vector3 angularLow = new OMV.Vector3(-f2PI, -f2PI, -f2PI); - OMV.Vector3 angularHigh = new OMV.Vector3(f2PI, f2PI, f2PI); - if (Prim.LockedAxis.X != 1f) + float fPI = (float)Math.PI; + OMV.Vector3 angularLow = new OMV.Vector3(-fPI, -fPI, -fPI); + OMV.Vector3 angularHigh = new OMV.Vector3(fPI, fPI, fPI); + if (m_controllingPrim.LockedAxis.X != 1f) { angularLow.X = 0f; angularHigh.X = 0f; } - if (Prim.LockedAxis.Y != 1f) + if (m_controllingPrim.LockedAxis.Y != 1f) { angularLow.Y = 0f; angularHigh.Y = 0f; } - if (Prim.LockedAxis.Z != 1f) + if (m_controllingPrim.LockedAxis.Z != 1f) { angularLow.Z = 0f; angularHigh.Z = 0f; } - axisConstrainer.SetAngularLimits(angularLow, angularHigh); + if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh)) + { + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits", m_controllingPrim.LocalID); + } - PhysicsScene.DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}", - Prim.LocalID, linearLow, linearHigh, angularLow, angularHigh); + m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,create,linLow={1},linHi={2},angLow={3},angHi={4}", + m_controllingPrim.LocalID, linearLow, linearHigh, angularLow, angularHigh); // Constants from one of the posts mentioned above and used in Bullet's ConstraintDemo. axisConstrainer.TranslationalLimitMotor(true /* enable */, 5.0f, 0.1f); - axisConstrainer.RecomputeConstraintVariables(Prim.RawMass); + axisConstrainer.RecomputeConstraintVariables(m_controllingPrim.RawMass); } private void RemoveAxisLockConstraint() { if (LockAxisConstraint != null) { - PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); + m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint); LockAxisConstraint = null; - PhysicsScene.DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", Prim.LocalID); + m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID); } } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs index 3163440..5a19ba4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSActors.cs @@ -96,15 +96,15 @@ public class BSActorCollection /// public abstract class BSActor { - protected BSScene PhysicsScene { get; private set; } - protected BSPhysObject Prim { get; private set; } + protected BSScene m_physicsScene { get; private set; } + protected BSPhysObject m_controllingPrim { get; private set; } protected bool Enabled { get; set; } public string ActorName { get; private set; } public BSActor(BSScene physicsScene, BSPhysObject pObj, string actorName) { - PhysicsScene = physicsScene; - Prim = pObj; + m_physicsScene = physicsScene; + m_controllingPrim = pObj; ActorName = actorName; Enabled = true; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs index b813974..42b5c49 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint.cs @@ -85,7 +85,9 @@ public abstract class BSConstraint : IDisposable { bool ret = false; if (m_enabled) + { ret = PhysicsScene.PE.SetAngularLimits(m_constraint, low, high); + } return ret; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs index 476a0e5..d0949f5 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSConstraint6Dof.cs @@ -97,14 +97,14 @@ public sealed class BSConstraint6Dof : BSConstraint // A 6 Dof constraint that is fixed in the world and constrained to a on-the-fly created static object public BSConstraint6Dof(BulletWorld world, BulletBody obj1, Vector3 frameInBloc, Quaternion frameInBrot, - bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies) + bool useLinearReferenceFrameB, bool disableCollisionsBetweenLinkedBodies) : base(world) { m_body1 = obj1; m_body2 = obj1; // Look out for confusion down the road m_constraint = PhysicsScene.PE.Create6DofConstraintFixed(m_world, m_body1, frameInBloc, frameInBrot, - useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies); + useLinearReferenceFrameB, disableCollisionsBetweenLinkedBodies); m_enabled = true; world.physicsScene.DetailLog("{0},BS6DofConstraint,createFixed,wID={1},rID={2},rBody={3}", BSScene.DetailLogZero, world.worldID, obj1.ID, obj1.AddrString); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index ec78fdc..e56276a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -274,10 +274,10 @@ public class BSPrim : BSPhysObject { PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate() { - DetailLog("{0},BSPrim.LockAngularMotion,taint,registeringLockAxisActor", LocalID); // If there is not already an axis locker, make one if (!PhysicalActors.HasActor(LockedAxisActorName)) { + DetailLog("{0},BSPrim.LockAngularMotion,taint,registeringLockAxisActor", LocalID); PhysicalActors.Add(LockedAxisActorName, new BSActorLockAxis(PhysicsScene, this, LockedAxisActorName)); } UpdatePhysicalParameters(); -- cgit v1.1