public BSLinkInfoConstraint(BSPrimLinkable pMember)
     : base(pMember)
 {
     constraint = null;
     ResetLink();
     member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.creation", member.LocalID);
 }
Ejemplo n.º 2
0
 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
     : base(physicsScene, pObj, actorName)
 {
     m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
     LockAxisConstraint = null;
     HaveRegisteredForBeforeStepCallback = false;
 }
        // Given a constraint, apply the current constraint parameters to same.
        public void SetConstraintParameters(BSConstraint constrain)
        {
            switch (constraintType)
            {
                case ConstraintType.D6_CONSTRAINT_TYPE:
                    BSConstraint6Dof constrain6dof = constrain as BSConstraint6Dof;
                    if (constrain6dof != null)
                    {
                        // zero linear and angular limits makes the objects unable to move in relation to each other
                        constrain6dof.SetLinearLimits(linearLimitLow, linearLimitHigh);
                        constrain6dof.SetAngularLimits(angularLimitLow, angularLimitHigh);

                        // tweek the constraint to increase stability
                        constrain6dof.UseFrameOffset(useFrameOffset);
                        constrain6dof.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce);
                        constrain6dof.SetCFMAndERP(cfm, erp);
                        if (solverIterations != 0f)
                        {
                            constrain6dof.SetSolverIterations(solverIterations);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        public bool AddConstraint(BSConstraint cons)
        {
            // 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);
        }
        public bool AddConstraint(BSConstraint cons)
        {
            // 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;
        }
Ejemplo n.º 6
0
    public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
        : base(physicsScene, pObj, actorName)
    {
        m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
        LockAxisConstraint = null;

        // we place our constraint just before the simulation step to make sure the linkset is complete
        m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
    }
Ejemplo n.º 7
0
 private void RemoveAxisLockConstraint()
 {
     if (LockAxisConstraint != null)
     {
         m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
         LockAxisConstraint = null;
         m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID);
     }
 }
Ejemplo n.º 8
0
        public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
            : base(physicsScene, pObj, actorName)
        {
            m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
            LockAxisConstraint = null;

            // we place our constraint just before the simulation step to make sure the linkset is complete
            m_physicsScene.BeforeStep += PhysicsScene_BeforeStep;
        }
        // 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;

            // remove the constraint from our collection
            removed = m_constraints.Remove(constrain);
            // Dispose() is safe to call multiple times
            constrain.Dispose();
            return(removed);
        }
Ejemplo n.º 10
0
 // The constraint MUST exist in the collection
 public bool RemoveAndDestroyConstraint(BSConstraint constrain)
 {
     lock (m_constraints)
     {
         // remove the constraint from our collection
         m_constraints.Remove(constrain);
     }
     // tell the engine that all its structures need to be freed
     constrain.Dispose();
     // we destroyed something
     return(true);
 }
Ejemplo n.º 11
0
        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);

                // Remember the clocking being inforced so we can notice if they have changed
                LockAxisLinearFlags  = m_controllingPrim.LockedLinearAxis;
                LockAxisAngularFlags = m_controllingPrim.LockedAngularAxis;

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

                if (!axisConstrainer.SetLinearLimits(m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh))
                {
                    m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetLinearLimits",
                                             m_controllingPrim.LocalID);
                }

                if (!axisConstrainer.SetAngularLimits(m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh))
                {
                    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,
                                         m_controllingPrim.LockedLinearAxisLow,
                                         m_controllingPrim.LockedLinearAxisHigh,
                                         m_controllingPrim.LockedAngularAxisLow,
                                         m_controllingPrim.LockedAngularAxisHigh);

                // 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 bool AddConstraint(BSConstraint cons)
        {
            m_constraintsRwLock.AcquireWriterLock(-1);
            try
            {
                // There is only one constraint between any bodies. Remove any old just to make sure.
                RemoveAndDestroyConstraint(cons.Body1, cons.Body2);

                m_constraints.Add(cons);
            }
            finally
            {
                m_constraintsRwLock.ReleaseWriterLock();
            }

            return(true);
        }
        // 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;

            m_constraintsRwLock.AcquireWriterLock(-1);
            try
            {
                // remove the constraint from our collection
                removed = m_constraints.Remove(constrain);
            }
            finally
            {
                m_constraintsRwLock.ReleaseWriterLock();
            }
            // Dispose() is safe to call multiple times
            constrain.Dispose();
            return(removed);
        }
 // 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)
 {
     uint lookingID1 = body1.ID;
     uint lookingID2 = body2.ID;
     try
     {
         m_constraints.ForEach(delegate(BSConstraint constrain)
         {
             if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2)
                 || (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1))
             {
                 throw new ThreadedClasses.ReturnValueException<BSConstraint>(constrain);
             }
         });
     }
     catch(ThreadedClasses.ReturnValueException<BSConstraint> e)
     {
         returnConstraint = e.Value;
         return true;
     }
     returnConstraint = default(BSConstraint);
     return false;
 }
