Inheritance: BSPrimDisplaced
        // Create the correct type of linkset for this child
        public static BSLinkset Factory(BSScene physScene, BSPrimLinkable parent)
        {
            BSLinkset ret = null;

            switch (parent.LinksetType)
            {
                case LinksetImplementation.Constraint:
                    ret = new BSLinksetConstraints(physScene, parent);
                    break;
                case LinksetImplementation.Compound:
                    ret = new BSLinksetCompound(physScene, parent);
                    break;
                case LinksetImplementation.Manual:
                    // ret = new BSLinksetManual(physScene, parent);
                    break;
                default:
                    ret = new BSLinksetCompound(physScene, parent);
                    break;
            }
            if (ret == null)
            {
                physScene.Logger.ErrorFormat(
                    "[Bulletsim Linkset] Factory could not create linkset. Parent name={1}, ID={2}", parent.Name,
                    parent.LocalID);
            }
            return ret;
        }
        // TODO!!! public override void SetPhysicalFriction
        // TODO!!! public override void SetPhysicalRestitution
        // TODO!!! public override void SetPhysicalGravity
        // TODO!!! public override void ComputeAndSetLocalInertia
        // TODO!!! public override void SetPhysicalCollisionFlags
        // TODO!!! public override void AddToPhysicalCollisionFlags
        // TODO!!! public override void RemoveFromPhysicalCollisionFlags

        // For compound implimented linksets, if there are children, use compound shape for the root.
        public override BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
        {
            // Returning 'unknown' means we don't have a preference.
            BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN;

            if (IsRoot(requestor) && HasAnyChildren)
            {
                ret = BSPhysicsShapeType.SHAPE_COMPOUND;
            }
            // DetailLog("{0},BSLinksetCompound.PreferredPhysicalShape,call,shape={1}", LinksetRoot.LocalID, ret);
            return(ret);
        }
        // The object is going static (non-physical). Do any setup necessary for a static linkset.
        // Return 'true' if any properties updated on the passed object.
        // This doesn't normally happen -- Universe removes the objects from the physical
        //     world if it is a static linkset.
        // Called at taint-time!
        public override bool MakeStatic(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
            child.ClearDisplacement();
            if (IsRoot(child))
            {
                Refresh(LinksetRoot);
            }
            return(ret);
        }
        // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset.
        // Only the state of the passed object can be modified. The rest of the linkset
        //     has not yet been fully constructed.
        // Return 'true' if any properties updated on the passed object.
        // Called at taint-time!
        public override bool MakeDynamic(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
            if (IsRoot(child))
            {
                // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly.
                Refresh(LinksetRoot);
            }
            return(ret);
        }
 // Schedule a refresh to happen after all the other taint processing.
 protected override void ScheduleRebuild(BSPrimLinkable requestor)
 {
     // When rebuilding, it is possible to set properties that would normally require a rebuild.
     //    If already rebuilding, don't request another rebuild.
     //    If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding.
     lock (m_linksetActivityLock)
     {
         if (!RebuildScheduled && !Rebuilding && HasAnyChildren)
         {
             InternalScheduleRebuild(requestor);
         }
     }
 }
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child)
        {
            if (!HasChild(child))
            {
                m_children.Add(child, new BSLinkInfo(child));

                DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

                // Rebuild the compound shape with the new child shape included
                Refresh(child);
            }
            return;
        }
Exemplo n.º 7
0
 // Link to a linkset where the child knows the parent.
 // Parent changing should not happen so do some sanity checking.
 // We return the parent's linkset so the child can track its membership.
 // Called at runtime.
 public BSLinkset AddMeToLinkset(BSPrimLinkable child)
 {
     lock (m_linksetActivityLock)
     {
         // Don't add the root to its own linkset
         if (!IsRoot(child))
         {
             AddChildToLinkset(child);
         }
         LinksetMass = ComputeLinksetMass();
     }
     return(this);
 }
Exemplo n.º 8
0
        // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape)
        public BSLinksetCompoundInfo(int indx, BSPrimLinkable root, BSPrimLinkable child, OMV.Vector3 centerDisplacement)
        {
            // Each child position and rotation is given relative to the center-of-mass.
            OMV.Quaternion invRootOrientation = OMV.Quaternion.Inverse(root.RawOrientation);
            OMV.Vector3 displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation;
            OMV.Vector3 displacementFromCOM = displacementFromRoot - centerDisplacement;
            OMV.Quaternion displacementRot = child.RawOrientation * invRootOrientation;

            // Save relative position for recomputing child's world position after moving linkset.
            Index = indx;
            OffsetFromRoot = displacementFromRoot;
            OffsetFromCenterOfMass = displacementFromCOM;
            OffsetRot = displacementRot;
        }
        // 'centerDisplacement' is the distance from the root the the center-of-mass (Bullet 'zero' of the shape)
        public BSLinksetCompoundInfo(int indx, BSPrimLinkable root, BSPrimLinkable child, OMV.Vector3 centerDisplacement)
        {
            // Each child position and rotation is given relative to the center-of-mass.
            OMV.Quaternion invRootOrientation   = OMV.Quaternion.Inverse(root.RawOrientation);
            OMV.Vector3    displacementFromRoot = (child.RawPosition - root.RawPosition) * invRootOrientation;
            OMV.Vector3    displacementFromCOM  = displacementFromRoot - centerDisplacement;
            OMV.Quaternion displacementRot      = child.RawOrientation * invRootOrientation;

            // Save relative position for recomputing child's world position after moving linkset.
            Index                  = indx;
            OffsetFromRoot         = displacementFromRoot;
            OffsetFromCenterOfMass = displacementFromCOM;
            OffsetRot              = displacementRot;
        }
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child)
        {
            if (!HasChild(child))
            {
                m_children.Add(child, new BSLinkInfoConstraint(child));

                DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID,
                          child.LocalID);

                // Cause constraints and assorted properties to be recomputed before the next simulation step.
                Refresh(LinksetRoot);
            }
            return;
        }
        // TODO!!! Rename to RemoveDependencies
        // Routine called when rebuilding the body of some member of the linkset.
        // Destroy all the constraints have have been made to root and set
        //     up to rebuild the constraints before the next simulation step.
        // Returns 'true' of something was actually removed and would need restoring
        // Called at taint-time!!
        public override bool RemoveBodyDependencies(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetConstraint.RemoveBodyDependencies,removeChildrenForRoot,rID={1},rBody={2}",
                      child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString);

            lock (m_linksetActivityLock)
            {
                // Just undo all the constraints for this linkset. Rebuild at the end of the step.
                ret = PhysicallyUnlinkAllChildrenFromRoot(LinksetRoot);
                // Cause the constraints, et al to be rebuilt before the next simulation step.
                Refresh(LinksetRoot);
            }
            return(ret);
        }
Exemplo n.º 12
0
        // Remove a child from a linkset.
        // Returns a new linkset for the child which is a linkset of one (just the
        //    orphened child).
        // Called at runtime.
        public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child, bool inTaintTime)
        {
            lock (m_linksetActivityLock)
            {
                if (IsRoot(child))
                {
                    // Cannot remove the root from a linkset.
                    return(this);
                }
            }

            RemoveChildFromLinkset(child, inTaintTime);         // this establishes it's own lock
            LinksetMass = ComputeLinksetMass();

            // The child is down to a linkset of just itself
            return(BSLinkset.Factory(PhysicsScene, child));
        }
Exemplo n.º 13
0
        protected BSLinkset(BSScene scene, BSPrimLinkable parent)
        {
            // A simple linkset of one (no children)
            LinksetID = m_nextLinksetID++;
            // We create LOTS of linksets.
            if (m_nextLinksetID <= 0)
                m_nextLinksetID = 1;
            PhysicsScene = scene;
            LinksetRoot = parent;
            //m_children = new HashSet<BSPrimLinkable>();
            m_children = new Dictionary<BSPrimLinkable, BSLinkInfo>();
            LinksetMass = parent.RawMass;
            Rebuilding = false;
            RebuildScheduled = false;

            parent.ClearDisplacement();
        }
Exemplo n.º 14
0
        protected BSLinkset(BSScene scene, BSPrimLinkable parent)
        {
            // A simple linkset of one (no children)
            LinksetID = m_nextLinksetID++;
            // We create LOTS of linksets.
            if (m_nextLinksetID <= 0)
            {
                m_nextLinksetID = 1;
            }
            PhysicsScene = scene;
            LinksetRoot  = parent;
            //m_children = new HashSet<BSPrimLinkable>();
            m_children       = new Dictionary <BSPrimLinkable, BSLinkInfo>();
            LinksetMass      = parent.RawMass;
            Rebuilding       = false;
            RebuildScheduled = false;

            parent.ClearDisplacement();
        }
Exemplo n.º 15
0
        public override void Link(PhysicsActor obj)
        {
            BSPrimLinkable parent = obj as BSPrimLinkable;

            if (parent != null)
            {
                BSPhysObject parentBefore   = Linkset.LinksetRoot;
                int          childrenBefore = Linkset.NumberOfChildren;

                Linkset = parent.Linkset.AddMeToLinkset(this);

                if (Linkset != null)
                {
                    DetailLog(
                        "{0},BSPrimLinkset.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}",
                        LocalID, parentBefore.LocalID, childrenBefore, Linkset.LinksetRoot.LocalID, Linkset.NumberOfChildren);
                }
            }
            return;
        }
        // Remove linkage between the linkset root and a particular child
        // The root and child bodies are passed in because we need to remove the constraint between
        //      the bodies that were present at unlink time.
        // Called at taint time!
        bool PhysicallyUnlinkAChildFromRoot(BSPrimLinkable rootPrim, BSPrimLinkable childPrim)
        {
            bool ret = false;

            DetailLog(
                "{0},BSLinksetConstraint.PhysicallyUnlinkAChildFromRoot,taint,root={1},rBody={2},child={3},cBody={4}",
                rootPrim.LocalID,
                rootPrim.LocalID, rootPrim.PhysBody.AddrString,
                childPrim.LocalID, childPrim.PhysBody.AddrString);

            // Find the constraint for this link and get rid of it from the overall collection and from my list
            if (PhysicsScene.Constraints.RemoveAndDestroyConstraint(rootPrim.PhysBody, childPrim.PhysBody))
            {
                // Make the child refresh its location
                PhysicsScene.PE.PushUpdate(childPrim.PhysBody);
                ret = true;
            }

            return(ret);
        }
Exemplo n.º 17
0
        public override PhysicsActor AddPrimShape(UUID primID, uint localID, string name, byte physicsType,
                                                  PrimitiveBaseShape shape,
                                                  Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical, int material,
                                                  float friction, float restitution, float gravityMultiplier, float density)
        {
            // MainConsole.Instance.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);

            if (!m_initialized)
            {
                return(null);
            }

            // DetailLog("{0},BSScene.AddPrimShape,call", localID);

            BSPhysObject prim = new BSPrimLinkable(localID, name, this, position, size, rotation, shape, false, material,
                                                   friction, restitution, gravityMultiplier, density);

            prim.UUID = primID;
            lock (PhysObjects) PhysObjects.Add(localID, prim);
            return(prim);
        }
        // When the linkset is built, the child shape is added to the compound shape relative to the
        //    root shape. The linkset then moves around but this does not move the actual child
        //    prim. The child prim's location must be recomputed based on the location of the root shape.
        void RecomputeChildWorldPosition(BSPrimLinkable child, bool inTaintTime)
        {
            // For the moment (20130201), disable this computation (converting the child physical addr back to
            //    a region address) until we have a good handle on center-of-mass offsets and what the physics
            //    engine moving a child actually means.
            // The simulator keeps track of where children should be as the linkset moves. Setting
            //    the pos/rot here does not effect that knowledge as there is no good way for the
            //    physics engine to send the simulator an update for a child.

            /*
             * BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo;
             * if (lci != null)
             * {
             *  if (inTaintTime)
             *  {
             *      OMV.Vector3 oldPos = child.RawPosition;
             *      child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetFromRoot;
             *      child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot;
             *      DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}",
             *                                  child.LocalID, oldPos, lci, child.RawPosition);
             *  }
             *  else
             *  {
             *      // TaintedObject is not used here so the raw position is set now and not at taint-time.
             *      child.Position = LinksetRoot.RawPosition + lci.OffsetFromRoot;
             *      child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot;
             *  }
             * }
             * else
             * {
             *  // This happens when children have been added to the linkset but the linkset
             *  //     has not been constructed yet. So like, at taint time, adding children to a linkset
             *  //     and then changing properties of the children (makePhysical, for instance)
             *  //     but the post-print action of actually rebuilding the linkset has not yet happened.
             *  // PhysicsScene.Logger.WarnFormat("{0} Restoring linkset child position failed because of no relative position computed. ID={1}",
             *  //                                 LogHeader, child.LocalID);
             *  DetailLog("{0},BSLinksetCompound.recomputeChildWorldPosition,noRelativePositonInfo", child.LocalID);
             * }
             */
        }
