Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

question on polyfill algorithm

2 views
Skip to first unread message

Paal K Holmberg

unread,
Feb 3, 1992, 7:06:57 AM2/3/92
to

I am currently working on my own graphicsroutines for mode 13h 320x200x256,
and have tried to find good algorithms for drawing convex plygons for use
in 3d simulation games.
In the process i have come up with the following algorithm , and i wonder
if it is a good one (i.e. fast), and also if anyone can give me tips on
any other fast polyfill algoritm.

Assuming the the linesegment are clipped and the n points are stored
in an array p, the algorithm follows.

1) find the point with maximal y coordinate(max_point), and the minimal
y coordinate( min_y)
2) find how to get form max_point to the next point on the left
and on the right side of the polygon
i.e.
tmp=max_point-1;
if (tmp<0) tmp=n-1;
if (p[tmp].x < p[(max_point+1) % n].x
{
left_incr=-1;
right_incr=1;
}
else
{
left_incr=1;
right_incr=-1;
}
3) do a modified bresenham line-traversal on from max_y to min_y
through the line-segments on the left side of the polygon, which
stores the offsets in an offset buffer. (i.e. offset for intersection
with scan-line y is stored in ofs_buf[y].left)

4) repeat this for the right side of the polygon, and store offsets
in ofs_buf[y].right

5) do a loop from max_y to min_y
and fill the offsets from ofs_buf[i].left to ofs_buf[i].right with
assembly stosd (for 386/486) and the rest with stosb


i have implemeted a slower variety of this algorithm which used C
except for the offset fill, for which i used inline assmebler.
I also wonder how much could be earned by converting the whole routine
to assembler, if anyone has any answers to this, then feel free to reply.

Paal K Holmberg
UiB
Norway

"To program, or not to program - that is the question."

0 new messages