Ejemplo n.º 15
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;
    }
Ejemplo n.º 16
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)
        {
            uint lookingID1 = body1.ID;
            uint lookingID2 = body2.ID;

            try
            {
                m_constraints.ForEach(delegate(BSConstraint constrain)
                {
                    if ((constrain.Body1.ID == lookingID1 && constrain.Body2.ID == lookingID2) ||
                        (constrain.Body1.ID == lookingID2 && constrain.Body2.ID == lookingID1))
                    {
                        throw new ThreadedClasses.ReturnValueException <BSConstraint>(constrain);
                    }
                });
            }
            catch (ThreadedClasses.ReturnValueException <BSConstraint> e)
            {
                returnConstraint = e.Value;
                return(true);
            }
            returnConstraint = default(BSConstraint);
            return(false);
        }
Ejemplo n.º 18
0
    public override void LockAngularMotion(OMV.Vector3 axis)
    {
        DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);

        // "1" means free, "0" means locked
        OMV.Vector3 locking = new OMV.Vector3(1f, 1f, 1f);
        if (axis.X != 1) locking.X = 0f;
        if (axis.Y != 1) locking.Y = 0f;
        if (axis.Z != 1) locking.Z = 0f;
        LockedAxis = locking;

        if (TryExperimentalLockAxisCode && LockedAxis != LockedAxisFree)
        {
            // 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

            PhysicsScene.TaintedObject("BSPrim.LockAngularMotion", delegate()
            {
                CleanUpLockAxisPhysicals(true /* inTaintTime */);

                BSConstraint6Dof axisConstrainer = new BSConstraint6Dof(PhysicsScene.World, PhysBody, 
                                    OMV.Vector3.Zero, OMV.Quaternion.Inverse(RawOrientation),
                                    true /* useLinearReferenceFrameB */, true /* disableCollisionsBetweenLinkedBodies */);
                LockAxisConstraint = axisConstrainer;
                PhysicsScene.Constraints.AddConstraint(LockAxisConstraint);

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

                // Free to move linearly
                OMV.Vector3 linearLow = OMV.Vector3.Zero;
                OMV.Vector3 linearHigh = 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 (LockedAxis.X != 1f)
                {
                    angularLow.X = 0f;
                    angularHigh.X = 0f;
                }
                if (LockedAxis.Y != 1f)
                {
                    angularLow.Y = 0f;
                    angularHigh.Y = 0f;
                }
                if (LockedAxis.Z != 1f)
                {
                    angularLow.Z = 0f;
                    angularHigh.Z = 0f;
                }
                axisConstrainer.SetAngularLimits(angularLow, angularHigh);

                DetailLog("{0},BSPrim.LockAngularMotion,create,linLow={1},linHi={2},angLow={3},angHi={4}",
                                            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(RawMass);
            });
        }
        else
        {
            // Everything seems unlocked
            CleanUpLockAxisPhysicals(false /* inTaintTime */);
        }

        return;
    }
Ejemplo n.º 19
0
        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.DefaultRegionSize;
                OMV.Vector3 linearLow  = new OMV.Vector3(-10000f, -10000f, -10000f);
                OMV.Vector3 linearHigh = new OMV.Vector3(10000f, 10000f, 10000f);
                if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis)
                {
                    linearLow.X  = m_controllingPrim.RawPosition.X;
                    linearHigh.X = m_controllingPrim.RawPosition.X;
                }
                if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis)
                {
                    linearLow.Y  = m_controllingPrim.RawPosition.Y;
                    linearHigh.Y = m_controllingPrim.RawPosition.Y;
                }
                if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis)
                {
                    linearLow.Z  = m_controllingPrim.RawPosition.Z;
                    linearHigh.Z = m_controllingPrim.RawPosition.Z;
                }
                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.LockedAngularAxis.X != BSPhysObject.FreeAxis)
                {
                    angularLow.X  = 0f;
                    angularHigh.X = 0f;
                }
                if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis)
                {
                    angularLow.Y  = 0f;
                    angularHigh.Y = 0f;
                }
                if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis)
                {
                    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);
            }
        }
Ejemplo n.º 20
0
 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
     : base(physicsScene, pObj, actorName)
 {
     m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
     LockAxisConstraint = null;
 }
