Ejemplo n.º 1
0
        ///<summary>
        ///there's no need to do an accurate (and expensive) circle versus
        ///rectangle intersection test. Instead we'll just test the bounding box
        ///of the given circle with the rectangle.
        ///</summary>
        ///<param name="entityCenter"></param>
        ///<param name="entityRadius"></param>
        ///<returns></returns>
        public override bool IsTouching(Vector2 entityCenter, float entityRadius)
        {
            InvertedAABBox2D box =
                new InvertedAABBox2D(
                    new Vector2(
                        entityCenter.X - entityRadius,
                        entityCenter.Y - entityRadius),
                    new Vector2(
                        entityCenter.X + entityRadius,
                        entityCenter.Y + entityRadius));

            return box.IsOverlappedWith(Rectangle);
        }
Ejemplo n.º 2
0
 //returns
 ///<summary>
 ///Tests if the bounding box described by other intersects with this one
 ///</summary>
 ///<param name="other"></param>
 ///<returns>
 ///true if the bounding box described by other intersects with this one
 ///</returns>
 public bool IsOverlappedWith(InvertedAABBox2D other)
 {
     return !((other.Top > Bottom) ||
            (other.Bottom < Top) ||
            (other.Left > Right) ||
            (other.Right < Left));
 }
Ejemplo n.º 3
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="topLeft"></param>
 ///<param name="bottomRight"></param>
 public Cell(Vector2 topLeft, Vector2 bottomRight)
 {
     _members = new List<NavGraphNode>();
     _boundingBox = new InvertedAABBox2D(topLeft, bottomRight);
 }
Ejemplo n.º 4
0
        ///<summary>
        ///This must be called to create the list of neighbors. This method 
        ///examines each cell within range of the target, If the cells contain
        ///entities then they are tested to see if they are situated within the
        ///target's neighborhood region. If they are they are added to
        ///neighbor list
        ///</summary>
        ///<param name="targetPos"></param>
        ///<param name="queryRadius"></param>
        public void CalculateNeighbors(Vector2 targetPos, float queryRadius)
        {
            //create an iterator and set it to the beginning of the
            //neighbor list
            int curNbor = 0;

            //create the query box that is the bounding box of the
            //target's query area
            InvertedAABBox2D queryBox =
                new InvertedAABBox2D(
                    targetPos - new Vector2(queryRadius, queryRadius),
                    targetPos + new Vector2(queryRadius, queryRadius));

            //iterate through each cell and test to see if its bounding box
            //overlaps with the query box. If it does and it also contains
            //entities then make further proximity tests.
            foreach (Cell curCell in Cells)
            {
                //test to see if this cell contains members and if it overlaps
                //the query box
                if (!curCell.BoundingBox.IsOverlappedWith(queryBox) ||
                    curCell.Members.Count <= 0)
                    continue;

                //add any entities found within query radius to the neighbor list
                foreach (NavGraphNode curNode in curCell.Members)
                {
                    if (GraphNode.IsInvalidIndex(curNode.Index))
                        continue;

                    if (Vector2.DistanceSquared(curNode.Position, targetPos) >=
                        queryRadius*queryRadius)
                        continue;

                    Neighbors[curNbor] = curNode;
                    curNbor++;
                }
            }

            //mark the end of the list with a null.
            Neighbors[curNbor] = null;
        }
Ejemplo n.º 5
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="topLeft"></param>
 ///<param name="bottomRight"></param>
 public TriggerRegionRectangle(Vector2 topLeft, Vector2 bottomRight)
 {
     _rectangle = new InvertedAABBox2D(topLeft, bottomRight);
 }