Use backtick code blocks for syntax highlighting
This commit is contained in:
parent
8ed9dea394
commit
f658bfbb40
203 changed files with 26546 additions and 25801 deletions
126
57-02.md
126
57-02.md
|
|
@ -51,76 +51,78 @@ level of orientation-dependent asymmetry.
|
|||
|
||||
**LISTING 57.1 L57-1.C**
|
||||
|
||||
/* Texture-map-draw the scan line between two edges. Uses approach of
|
||||
pre-stepping 1/2 pixel into the source image and rounding to the nearest
|
||||
source pixel at each step, so that texture maps will appear
|
||||
reasonably similar at all angles. */
|
||||
```c
|
||||
/* Texture-map-draw the scan line between two edges. Uses approach of
|
||||
pre-stepping 1/2 pixel into the source image and rounding to the nearest
|
||||
source pixel at each step, so that texture maps will appear
|
||||
reasonably similar at all angles. */
|
||||
|
||||
void ScanOutLine(EdgeScan * LeftEdge, EdgeScan * RightEdge)
|
||||
{
|
||||
Fixedpoint SourceX;
|
||||
Fixedpoint SourceY;
|
||||
int DestX = LeftEdge->DestX;
|
||||
int DestXMax = RightEdge->DestX;
|
||||
Fixedpoint DestWidth;
|
||||
Fixedpoint SourceStepX, SourceStepY;
|
||||
void ScanOutLine(EdgeScan * LeftEdge, EdgeScan * RightEdge)
|
||||
{
|
||||
Fixedpoint SourceX;
|
||||
Fixedpoint SourceY;
|
||||
int DestX = LeftEdge->DestX;
|
||||
int DestXMax = RightEdge->DestX;
|
||||
Fixedpoint DestWidth;
|
||||
Fixedpoint SourceStepX, SourceStepY;
|
||||
|
||||
/* Nothing to do if fully X clipped */
|
||||
if ((DestXMax <= ClipMinX) || (DestX >= ClipMaxX)) {
|
||||
return;
|
||||
}
|
||||
/* Nothing to do if fully X clipped */
|
||||
if ((DestXMax <= ClipMinX) || (DestX >= ClipMaxX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((DestXMax - DestX) <= 0) {
|
||||
return; /* nothing to draw */
|
||||
}
|
||||
SourceX = LeftEdge->SourceX;
|
||||
SourceY = LeftEdge->SourceY;
|
||||
if ((DestXMax - DestX) <= 0) {
|
||||
return; /* nothing to draw */
|
||||
}
|
||||
SourceX = LeftEdge->SourceX;
|
||||
SourceY = LeftEdge->SourceY;
|
||||
|
||||
/* Width of destination scan line, for scaling. Note: because this is an
|
||||
integer-based scaling, it can have a total error of as much as nearly
|
||||
one pixel. For more precise scaling, also maintain a fixed-point DestX
|
||||
in each edge, and use it for scaling. If this is done, it will also
|
||||
be necessary to nudge the source start coordinates to the right by an
|
||||
amount corresponding to the distance from the the real (fixed-point)
|
||||
DestX and the first pixel (at an integer X) to be drawn). */
|
||||
DestWidth = INT-TO-FIXED(DestXMax - DestX);
|
||||
/* Width of destination scan line, for scaling. Note: because this is an
|
||||
integer-based scaling, it can have a total error of as much as nearly
|
||||
one pixel. For more precise scaling, also maintain a fixed-point DestX
|
||||
in each edge, and use it for scaling. If this is done, it will also
|
||||
be necessary to nudge the source start coordinates to the right by an
|
||||
amount corresponding to the distance from the the real (fixed-point)
|
||||
DestX and the first pixel (at an integer X) to be drawn). */
|
||||
DestWidth = INT-TO-FIXED(DestXMax - DestX);
|
||||
|
||||
/* Calculate source steps that correspond to each dest X step (across
|
||||
the scan line) */
|
||||
SourceStepX = FixedDiv(RightEdge->SourceX - SourceX, DestWidth);
|
||||
SourceStepY = FixedDiv(RightEdge->SourceY - SourceY, DestWidth);
|
||||
/* Calculate source steps that correspond to each dest X step (across
|
||||
the scan line) */
|
||||
SourceStepX = FixedDiv(RightEdge->SourceX - SourceX, DestWidth);
|
||||
SourceStepY = FixedDiv(RightEdge->SourceY - SourceY, DestWidth);
|
||||
|
||||
/* Advance 1/2 step in the stepping direction, to space scanned pixels
|
||||
evenly between the left and right edges. (There's a slight inaccuracy
|
||||
in dividing negative numbers by 2 by shifting rather than dividing,
|
||||
but the inaccuracy is in the least significant bit, and we'll just
|
||||
live with it.) */
|
||||
SourceX += SourceStepX >> 1;
|
||||
SourceY += SourceStepY >> 1;
|
||||
/* Advance 1/2 step in the stepping direction, to space scanned pixels
|
||||
evenly between the left and right edges. (There's a slight inaccuracy
|
||||
in dividing negative numbers by 2 by shifting rather than dividing,
|
||||
but the inaccuracy is in the least significant bit, and we'll just
|
||||
live with it.) */
|
||||
SourceX += SourceStepX >> 1;
|
||||
SourceY += SourceStepY >> 1;
|
||||
|
||||
/* Clip right edge if necssary */
|
||||
if (DestXMax > ClipMaxX)
|
||||
DestXMax = ClipMaxX;
|
||||
/* Clip right edge if necssary */
|
||||
if (DestXMax > ClipMaxX)
|
||||
DestXMax = ClipMaxX;
|
||||
|
||||
/* Clip left edge if necssary */
|
||||
if (DestX < ClipMinX) {
|
||||
SourceX += FixedMul(SourceStepX, INT-TO-FIXED(ClipMinX - DestX));
|
||||
SourceY += FixedMul(SourceStepY, INT-TO-FIXED(ClipMinX - DestX));
|
||||
DestX = ClipMinX;
|
||||
}
|
||||
/* Scan across the destination scan line, updating the source image
|
||||
position accordingly */
|
||||
for (; DestX<DestXMax; DestX++) {
|
||||
/* Get the currently mapped pixel out of the image and draw it to
|
||||
the screen */
|
||||
WritePixelX(DestX, DestY,
|
||||
GET-IMAGE-PIXEL(TexMapBits, TexMapWidth,
|
||||
ROUND-FIXED-TO-INT(SourceX), ROUND-FIXED-TO-INT(SourceY)) );
|
||||
/* Point to the next source pixel */
|
||||
SourceX += SourceStepX;
|
||||
SourceY += SourceStepY;
|
||||
}
|
||||
}
|
||||
/* Clip left edge if necssary */
|
||||
if (DestX < ClipMinX) {
|
||||
SourceX += FixedMul(SourceStepX, INT-TO-FIXED(ClipMinX - DestX));
|
||||
SourceY += FixedMul(SourceStepY, INT-TO-FIXED(ClipMinX - DestX));
|
||||
DestX = ClipMinX;
|
||||
}
|
||||
/* Scan across the destination scan line, updating the source image
|
||||
position accordingly */
|
||||
for (; DestX<DestXMax; DestX++) {
|
||||
/* Get the currently mapped pixel out of the image and draw it to
|
||||
the screen */
|
||||
WritePixelX(DestX, DestY,
|
||||
GET-IMAGE-PIXEL(TexMapBits, TexMapWidth,
|
||||
ROUND-FIXED-TO-INT(SourceX), ROUND-FIXED-TO-INT(SourceY)) );
|
||||
/* Point to the next source pixel */
|
||||
SourceX += SourceStepX;
|
||||
SourceY += SourceStepY;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Mapping Textures across Multiple Polygons {#Heading6}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue