예제 #1
0
        public void SearchPoint(Vector3 position, List <T> results)
        {
            if (Aabb.Contains(position))
            {
                // check all the items that are part of this object
                foreach (var item in Items)
                {
                    if (item.Aabb.Contains(position))
                    {
                        results.Add(item.Item);
                    }
                }

                nodeA?.SearchPoint(position, results);
                nodeB?.SearchPoint(position, results);
            }
        }
예제 #2
0
        /// <summary>
        ///     Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is
        ///     removed from the tree and re-inserted. Otherwise the function returns immediately.
        /// </summary>
        /// <param name="proxyId">The proxy id.</param>
        /// <param name="aabb">The AABB.</param>
        /// <param name="displacement">The displacement.</param>
        /// <returns>true if the proxy was re-inserted.</returns>
        public bool MoveProxy(int proxyId, ref Aabb aabb, Vector2 displacement)
        {
            Debug.Assert(0 <= proxyId && proxyId < nodeCapacity);

            Debug.Assert(nodes[proxyId].IsLeaf());

            // Extend AABB
            Aabb    fatAabb = new Aabb();
            Vector2 r       = new Vector2(Settings.AabbExtension, Settings.AabbExtension);

            fatAabb.LowerBound = aabb.LowerBound - r;
            fatAabb.UpperBound = aabb.UpperBound + r;

            // Predict AABB movement
            Vector2 d = Settings.AabbMultiplier * displacement;

            if (d.X < 0.0f)
            {
                fatAabb.LowerBound.X += d.X;
            }
            else
            {
                fatAabb.UpperBound.X += d.X;
            }

            if (d.Y < 0.0f)
            {
                fatAabb.LowerBound.Y += d.Y;
            }
            else
            {
                fatAabb.UpperBound.Y += d.Y;
            }

            Aabb treeAabb = nodes[proxyId].Aabb;

            if (treeAabb.Contains(ref aabb))
            {
                // The tree AABB still contains the object, but it might be too large.
                // Perhaps the object was moving fast but has since gone to sleep.
                // The huge AABB is larger than the new fat AABB.
                Aabb hugeAabb = new Aabb
                {
                    LowerBound = fatAabb.LowerBound - 4.0f * r,
                    UpperBound = fatAabb.UpperBound + 4.0f * r
                };

                if (hugeAabb.Contains(ref treeAabb))
                {
                    // The tree AABB contains the object AABB and the tree AABB is
                    // not too large. No tree update needed.
                    return(false);
                }

                // Otherwise the tree AABB is huge and needs to be shrunk
            }

            RemoveLeaf(proxyId);

            nodes[proxyId].Aabb = fatAabb;

            InsertLeaf(proxyId);

            nodes[proxyId].Moved = true;

            return(true);
        }
예제 #3
0
 public bool Contains(LineSeg l)
 {
     return(m_bound.Contains(l));
 }