Exemplo n.º 19
0
        // TODO!!! public virtual bool ShouldReportPropertyUpdates

        // Called after a simulation step to post a collision with this object.
        // Return 'true' if linkset processed the collision. 'false' says the linkset didn't have
        //     anything to add for the collision and it should be passed through normal processing.
        // Default processing for a linkset.
        public virtual bool HandleCollide(uint collidingWith, BSPhysObject collidee,
                                          OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
        {
            bool ret = false;

            // prims in the same linkset cannot collide with each other
            BSPrimLinkable convCollidee = collidee as BSPrimLinkable;

            if (convCollidee != null && (LinksetID == convCollidee.Linkset.LinksetID))
            {
                // By returning 'true', we tell the caller the collision has been 'handled' so it won't
                //     do anything about this collision and thus, effectivily, ignoring the collision.
                ret = true;
            }
            else
            {
                // Not a collision between members of the linkset. Must be a real collision.
                // So the linkset root can know if there is a collision anywhere in the linkset.
                LinksetRoot.SomeCollisionSimulationStep = PhysicsScene.SimulationStep;
            }

            return(ret);
        }
 // must be called with m_linksetActivityLock or race conditions will haunt you.
 void InternalScheduleRebuild(BSPrimLinkable requestor)
 {
     DetailLog("{0},BSLinksetCompound.InternalScheduleRebuild,,rebuilding={1},hasChildren={2}", requestor.LocalID,
               Rebuilding, HasAnyChildren);
     RebuildScheduled = true;
     PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate()
     {
         if (HasAnyChildren)
         {
             if (AllPartsComplete)
             {
                 RecomputeLinksetCompound();
             }
             else
             {
                 DetailLog(
                     "{0},BSLinksetCompound.InternalScheduleRebuild,,rescheduling because not all children complete",
                     requestor.LocalID);
                 InternalScheduleRebuild(requestor);
             }
         }
         RebuildScheduled = false;
     });
 }
        // Remove the specified child from the linkset.
        // Safe to call even if the child is not really in my linkset.
        protected override void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime)
        {
            if (m_children.Remove(child))
            {
                BSPrimLinkable rootx  = LinksetRoot; // capture the root and body as of now
                BSPrimLinkable childx = child;

                DetailLog("{0},BSLinksetConstraints.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
                          childx.LocalID,
                          rootx.LocalID, rootx.PhysBody.AddrString,
                          childx.LocalID, childx.PhysBody.AddrString);

                PhysicsScene.TaintedObject(inTaintTime, "BSLinksetConstraints.RemoveChildFromLinkset",
                                           delegate() { PhysicallyUnlinkAChildFromRoot(rootx, childx); });
                // See that the linkset parameters are recomputed at the end of the taint time.
                Refresh(LinksetRoot);
            }
            else
            {
                // Non-fatal occurance.
                // PhysicsScene.Logger.ErrorFormat("{0}: Asked to remove child from linkset that was not in linkset", LogHeader);
            }
            return;
        }
Exemplo n.º 22
0
 // Some linksets have a preferred physical shape.
 // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected.
 public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
 {
     return BSPhysicsShapeType.SHAPE_UNKNOWN;
 }
Exemplo n.º 23
0
        // ================================================================

        // Add a new child to the linkset.
        // Called while LinkActivity is locked.
        protected override void AddChildToLinkset(BSPrimLinkable child)
        {
            if (!HasChild(child))
            {
                m_children.Add(child, new BSLinkInfo(child));

                DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);

                // Rebuild the compound shape with the new child shape included
                Refresh(child);

            }
            return;
        }
Exemplo n.º 24
0
 // When physical properties are changed the linkset needs to recalculate
 //   its internal properties.
 public override void Refresh(BSPrimLinkable requestor)
 {
     // Something changed so do the rebulding thing
     ScheduleRebuild(requestor);
     base.Refresh(requestor);
 }
Exemplo n.º 25
0
 // Return 'true' if the passed object is the root object of this linkset
 public bool IsRoot(BSPrimLinkable requestor)
 {
     return(requestor.LocalID == LinksetRoot.LocalID);
 }
Exemplo n.º 26
0
 // must be called with m_linksetActivityLock or race conditions will haunt you.
 void InternalScheduleRebuild(BSPrimLinkable requestor)
 {
     DetailLog("{0},BSLinksetCompound.InternalScheduleRebuild,,rebuilding={1},hasChildren={2}", requestor.LocalID,
         Rebuilding, HasAnyChildren);
     RebuildScheduled = true;
     PhysicsScene.PostTaintObject("BSLinksetCompound.ScheduleRebuild", LinksetRoot.LocalID, delegate()
     {
         if (HasAnyChildren)
         {
             if (AllPartsComplete)
             {
                 RecomputeLinksetCompound();
             }
             else
             {
                 DetailLog(
                     "{0},BSLinksetCompound.InternalScheduleRebuild,,rescheduling because not all children complete",
                     requestor.LocalID);
                 InternalScheduleRebuild(requestor);
             }
         }
         RebuildScheduled = false;
     });
 }
Exemplo n.º 27
0
 // Some linksets have a preferred physical shape.
 // Returns SHAPE_UNKNOWN if there is no preference. Causes the correct shape to be selected.
 public virtual BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
 {
     return(BSPhysicsShapeType.SHAPE_UNKNOWN);
 }
Exemplo n.º 28
0
        // TODO!!! rename to RemoveDependencies!
        // Routine called when rebuilding the body of some member of the linkset.
        // Since we don't keep in world relationships, do nothing unless it's a child changing.
        // Returns 'true' of something was actually removed and would need restoring
        // Called at taint-time!!
        public override bool RemoveBodyDependencies(BSPrimLinkable child)
        {
            bool ret = false;

            DetailLog("{0},BSLinksetCompound.RemoveBodyDependencies,refreshIfChild,rID={1},rBody={2},isRoot={3}",
                child.LocalID, LinksetRoot.LocalID, LinksetRoot.PhysBody, IsRoot(child));

            Refresh(child);

            return ret;
        }
Exemplo n.º 29
0
        // Remove a child from a linkset.
        // Returns a new linkset for the child which is a linkset of one (just the
        //    orphened child).
        // Called at runtime.
        public BSLinkset RemoveMeFromLinkset(BSPrimLinkable child, bool inTaintTime)
        {
            lock (m_linksetActivityLock)
            {
                if (IsRoot(child))
                {
                    // Cannot remove the root from a linkset.
                    return this;
                }
            }

            RemoveChildFromLinkset(child, inTaintTime);         // this establishes it's own lock
            LinksetMass = ComputeLinksetMass();
 
            // The child is down to a linkset of just itself
            return BSLinkset.Factory(PhysicsScene, child);
        }
Exemplo n.º 30
0
 protected abstract void ScheduleRebuild(BSPrimLinkable requestor);
Exemplo n.º 31
0
 // The object is going dynamic (physical). Do any setup necessary
 //     for a dynamic linkset.
 // Only the state of the passed object can be modified. The rest of the linkset
 //     has not yet been fully constructed.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public abstract bool MakeDynamic(BSPrimLinkable child);
Exemplo n.º 32
0
 // I am the root of a linkset and a new child is being added
 // Called while LinkActivity is locked.
 protected abstract void AddChildToLinkset(BSPrimLinkable child);
Exemplo n.º 33
0
 // Return 'true' if this child is in this linkset
 public bool HasChild(BSPrimLinkable child)
 {
     bool ret;
     lock (m_linksetActivityLock)
     {
         ret = m_children.ContainsKey(child);
     }
     return ret;
 }
Exemplo n.º 34
0
 // Return 'true' if the passed object is the root object of this linkset
 public bool IsRoot(BSPrimLinkable requestor)
 {
     return (requestor.LocalID == LinksetRoot.LocalID);
 }
Exemplo n.º 35
0
        // When the linkset is built, the child shape is added to the compound shape relative to the
        //    root shape. The linkset then moves around but this does not move the actual child
        //    prim. The child prim's location must be recomputed based on the location of the root shape.
        void RecomputeChildWorldPosition(BSPrimLinkable child, bool inTaintTime)
        {
            // For the moment (20130201), disable this computation (converting the child physical addr back to
            //    a region address) until we have a good handle on center-of-mass offsets and what the physics
            //    engine moving a child actually means.
            // The simulator keeps track of where children should be as the linkset moves. Setting
            //    the pos/rot here does not effect that knowledge as there is no good way for the
            //    physics engine to send the simulator an update for a child.

            /*
            BSLinksetCompoundInfo lci = child.LinksetInfo as BSLinksetCompoundInfo;
            if (lci != null)
            {
                if (inTaintTime)
                {
                    OMV.Vector3 oldPos = child.RawPosition;
                    child.ForcePosition = LinksetRoot.RawPosition + lci.OffsetFromRoot;
                    child.ForceOrientation = LinksetRoot.RawOrientation * lci.OffsetRot;
                    DetailLog("{0},BSLinksetCompound.RecomputeChildWorldPosition,oldPos={1},lci={2},newPos={3}",
                                                child.LocalID, oldPos, lci, child.RawPosition);
                }
                else
                {
                    // TaintedObject is not used here so the raw position is set now and not at taint-time.
                    child.Position = LinksetRoot.RawPosition + lci.OffsetFromRoot;
                    child.Orientation = LinksetRoot.RawOrientation * lci.OffsetRot;
                }
            }
            else
            {
                // This happens when children have been added to the linkset but the linkset
                //     has not been constructed yet. So like, at taint time, adding children to a linkset
                //     and then changing properties of the children (makePhysical, for instance)
                //     but the post-print action of actually rebuilding the linkset has not yet happened.
                // PhysicsScene.Logger.WarnFormat("{0} Restoring linkset child position failed because of no relative position computed. ID={1}",
                //                                 LogHeader, child.LocalID);
                DetailLog("{0},BSLinksetCompound.recomputeChildWorldPosition,noRelativePositonInfo", child.LocalID);
            }
            */
        }
