Example #1
0
        /// <summary>
        /// Create an empty box
        /// </summary>
        /// <returns></returns>
        public static AABB2D EmptyBox()
        {
            AABB2D box = new AABB2D();

            box.min = new Vector2(Single.MaxValue);
            box.max = new Vector2(Single.MinValue);
            return(box);
        }
Example #2
0
        /// <summary>
        /// Test two AABB2Ds against each other.
        /// </summary>
        /// <param name="box"></param>
        /// <returns>True if they intersect.  False otherwise.</returns>
        public bool Intersect(AABB2D box)
        {
            bool result = true;

            if ((min.X > box.max.X || max.X < box.min.X) ||
                (min.Y > box.max.Y || max.Y < box.min.Y))
            {
                result = false;
            }

            return(result);
        }   // end of AABB2D Intersect()
Example #3
0
        }   // end of Touched()

        public bool Touched(TouchContact touch, Vector2 adjustedTouchPos, bool confirm)
        {
            bool result = false;

            if (Contains(adjustedTouchPos))
            {
                if (touch.phase == TouchPhase.Began)
                {
                    // touch down - store object touched
                    touch.TouchedObject = this;
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    if (confirm)
                    {
                        AABB2D storedHitBox = touch.TouchedObject as AABB2D;
                        if (storedHitBox != null)
                        {
                            if (storedHitBox == touch.TouchedObject)
                            {
                                // touch up/released on the same object
                                result = true;
                                touch.TouchedObject = null;
                            }
                        }
                    }
                    else
                    {
                        result = true;
                        touch.TouchedObject = null;
                    }
                }
            }

            return(result);
        }   // end of Touched()
Example #4
0
        }   // end of AABB2D c'tor

        public AABB2D(AABB2D src)
        {
            this.min = src.min;
            this.max = src.max;
        }
Example #5
0
 /// <summary>
 /// Union self with other box.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public AABB2D Union(AABB2D other)
 {
     min = Vector2.Min(min, other.Min);
     max = Vector2.Max(max, other.Max);
     return(this);
 }
Example #6
0
        }   // end of Set

        /// <summary>
        /// Initialize from another bounding box.
        /// </summary>
        /// <param name="src"></param>
        public void Set(AABB2D src)
        {
            this.min = src.Min;
            this.max = src.Max;
        }