Ejemplo n.º 21
0
 // Get rid of any constraint built for LockAxis
 // Most often the constraint is removed when the constraint collection is cleaned for this prim.
 private void CleanUpLockAxisPhysicals(bool inTaintTime)
 {
     if (LockAxisConstraint != null)
     {
         PhysicsScene.TaintedObject(inTaintTime, "BSPrim.CleanUpLockAxisPhysicals", delegate()
         {
             if (LockAxisConstraint != null)
             {
                 PhysicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
                 LockAxisConstraint = null;
                 DetailLog("{0},BSPrim.CleanUpLockAxisPhysicals,destroyingConstraint", LocalID);
             }
         });
     }
 }
Ejemplo n.º 22
0
 public virtual void SetLinkParameters(BSConstraint constrain)
 {
 }
Ejemplo n.º 23
0
 public virtual void SetLinkParameters(BSConstraint constrain) { }
Ejemplo n.º 24
0
    // Note that this relies on being called at TaintTime
    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);

            // Remember the clocking being inforced so we can notice if they have changed
            LockAxisLinearFlags = m_controllingPrim.LockedLinearAxis;
            LockAxisAngularFlags = m_controllingPrim.LockedAngularAxis;

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

            if (!axisConstrainer.SetLinearLimits(m_controllingPrim.LockedLinearAxisLow, m_controllingPrim.LockedLinearAxisHigh))
            {
                m_physicsScene.DetailLog("{0},BSActorLockAxis.AddAxisLockConstraint,failedSetLinearLimits",
                        m_controllingPrim.LocalID);
            }

            if (!axisConstrainer.SetAngularLimits(m_controllingPrim.LockedAngularAxisLow, m_controllingPrim.LockedAngularAxisHigh))
            {
                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,
                                        m_controllingPrim.LockedLinearAxisLow,
                                        m_controllingPrim.LockedLinearAxisHigh,
                                        m_controllingPrim.LockedAngularAxisLow,
                                        m_controllingPrim.LockedAngularAxisHigh);

            // 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);

            RegisterForBeforeStepCallback();
        }
    }
 // 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;
     // remove the constraint from our collection
     removed = m_constraints.Remove(constrain);
     // Dispose() is safe to call multiple times
     constrain.Dispose();
     return removed;
 }
Ejemplo n.º 26
0
 public BSActorLockAxis(BSScene physicsScene, BSPhysObject pObj, string actorName)
     : base(physicsScene, pObj, actorName)
 {
     m_physicsScene.DetailLog("{0},BSActorLockAxis,constructor", m_controllingPrim.LocalID);
     LockAxisConstraint = null;
 }
 public BSLinkInfoConstraint(BSPrimLinkable pMember)
     : base(pMember)
 {
     constraint = null;
     ResetToFixedConstraint();
 }
Ejemplo n.º 28
0
 // The constraint MUST exist in the collection
 public bool RemoveAndDestroyConstraint(BSConstraint constrain)
 {
     lock (m_constraints)
     {
         // remove the constraint from our collection
         m_constraints.Remove(constrain);
     }
     // tell the engine that all its structures need to be freed
     constrain.Dispose();
     // we destroyed something
     return true;
 }
        // Create a static constraint between the two passed objects
        private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSLinkInfo li)
        {
            BSLinkInfoConstraint liConstraint = li as BSLinkInfoConstraint;

            if (liConstraint == null)
            {
                return(null);
            }

            // Zero motion for children so they don't interpolate
            li.member.ZeroMotion(true);

            BSConstraint constrain = null;

            switch (liConstraint.constraintType)
            {
            case ConstraintType.D6_CONSTRAINT_TYPE:
                // Relative position normalized to the root prim
                // Essentually a vector pointing from center of rootPrim to center of li.member
                OMV.Vector3 childRelativePosition = liConstraint.member.Position - rootPrim.Position;

                // real world coordinate of midpoint between the two objects
                OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);

                DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
                          rootPrim.LocalID,
                          rootPrim.LocalID, rootPrim.PhysBody.AddrString,
                          liConstraint.member.LocalID, liConstraint.member.PhysBody.AddrString,
                          rootPrim.Position, liConstraint.member.Position, midPoint);

                // create a constraint that allows no freedom of movement between the two objects
                // http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818

                constrain = new BSConstraint6Dof(
                    m_physicsScene.World, rootPrim.PhysBody, liConstraint.member.PhysBody, midPoint, true, true);

                /* NOTE: below is an attempt to build constraint with full frame computation, etc.
                 *     Using the midpoint is easier since it lets the Bullet code manipulate the transforms
                 *     of the objects.
                 * Code left for future programmers.
                 * // ==================================================================================
                 * // relative position normalized to the root prim
                 * OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
                 * OMV.Vector3 childRelativePosition = (liConstraint.member.Position - rootPrim.Position) * invThisOrientation;
                 *
                 * // relative rotation of the child to the parent
                 * OMV.Quaternion childRelativeRotation = invThisOrientation * liConstraint.member.Orientation;
                 * OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation);
                 *
                 * DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, liConstraint.member.LocalID);
                 * constrain = new BS6DofConstraint(
                 *              PhysicsScene.World, rootPrim.Body, liConstraint.member.Body,
                 *              OMV.Vector3.Zero,
                 *              OMV.Quaternion.Inverse(rootPrim.Orientation),
                 *              OMV.Vector3.Zero,
                 *              OMV.Quaternion.Inverse(liConstraint.member.Orientation),
                 *              true,
                 *              true
                 *              );
                 * // ==================================================================================
                 */

                break;

            default:
                break;
            }

            liConstraint.SetConstraintParameters(constrain);

            m_physicsScene.Constraints.AddConstraint(constrain);

            return(constrain);
        }
 public BSLinkInfoConstraint(BSPrimLinkable pMember)
     : base(pMember)
 {
     constraint = null;
     ResetToFixedConstraint();
 }