Exemplo n.º 36
0
 // The object is going static (non-physical). Do any setup necessary for a static linkset.
 // Return 'true' if any properties updated on the passed object.
 // This doesn't normally happen -- Universe removes the objects from the physical
 //     world if it is a static linkset.
 // Called at taint-time!
 public override bool MakeStatic(BSPrimLinkable child)
 {
     bool ret = false;
     DetailLog("{0},BSLinksetCompound.MakeStatic,call,IsRoot={1}", child.LocalID, IsRoot(child));
     child.ClearDisplacement();
     if (IsRoot(child))
     {
         Refresh(LinksetRoot);
     }
     return ret;
 }
Exemplo n.º 37
0
 // Called when a parameter update comes from the physics engine for any object
 //      of the linkset is received.
 // Passed flag is update came from physics engine (true) or the user (false).
 // Called at taint-time!!
 public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable physObject);
Exemplo n.º 38
0
 // Link to a linkset where the child knows the parent.
 // Parent changing should not happen so do some sanity checking.
 // We return the parent's linkset so the child can track its membership.
 // Called at runtime.
 public BSLinkset AddMeToLinkset(BSPrimLinkable child)
 {
     lock (m_linksetActivityLock)
     {
         // Don't add the root to its own linkset
         if (!IsRoot(child))
             AddChildToLinkset(child);
         LinksetMass = ComputeLinksetMass();
     }
     return this;
 }
Exemplo n.º 39
0
        // 'physicalUpdate' is true if these changes came directly from the physics engine. Don't need to rebuild then.
        // Called at taint-time.
        public override void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable updated)
        {
            if (!LinksetRoot.IsPhysicallyActive)
            {
                // No reason to do this physical stuff for static linksets.
                DetailLog("{0},BSLinksetCompound.UpdateProperties,notPhysical", LinksetRoot.LocalID);
                return;
            }
            // The user moving a child around requires the rebuilding of the linkset compound shape
            // One problem is this happens when a border is crossed -- the simulator implementation
            //    stores the position into the group which causes the move of the object
            //    but it also means all the child positions get updated.
            //    What would cause an unnecessary rebuild so we make sure the linkset is in a
            //    region before bothering to do a rebuild.
            if (!IsRoot(updated) && PhysicsScene.TerrainManager.IsWithinKnownTerrain(LinksetRoot.RawPosition))
            {
                // If a child of the linkset is updating only the position or rotation, that can be done
                //    without rebuilding the linkset.
                // If a handle for the child can be fetch, we update the child here. If a rebuild was
                //    scheduled by someone else, the rebuild will just replace this setting.
                bool updatedChild = false;

                // Anything other than updating position or orientation usually means a physical update
                //     and that is caused by us updating the object.
                if ((whichUpdated & ~(UpdatedProperties.Position | UpdatedProperties.Orientation)) == 0)
                {
                    // Find the physical instance of the child 
                    if (!RebuildScheduled && !LinksetRoot.IsIncomplete && LinksetRoot.PhysShape.HasPhysicalShape &&
                        PhysicsScene.PE.IsCompound(LinksetRoot.PhysShape.physShapeInfo))
                    {
                        // It is possible that the linkset is still under construction and the child is not yet
                        //    inserted into the compound shape. A rebuild of the linkset in a pre-step action will
                        //    build the whole thing with the new position or rotation.
                        // The index must be checked because Bullet references the child array but does no validity
                        //    checking of the child index passed.
                        int numLinksetChildren =
                            PhysicsScene.PE.GetNumberOfCompoundChildren(LinksetRoot.PhysShape.physShapeInfo);
                        if (updated.LinksetChildIndex < numLinksetChildren)
                        {
                            BulletShape linksetChildShape =
                                PhysicsScene.PE.GetChildShapeFromCompoundShapeIndex(LinksetRoot.PhysShape.physShapeInfo,
                                    updated.LinksetChildIndex);
                            if (linksetChildShape.HasPhysicalShape)
                            {
                                // Found the child shape within the compound shape
                                PhysicsScene.PE.UpdateChildTransform(LinksetRoot.PhysShape.physShapeInfo,
                                    updated.LinksetChildIndex,
                                    updated.RawPosition - LinksetRoot.RawPosition,
                                    updated.RawOrientation*OMV.Quaternion.Inverse(LinksetRoot.RawOrientation),
                                    true /* shouldRecalculateLocalAabb */);
                                updatedChild = true;
                                DetailLog(
                                    "{0},BSLinksetCompound.UpdateProperties,changeChildPosRot,whichUpdated={1},pos={2},rot={3}",
                                    updated.LocalID, whichUpdated, updated.RawPosition, updated.RawOrientation);
                            }
                            else // DEBUG DEBUG
                            {
                                // DEBUG DEBUG
                                DetailLog(
                                    "{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,noChildShape,shape={1}",
                                    updated.LocalID, linksetChildShape);
                            } // DEBUG DEBUG
                        }
                        else // DEBUG DEBUG
                        {
                            // DEBUG DEBUG
                            // the child is not yet in the compound shape. This is non-fatal.
                            DetailLog(
                                "{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,childNotInCompoundShape,numChildren={1},index={2}",
                                updated.LocalID, numLinksetChildren, updated.LinksetChildIndex);
                        } // DEBUG DEBUG
                    }
                    else // DEBUG DEBUG
                    {
                        // DEBUG DEBUG
                        DetailLog("{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild,noBodyOrNotCompound",
                            updated.LocalID);
                    } // DEBUG DEBUG

                    if (!updatedChild)
                    {
                        // If couldn't do the individual child, the linkset needs a rebuild to incorporate the new child info.
                        // Note: there are several ways through this code that will not update the child if
                        //    the linkset is being rebuilt. In this case, scheduling a rebuild is a NOOP since
                        //    there will already be a rebuild scheduled.
                        DetailLog(
                            "{0},BSLinksetCompound.UpdateProperties,couldNotUpdateChild.schedulingRebuild,whichUpdated={1}",
                            updated.LocalID, whichUpdated);
                        Refresh(updated);
                    }
                }
            }
        }
