private void RemoveAxisLockConstraint()
 {
     if (LockAxisConstraint != null)
     {
         m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
         LockAxisConstraint = null;
         m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint",
                                  m_controllingPrim.LocalID);
     }
 }
        public bool AddConstraint(BSConstraint cons)
        {
            lock (m_constraints)
            {
                // There is only one constraint between any bodies. Remove any old just to make sure.
                RemoveAndDestroyConstraint(cons.Body1, cons.Body2);

                m_constraints.Add(cons);
            }

            return true;
        }
Esempio n. 3
0
        public bool AddConstraint(BSConstraint cons)
        {
            lock (m_constraints)
            {
                // There is only one constraint between any bodies. Remove any old just to make sure.
                RemoveAndDestroyConstraint(cons.Body1, cons.Body2);

                m_constraints.Add(cons);
            }

            return(true);
        }
Esempio n. 4
0
        // The constraint MUST exist in the collection
        // Could be called if the constraint was previously removed.
        // Return 'true' if the constraint was actually removed and disposed.
        public bool RemoveAndDestroyConstraint(BSConstraint constrain)
        {
            bool removed = false;

            lock (m_constraints)
            {
                // remove the constraint from our collection
                removed = m_constraints.Remove(constrain);
            }
            // Dispose() is safe to call multiple times
            constrain.Dispose();
            return(removed);
        }
Esempio n. 5
0
        // Get the constraint between two bodies. There can be only one.
        // Return 'true' if a constraint was found.
        public bool TryGetConstraint(BulletBody body1, BulletBody body2, out BSConstraint returnConstraint)
        {
            bool         found           = false;
            BSConstraint foundConstraint = null;

            uint lookingID1 = body1.ID;
            uint lookingID2 = body2.ID;

            lock (m_constraints)
            {
                foreach (BSConstraint constrain in m_constraints)
                {
                    if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) ||
                        (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1))
                    {
                        foundConstraint = constrain;
                        found           = true;
                        break;
                    }
                }
            }
            returnConstraint = foundConstraint;
            return(found);
        }
        // Get the constraint between two bodies. There can be only one.
        // Return 'true' if a constraint was found.
        public bool TryGetConstraint(BulletBody body1, BulletBody body2, out BSConstraint returnConstraint)
        {
            bool found = false;
            BSConstraint foundConstraint = null;

            uint lookingID1 = body1.ID;
            uint lookingID2 = body2.ID;
            lock (m_constraints)
            {
                foreach (BSConstraint constrain in m_constraints)
                {
                    if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2)
                        || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1))
                    {
                        foundConstraint = constrain;
                        found = true;
                        break;
                    }
                }
            }
            returnConstraint = foundConstraint;
            return found;
        }
 // The constraint MUST exist in the collection
 // Could be called if the constraint was previously removed.
 // Return 'true' if the constraint was actually removed and disposed.
 public bool RemoveAndDestroyConstraint(BSConstraint constrain)
 {
     bool removed = false;
     lock (m_constraints)
     {
         // remove the constraint from our collection
         removed = m_constraints.Remove(constrain);
     }
     // Dispose() is safe to call multiple times
     constrain.Dispose();
     return removed;
 }
 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
     : base(physicsScene, pObj, actorName)
 {
     m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
     LockAxisConstraint = null;
 }
 private void RemoveAxisLockConstraint()
 {
     if (LockAxisConstraint != null)
     {
         m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
         LockAxisConstraint = null;
         m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint",
             m_controllingPrim.LocalID);
     }
 }
        private void AddAxisLockConstraint()
        {
            if (LockAxisConstraint == null)
            {
                // Lock that axis by creating a 6DOF constraint that has one end in the world and
                //    the other in the object.
                // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=20817
                // http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=26380

                // Remove any existing axis constraint (just to be sure)
                RemoveAxisLockConstraint();

                BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(m_physicsScene.World, m_controllingPrim.PhysBody,
                    OMV.Vector3.Zero, OMV.Quaternion.Identity,
                    false /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
                LockAxisConstraint = axisConstrainer;
                m_physicsScene.Constraints.AddConstraint(LockAxisConstraint);

                // The constraint is tied to the world and oriented to the prim.

                // Free to move linearly in the region
                OMV.Vector3 linearLow = OMV.Vector3.Zero;
                OMV.Vector3 linearHigh = m_physicsScene.TerrainManager.WorldMax;
                axisConstrainer.SetLinearLimits(linearLow, linearHigh);

                // Angular with some axis locked
                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 (m_controllingPrim.LockedAxis.Y != 1f)
                {
                    angularLow.Y = 0f;
                    angularHigh.Y = 0f;
                }
                if (m_controllingPrim.LockedAxis.Z != 1f)
                {
                    angularLow.Z = 0f;
                    angularHigh.Z = 0f;
                }
                if (!axisConstrainer.SetAngularLimits(angularLow, angularHigh))
                {
                    m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetAngularLimits",
                        m_controllingPrim.LocalID);
                }

                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(m_controllingPrim.RawMass);
            }
        }
 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
     : base(physicsScene, pObj, actorName)
 {
     m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
     LockAxisConstraint = null;
 }