135 lines
4.5 KiB
HTML
135 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta name="vsisbn" content="1576101746" />
|
|
<meta name="vstitle" content="Michael Abrash's Graphics Programming Black Book, Special Edition" />
|
|
<meta name="vsauthor" content="Michael Abrash" />
|
|
<meta name="vspublisher" content="The Coriolis Group" />
|
|
<meta name="vspubdate" content="07/01/97" />
|
|
<meta name="vscategory" content="Web and Software Development: Game Development,Web and Software Development: Graphics and Multimedia Development" />
|
|
|
|
<title>Michael Abrash's Graphics Programming Black Book Special Edition: Adding a Dimension</title>
|
|
<meta name="chapter" content="50" />
|
|
<meta name="pages" content="945-946" />
|
|
</head>
|
|
|
|
<body>
|
|
<center>
|
|
<table border="1">
|
|
<tr>
|
|
<td>
|
|
<a href="50-04.html">Previous</a>
|
|
</td>
|
|
|
|
<td>
|
|
<a href="index.html">Table of Contents</a>
|
|
</td>
|
|
|
|
<td>
|
|
<a href="50-06.html">Next</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
<p><b>LISTING 50.4 POLYGON.H</b></p>
|
|
<pre>
|
|
/* POLYGON.H: Header file for polygon-filling code, also includes
|
|
a number of useful items for 3-D animation. */
|
|
|
|
#define MAX_POLY_LENGTH 4 /* four vertices is the max per poly */
|
|
#define SCREEN_WIDTH 320
|
|
#define SCREEN_HEIGHT 240
|
|
#define PAGE0_START_OFFSET 0
|
|
#define PAGE1_START_OFFSET (((long)SCREEN_HEIGHT*SCREEN_WIDTH)/4)
|
|
/* Ratio: distance from viewpoint to projection plane / width of
|
|
projection plane. Defines the width of the field of view. Lower
|
|
absolute values = wider fields of view; higher values = narrower */
|
|
#define PROJECTION_RATIO -2.0 /* negative because visible Z
|
|
coordinates are negative */
|
|
/* Draws the polygon described by the point list PointList in color
|
|
Color with all vertices offset by (X,Y) */
|
|
#define DRAW_POLYGON(PointList,NumPoints,Color,X,Y) \
|
|
Polygon.Length = NumPoints; \
|
|
Polygon.PointPtr = PointList; \
|
|
FillConvexPolygon(&Polygon, Color, X, Y);
|
|
|
|
/* Describes a single 2-D point */
|
|
struct Point {
|
|
int X; /* X coordinate */
|
|
int Y; /* Y coordinate */
|
|
};
|
|
/* Describes a single 3-D point in homogeneous coordinates */
|
|
struct Point3 {
|
|
double X; /* X coordinate */
|
|
double Y; /* Y coordinate */
|
|
double Z; /* Z coordinate */
|
|
double W;
|
|
};
|
|
/* Describes a series of points (used to store a list of vertices that
|
|
describe a polygon; each vertex is assumed to connect to the two
|
|
adjacent vertices, and the last vertex is assumed to connect to the
|
|
first) */
|
|
struct PointListHeader {
|
|
int Length; /* # of points */
|
|
struct Point * PointPtr; /* pointer to list of points */
|
|
};
|
|
|
|
/* Describes the beginning and ending X coordinates of a single
|
|
horizontal line */
|
|
struct HLine {
|
|
int XStart; /* X coordinate of leftmost pixel in line */
|
|
int XEnd; /* X coordinate of rightmost pixel in line */
|
|
};
|
|
|
|
/* Describes a Length-long series of horizontal lines, all assumed to
|
|
be on contiguous scan lines starting at YStart and proceeding
|
|
downward (used to describe a scan-converted polygon to the
|
|
low-level hardware-dependent drawing code) */
|
|
struct HLineList {
|
|
int Length; /* # of horizontal lines */
|
|
int YStart; /* Y coordinate of topmost line */
|
|
struct HLine * HLinePtr; /* pointer to list of horz lines */
|
|
};
|
|
struct Rect { int Left, Top, Right, Bottom; };
|
|
|
|
extern void XformVec(double Xform[4][4], double * SourceVec,
|
|
double * DestVec);
|
|
extern void ConcatXforms(double SourceXform1[4][4],
|
|
double SourceXform2[4][4], double DestXform[4][4]);
|
|
extern void XformAndProjectPoly(double Xform[4][4],
|
|
struct Point3 * Poly, int PolyLength, int Color);
|
|
extern int FillConvexPolygon(struct PointListHeader *, int, int, int);
|
|
extern void Set320x240Mode(void);
|
|
extern void ShowPage(unsigned int StartOffset);
|
|
extern void FillRectangleX(int StartX, int StartY, int EndX,
|
|
int EndY, unsigned int PageBase, int Color);
|
|
extern int DisplayedPage, NonDisplayedPage;
|
|
extern struct Rect EraseRect[];
|
|
</pre>
|
|
|
|
<center>
|
|
<table border="1">
|
|
<tr>
|
|
<td>
|
|
<a href="50-04.html">Previous</a>
|
|
</td>
|
|
|
|
<td>
|
|
<a href="index.html">Table of Contents</a>
|
|
</td>
|
|
|
|
<td>
|
|
<a href="50-06.html">Next</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
<hr width="90%" size="1" noshade="noshade" />
|
|
|
|
<div align="center">
|
|
Graphics Programming Black Book © 2001 Michael Abrash
|
|
</div>
|
|
</body>
|
|
</html>
|