Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Vector2 GetIntersectionDepth(Rectangle _rectB)
- {
- //make sure rects atleast intersect
- if (!Bounds.Intersects(_rectB))
- {
- return Vector2.Zero;
- }
- Vector2 topLeft = new Vector2(_rectB.Left, _rectB.Top);
- Vector2 topRight = new Vector2(_rectB.Right, _rectB.Top);
- Vector2 bottomLeft = new Vector2(_rectB.Left, _rectB.Bottom);
- Vector2 bottomRight = new Vector2(_rectB.Right, _rectB.Bottom);
- float left = Left;
- float right = Right;
- float top = Top;
- float bottom = Bottom;
- //left
- //upside down
- if (VertDirection == -1)
- {
- if (topLeft.X >= left &&
- topLeft.X <= right &&
- topLeft.Y >= top &&
- topLeft.Y <= bottom)
- {
- float y = topLeft.X * Slope + B;
- if (topLeft.Y <= y)
- {
- return new Vector2(0, y - topLeft.Y);
- }
- }
- }
- else
- {
- if (bottomLeft.X >= left &&
- bottomLeft.X <= right &&
- bottomLeft.Y >= top &&
- bottomLeft.Y <= bottom)
- {
- float y = bottomLeft.X * Slope + B;
- if (bottomLeft.Y >= y)
- {
- return new Vector2(0, y - bottomLeft.Y);
- }
- }
- }
- // return 0;
- //test other side
- //right side
- //upside down
- if (VertDirection == -1)
- {
- // if (HorzDirection = 1)
- // {
- if (topRight.X >= left &&
- topRight.X <= right &&
- topRight.Y >= top &&
- topRight.Y <= bottom)
- {
- float y = topRight.X * Slope + B;
- if (topRight.Y <= y)
- {
- return new Vector2(0, y - topRight.Y);
- }
- }
- }
- else
- {
- if (bottomRight.X >= left &&
- bottomRight.X <= right &&
- bottomRight.Y >= top &&
- bottomRight.Y <= bottom)
- {
- float y = bottomRight.X * Slope + B;
- if (bottomRight.Y >= y)
- {
- return new Vector2(0, y - bottomRight.Y);
- }
- }
- }
- return Vector2.Zero;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement