There was a simple way to find the overlapping rectangle after you found that 2 rectangles have collided using min max functions but I can't remember it. Anyone know what that is?

]]>if (rect1.x1 > rect2.x1) finalrect.x1 = rect1.x1; else finalrect.x1 = rect2.x1; if (rect1.x2 < rect2.x2) finalrect.x2 = rect1.x2; else finalrect.x2 = rect2.x2; if (rect1.y1 > rect2.y1) finalrect.y1 = rect1.y1; else finalrect.y1 = rect2.y1; if (rect1.y2 < rect2.y2) finalrect.y2 = rect1.y2; else finalrect.y2 = rect2.y2;

That's a guess BTW, that I came up with moments after reading your post... I could be totally wrong about that.

--- Kris Asick (Gemini)

--- http://www.pixelships.com

[edit]

Doh, Same as Kris's. I should learn to read before I write

[/edit]

Something like this?

// // rect[n].<Left|Right|Top|Bottom> // n = rectangle number - 0 for first rectangle, 1 for second rectangle or 2 for overlap // Left = left edge // Right = right edge // Top = top edge // Bottom = bottom edge // rect[2].Left = max(rect[0].Left, rect[1].Left) rect[2].Right = min(rect[0].Right, rect[1].Right) rect[2].Top = max(rect[0].Top, rect[1].Top) rect[2].Bottom = min(rect[0].Bottom, rect[1].Bottom)

[edit]

Is there any optimisation to :

finalrect.y2 = (rect1.y2 < rect2.y2) ? rect1.y2 : rect2.y2;

as an alternative to :

if (rect1.y2 < rect2.y2) finalrect.y2 = rect1.y2; else finalrect.y2 = rect2.y2;

[/edit]

]]>