Ejemplo n.º 31
0
 private void RemoveAxisLockConstraint()
 {
     if (LockAxisConstraint != null)
     {
         m_physicsScene.Constraints.RemoveAndDestroyConstraint(LockAxisConstraint);
         LockAxisConstraint = null;
         m_physicsScene.DetailLog("{0},BSActorLockAxis.RemoveAxisLockConstraint,destroyingConstraint", m_controllingPrim.LocalID);
     }
 }
        // Given a constraint, apply the current constraint parameters to same.
        public override void SetLinkParameters(BSConstraint constrain)
        {
            member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.SetLinkParameters,type={1}", member.LocalID, constraintType);
            switch (constraintType)
            {
                case ConstraintType.FIXED_CONSTRAINT_TYPE:
                case ConstraintType.D6_CONSTRAINT_TYPE:
                    BSConstraint6Dof constrain6dof = constrain as BSConstraint6Dof;
                    if (constrain6dof != null)
                    {
                        // NOTE: D6_SPRING_CONSTRAINT_TYPE should be updated if you change any of this code.
                        // zero linear and angular limits makes the objects unable to move in relation to each other
                        constrain6dof.SetLinearLimits(linearLimitLow, linearLimitHigh);
                        constrain6dof.SetAngularLimits(angularLimitLow, angularLimitHigh);

                        // tweek the constraint to increase stability
                        constrain6dof.UseFrameOffset(useFrameOffset);
                        constrain6dof.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce);
                        constrain6dof.SetCFMAndERP(cfm, erp);
                        if (solverIterations != 0f)
                        {
                            constrain6dof.SetSolverIterations(solverIterations);
                        }
                    }
                    break;
                case ConstraintType.D6_SPRING_CONSTRAINT_TYPE:
                    BSConstraintSpring constrainSpring = constrain as BSConstraintSpring;
                    if (constrainSpring != null)
                    {
                        // zero linear and angular limits makes the objects unable to move in relation to each other
                        constrainSpring.SetLinearLimits(linearLimitLow, linearLimitHigh);
                        constrainSpring.SetAngularLimits(angularLimitLow, angularLimitHigh);

                        // tweek the constraint to increase stability
                        constrainSpring.UseFrameOffset(useFrameOffset);
                        constrainSpring.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce);
                        constrainSpring.SetCFMAndERP(cfm, erp);
                        if (solverIterations != 0f)
                        {
                            constrainSpring.SetSolverIterations(solverIterations);
                        }
                        for (int ii = 0; ii < springAxisEnable.Length; ii++)
                        {
                            constrainSpring.SetAxisEnable(ii, springAxisEnable[ii]);
                            if (springDamping[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED)
                                constrainSpring.SetDamping(ii, springDamping[ii]);
                            if (springStiffness[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED)
                                constrainSpring.SetStiffness(ii, springStiffness[ii]);
                        }
                        constrainSpring.CalculateTransforms();

                        if (springLinearEquilibriumPoint != OMV.Vector3.Zero)
                            constrainSpring.SetEquilibriumPoint(springLinearEquilibriumPoint, springAngularEquilibriumPoint);
                        else
                            constrainSpring.SetEquilibriumPoint(BSAPITemplate.SPRING_NOT_SPECIFIED, BSAPITemplate.SPRING_NOT_SPECIFIED);
                    }
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 33
0
    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.DefaultRegionSize;
            OMV.Vector3 linearLow = new OMV.Vector3(-10000f, -10000f, -10000f);
            OMV.Vector3 linearHigh = new OMV.Vector3(10000f, 10000f, 10000f);
            if (m_controllingPrim.LockedLinearAxis.X != BSPhysObject.FreeAxis)
            {
                linearLow.X = m_controllingPrim.RawPosition.X;
                linearHigh.X = m_controllingPrim.RawPosition.X;
            }
            if (m_controllingPrim.LockedLinearAxis.Y != BSPhysObject.FreeAxis)
            {
                linearLow.Y = m_controllingPrim.RawPosition.Y;
                linearHigh.Y = m_controllingPrim.RawPosition.Y;
            }
            if (m_controllingPrim.LockedLinearAxis.Z != BSPhysObject.FreeAxis)
            {
                linearLow.Z = m_controllingPrim.RawPosition.Z;
                linearHigh.Z = m_controllingPrim.RawPosition.Z;
            }
            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.LockedAngularAxis.X != BSPhysObject.FreeAxis)
            {
                angularLow.X = 0f;
                angularHigh.X = 0f;
            }
            if (m_controllingPrim.LockedAngularAxis.Y != BSPhysObject.FreeAxis)
            {
                angularLow.Y = 0f;
                angularHigh.Y = 0f;
            }
            if (m_controllingPrim.LockedAngularAxis.Z != BSPhysObject.FreeAxis)
            {
                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);
        }
    }
            // Given a constraint, apply the current constraint parameters to same.
            public override void SetLinkParameters(BSConstraint constrain)
            {
                member.PhysScene.DetailLog("{0},BSLinkInfoConstraint.SetLinkParameters,type={1}", member.LocalID, constraintType);
                switch (constraintType)
                {
                case ConstraintType.FIXED_CONSTRAINT_TYPE:
                case ConstraintType.D6_CONSTRAINT_TYPE:
                    BSConstraint6Dof constrain6dof = constrain as BSConstraint6Dof;
                    if (constrain6dof != null)
                    {
                        // NOTE: D6_SPRING_CONSTRAINT_TYPE should be updated if you change any of this code.
                        // zero linear and angular limits makes the objects unable to move in relation to each other
                        constrain6dof.SetLinearLimits(linearLimitLow, linearLimitHigh);
                        constrain6dof.SetAngularLimits(angularLimitLow, angularLimitHigh);

                        // tweek the constraint to increase stability
                        constrain6dof.UseFrameOffset(useFrameOffset);
                        constrain6dof.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce);
                        constrain6dof.SetCFMAndERP(cfm, erp);
                        if (solverIterations != 0f)
                        {
                            constrain6dof.SetSolverIterations(solverIterations);
                        }
                    }
                    break;

                case ConstraintType.D6_SPRING_CONSTRAINT_TYPE:
                    BSConstraintSpring constrainSpring = constrain as BSConstraintSpring;
                    if (constrainSpring != null)
                    {
                        // zero linear and angular limits makes the objects unable to move in relation to each other
                        constrainSpring.SetLinearLimits(linearLimitLow, linearLimitHigh);
                        constrainSpring.SetAngularLimits(angularLimitLow, angularLimitHigh);

                        // tweek the constraint to increase stability
                        constrainSpring.UseFrameOffset(useFrameOffset);
                        constrainSpring.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce);
                        constrainSpring.SetCFMAndERP(cfm, erp);
                        if (solverIterations != 0f)
                        {
                            constrainSpring.SetSolverIterations(solverIterations);
                        }
                        for (int ii = 0; ii < springAxisEnable.Length; ii++)
                        {
                            constrainSpring.SetAxisEnable(ii, springAxisEnable[ii]);
                            if (springDamping[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED)
                            {
                                constrainSpring.SetDamping(ii, springDamping[ii]);
                            }
                            if (springStiffness[ii] != BSAPITemplate.SPRING_NOT_SPECIFIED)
                            {
                                constrainSpring.SetStiffness(ii, springStiffness[ii]);
                            }
                        }
                        constrainSpring.CalculateTransforms();

                        if (springLinearEquilibriumPoint != OMV.Vector3.Zero)
                        {
                            constrainSpring.SetEquilibriumPoint(springLinearEquilibriumPoint, springAngularEquilibriumPoint);
                        }
                        else
                        {
                            constrainSpring.SetEquilibriumPoint(BSAPITemplate.SPRING_NOT_SPECIFIED, BSAPITemplate.SPRING_NOT_SPECIFIED);
                        }
                    }
                    break;

                default:
                    break;
                }
            }