Hello,
This kinda leads on from an earlier post I made in the C Programming board, but as that one apparently fell on deaf ears I suppose graphics-related algorithms can be posted under Game Programming?
Anyways, I'm trying to implement what could be referred to as "dirty rectangle drawing". I've got all the basic rectangle functions sorted out (intersection, difference) and adapted them for use with linked lists of rectangles that can describe a complex region.
The thing is, applying intersection and difference to two rectangles in lists ignores the presence of any other rectangles and so I end up with a lot of overlapping rectangles, which is bad.
Is the pseudocode function below, which modifies a list given to it to contain non-overlapping rectangles only, sensible?
Code:
void deoverlap_region(t_region *region)
{
t_region *rgn1, *rgn2, *rgnIntersect;
rgn1 = region;
While rgn1
{
rgn2 = region;
While rgn2
{
If (rgn1 <> rgn2)
{
rgnIntersect = intersect(rgn1, rgn2);
If (rgnIntersect)
{
Detach rect rgn2 from the list
Append the difference of rgn2 and rgnIntersect (rgn2 - rgnIntersect) to region
rgn2 = the rect that was next in the list
}
Else
rgn2 = rgn2->next;
}
Else
rgn2 = rgn2->next;
}
rgn1 = rgn1->next;
}
}
If anyone knows anywhere that talks about this type of algorithm, I'd be grateful.