Mail Archives: djgpp/1999/01/17/19:05:52
From: | "Michael Stewart" <mike AT reggin DOT freeserve DOT co DOT uk>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Polygon scan problem
|
Date: | Sun, 17 Jan 1999 23:36:18 -0000
|
Organization: | Customer of Planet Online
|
Lines: | 52
|
Message-ID: | <77tsdv$6mk$1@news7.svr.pol.co.uk>
|
NNTP-Posting-Host: | modem-88.havrix.dialup.pol.co.uk
|
X-Trace: | news7.svr.pol.co.uk 916616447 6868 62.136.70.88 (17 Jan 1999 23:40:47 GMT)
|
NNTP-Posting-Date: | 17 Jan 1999 23:40:47 GMT
|
X-Complaints-To: | abuse AT theplanet DOT net
|
X-Newsreader: | Microsoft Outlook Express 4.72.3110.5
|
X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
I have been having an annoying problem whilst writing a scan convertor.
Hopefully someone will be able to see what I am doing wrong.
The problem I have been having concerns the accuracy of fixed point values.
The routine works as it should while using doubles, however when converting
to fixed point values I loose an enormous amount of accuracy, to much to be
accounted for by the accuracy of a 16.16 fixed point value.
I have tried using Allegros fixed point routines instead of my own and I get
the exactly the same problem. Can anyone see what I am doing wrong ?
The routine I am using is as follows:
struct s_pscan {
int left, right;
}
void fill_scan_line (int x, int y, int x2, int y2, s_pscan *scan) {
fixed xinc, ydif, fx, fy;
int yinc;
// check for special case first
if (y == y2) { // horizontal
if (scan[y].left > x) scan[y].left = x;
if (scan[y].left > x2) scan[y].left = x2;
if (scan[y].right < x) scan[y].right = x;
if (scan[y].right < x2) scan[y].right = x2;
} else { // any other line
int y1;
fixed x1, xinc;
if (y2 < y) { // make sure we're going in the right direction
y1 = y;
y = y2;
y2 = y1;
y1 = x;
x = x2;
x2 = y1;
}
x1 = x;
xinc = (x2 - x) / (y2 - y);
for (y1 = y; y1 <= y2; y1++) {
if (scan[y1].left >int(x1)) scan[y1].left = int(x1);
if (scan[y1].right < int(x1)) scan[y1].right = int(x1);
x1 += xinc;
}
}
}
- Raw text -