Exemplo n.º 40
0
 public BSLinkInfo(BSPrimLinkable pMember)
 {
     member = pMember;
 }
Exemplo n.º 41
0
 // The object is going dynamic (physical). Do any setup necessary for a dynamic linkset.
 // Only the state of the passed object can be modified. The rest of the linkset
 //     has not yet been fully constructed.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public override bool MakeDynamic(BSPrimLinkable child)
 {
     bool ret = false;
     DetailLog("{0},BSLinksetCompound.MakeDynamic,call,IsRoot={1}", child.LocalID, IsRoot(child));
     if (IsRoot(child))
     {
         // The root is going dynamic. Rebuild the linkset so parts and mass get computed properly.
         Refresh(LinksetRoot);
     }
     return ret;
 }
Exemplo n.º 42
0
#pragma warning restore 414

        public BSLinksetCompound(BSScene scene, BSPrimLinkable parent)
            : base(scene, parent)
        {
            LinksetImpl = LinksetImplementation.Compound;
        }
#pragma warning restore 414

        public BSLinksetCompound(BSScene scene, BSPrimLinkable parent)
            : base(scene, parent)
        {
            LinksetImpl = LinksetImplementation.Compound;
        }
Exemplo n.º 44
0
 // Called when a parameter update comes from the physics engine for any object
 //      of the linkset is received.
 // Passed flag is update came from physics engine (true) or the user (false).
 // Called at taint-time!!
 public abstract void UpdateProperties(UpdatedProperties whichUpdated, BSPrimLinkable physObject);
Exemplo n.º 45
0
 // Schedule a refresh to happen after all the other taint processing.
 protected override void ScheduleRebuild(BSPrimLinkable requestor)
 {
     // When rebuilding, it is possible to set properties that would normally require a rebuild.
     //    If already rebuilding, don't request another rebuild.
     //    If a linkset with just a root prim (simple non-linked prim) don't bother rebuilding.
     lock (m_linksetActivityLock)
     {
         if (!RebuildScheduled && !Rebuilding && HasAnyChildren)
         {
             InternalScheduleRebuild(requestor);
         }
     }
 }
Exemplo n.º 46
0
 // TODO!!! rename to RemoveDependencies
 // Routine used when rebuilding the body of the root of the linkset
 // Destroy all the constraints have have been made to root.
 // This is called when the root body is changing.
 // Returns 'true' of something was actually removed and would need restoring
 // Called at taint-time!!
 public abstract bool RemoveBodyDependencies(BSPrimLinkable child);
Exemplo n.º 47
0
        // TODO!!! public override void SetPhysicalFriction
        // TODO!!! public override void SetPhysicalRestitution
        // TODO!!! public override void SetPhysicalGravity
        // TODO!!! public override void ComputeAndSetLocalInertia
        // TODO!!! public override void SetPhysicalCollisionFlags
        // TODO!!! public override void AddToPhysicalCollisionFlags
        // TODO!!! public override void RemoveFromPhysicalCollisionFlags

        // For compound implimented linksets, if there are children, use compound shape for the root.
        public override BSPhysicsShapeType PreferredPhysicalShape(BSPrimLinkable requestor)
        {
            // Returning 'unknown' means we don't have a preference.
            BSPhysicsShapeType ret = BSPhysicsShapeType.SHAPE_UNKNOWN;
            if (IsRoot(requestor) && HasAnyChildren)
            {
                ret = BSPhysicsShapeType.SHAPE_COMPOUND;
            }
            // DetailLog("{0},BSLinksetCompound.PreferredPhysicalShape,call,shape={1}", LinksetRoot.LocalID, ret);
            return ret;
        }
