Exemple #1
0
        public BoxWithPoints GetBoundingBoxPointsRotated()
        {
            BoundingBoxNonAligned box    = new BoundingBoxNonAligned(GetBoundingBoxNonRotated(), Rotation);
            BoxWithPoints         result = box.GetPoints();

            return(result);
        }
Exemple #2
0
 public BoundingBoxNonAligned(BoundingBoxNonAligned cpy)
 {
     CenterX = cpy.CenterX;
     CenterY = cpy.CenterY;
     Width   = cpy.Width;
     Height  = cpy.Height;
     Theta   = cpy.Theta;
 }
Exemple #3
0
        public bool Intersects(BoundingBoxNonAligned box)
        {
            // Work with copies of the boxes instead of modifying the originals
            BoundingBoxNonAligned thisCopy = new BoundingBoxNonAligned(this);
            BoundingBoxNonAligned target   = new BoundingBoxNonAligned(box);

            // Use thisCopy's point as the origin
            Vector2 origin = new Vector2(thisCopy.CenterX, thisCopy.CenterY);

            thisCopy.CenterX -= origin.X;
            thisCopy.CenterY -= origin.Y;
            target.CenterX   -= origin.X;
            target.CenterY   -= origin.Y;

            // Rotate so that box 1 is axis aligned
            BoxWithPoints thisPoints   = thisCopy.GetPoints();
            BoxWithPoints targetPoints = target.GetPoints();
            float         angle        = -target.Theta;

            thisPoints.RotateAroundOrigin(angle);
            targetPoints.RotateAroundOrigin(angle);

            // Check if any points in box 1 are contained within box 2
            // At this point, assume points are from top left and go clockwise
            // TODO: Add some kind of checking to the box with points so we don't have to assume
            if (targetPoints.PointIsInside(thisPoints.P1))
            {
                return(true);
            }
            if (targetPoints.PointIsInside(thisPoints.P2))
            {
                return(true);
            }
            if (targetPoints.PointIsInside(thisPoints.P3))
            {
                return(true);
            }
            if (targetPoints.PointIsInside(thisPoints.P4))
            {
                return(true);
            }
            return(false);
        }
Exemple #4
0
        public BoundingBoxNonAligned GetBoundingBoxNonAligned()
        {
            BoundingBoxNonAligned box = new BoundingBoxNonAligned(GetBoundingBoxNonRotated(), Rotation);

            return(box);
        }