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

            return(result);
        }
示例#2
0
 public BoxWithPoints(BoxWithPoints toCopy)
 {
     P1 = toCopy.P1;
     P2 = toCopy.P2;
     P3 = toCopy.P3;
     P4 = toCopy.P4;
 }
示例#3
0
        public BoxWithPoints GetPoints()
        {
            Vector2 p1, p2, p3, p4;

            p1 = new Vector2(CenterX - Width / 2, CenterY + Height / 2);
            p2 = new Vector2(CenterX - Width / 2, CenterY - Height / 2);
            p3 = new Vector2(CenterX + Width / 2, CenterY - Height / 2);
            p4 = new Vector2(CenterX + Width / 2, CenterY + Height / 2);

            BoxWithPoints result = new BoxWithPoints(p1, p2, p3, p4);

            result.RotateAroundPoint(Theta, new Vector2(CenterX, CenterY));
            return(result);
        }
示例#4
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);
        }