Exemplo n.º 48
0
        // Remove the specified child from the linkset.
        // Safe to call even if the child is not really in the linkset.
        protected override void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime)
        {
            child.ClearDisplacement();

            if (m_children.Remove(child))
            {
                DetailLog("{0},BSLinksetCompound.RemoveChildFromLinkset,call,rID={1},rBody={2},cID={3},cBody={4}",
                    child.LocalID,
                    LinksetRoot.LocalID, LinksetRoot.PhysBody.AddrString,
                    child.LocalID, child.PhysBody.AddrString);

                // Cause the child's body to be rebuilt and thus restored to normal operation
                child.ForceBodyShapeRebuild(inTaintTime);

                if (!HasAnyChildren)
                {
                    // The linkset is now empty. The root needs rebuilding.
                    LinksetRoot.ForceBodyShapeRebuild(inTaintTime);
                }
                else
                {
                    // Rebuild the compound shape with the child removed
                    Refresh(LinksetRoot);
                }
            }
            return;
        }
Exemplo n.º 49
0
 // I am the root of a linkset and a new child is being added
 // Called while LinkActivity is locked.
 protected abstract void AddChildToLinkset(BSPrimLinkable child);
Exemplo n.º 50
0
 public BSLinkInfo(BSPrimLinkable pMember)
 {
     member = pMember;
 }
Exemplo n.º 51
0
 // I am the root of a linkset and one of my children is being removed.
 // Safe to call even if the child is not really in my linkset.
 protected abstract void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime);
Exemplo n.º 52
0
 // I am the root of a linkset and one of my children is being removed.
 // Safe to call even if the child is not really in my linkset.
 protected abstract void RemoveChildFromLinkset(BSPrimLinkable child, bool inTaintTime);
Exemplo n.º 53
0
 // When physical properties are changed the linkset needs to recalculate
 //   its internal properties.
 // May be called at runtime or taint-time.
 public virtual void Refresh(BSPrimLinkable requestor)
 {
     LinksetMass = ComputeLinksetMass();
 }
Exemplo n.º 54
0
 protected abstract void ScheduleRebuild(BSPrimLinkable requestor);
Exemplo n.º 55
0
 // The object is going static (non-physical). Do any setup necessary
 //     for a static linkset.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public abstract bool MakeStatic(BSPrimLinkable child);
Exemplo n.º 56
0
 // When physical properties are changed the linkset needs to recalculate
 //   its internal properties.
 // May be called at runtime or taint-time.
 public virtual void Refresh(BSPrimLinkable requestor)
 {
     LinksetMass = ComputeLinksetMass();
 }
Exemplo n.º 57
0
 // TODO!!! rename to RemoveDependencies
 // Routine used when rebuilding the body of the root of the linkset
 // Destroy all the constraints have have been made to root.
 // This is called when the root body is changing.
 // Returns 'true' of something was actually removed and would need restoring
 // Called at taint-time!!
 public abstract bool RemoveBodyDependencies(BSPrimLinkable child);
Exemplo n.º 58
0
 // The object is going dynamic (physical). Do any setup necessary
 //     for a dynamic linkset.
 // Only the state of the passed object can be modified. The rest of the linkset
 //     has not yet been fully constructed.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public abstract bool MakeDynamic(BSPrimLinkable child);
Exemplo n.º 59
0
        public override PhysicsActor AddPrimShape(UUID primID, uint localID, string name, byte physicsType,
            PrimitiveBaseShape shape,
            Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical, int material,
            float friction, float restitution, float gravityMultiplier, float density)
        {
            // MainConsole.Instance.DebugFormat("{0}: AddPrimShape2: {1}", LogHeader, primName);

            if (!m_initialized) return null;

            // DetailLog("{0},BSScene.AddPrimShape,call", localID);

            BSPhysObject prim = new BSPrimLinkable(localID, name, this, position, size, rotation, shape, false, material,
                friction, restitution, gravityMultiplier, density);
            prim.UUID = primID;
            lock (PhysObjects) PhysObjects.Add(localID, prim);
            return prim;
        }
Exemplo n.º 60
0
 // The object is going static (non-physical). Do any setup necessary
 //     for a static linkset.
 // Return 'true' if any properties updated on the passed object.
 // Called at taint-time!
 public abstract bool MakeStatic(BSPrimLinkable child);