home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter51 / polygon.h < prev   
C/C++ Source or Header  |  1997-06-18  |  4KB  |  90 lines

  1. /* POLYGON.H: Header file for polygon-filling code, also includes a number of 
  2. useful items for 3D animation. */
  3.  
  4. #define MAX_POLY_LENGTH 4  /* four vertices is the max per poly */
  5. #define SCREEN_WIDTH 320
  6. #define SCREEN_HEIGHT 240
  7. #define PAGE0_START_OFFSET 0
  8. #define PAGE1_START_OFFSET (((long)SCREEN_HEIGHT*SCREEN_WIDTH)/4)
  9. /* Ratio: distance from viewpoint to projection plane / width of projection 
  10. plane. Defines the width of the field of view. Lower absolute values = wider 
  11. fields of view; higher values = narrower */
  12. #define PROJECTION_RATIO   -2.0 /* negative because visible Z
  13.                                    coordinates are negative */
  14. /* Draws the polygon described by the point list PointList in color Color with 
  15. all vertices offset by (X,Y) */
  16. #define DRAW_POLYGON(PointList,NumPoints,Color,X,Y)          \
  17.    Polygon.Length = NumPoints; Polygon.PointPtr = PointList; \
  18.    FillConvexPolygon(&Polygon, Color, X, Y);
  19.  
  20. /* Describes a single 2D point */
  21. struct Point {
  22.    int X;   /* X coordinate */
  23.    int Y;   /* Y coordinate */
  24. };
  25. /* Describes a single 3D point in homogeneous coordinates */
  26. struct Point3 {
  27.    double X;   /* X coordinate */
  28.    double Y;   /* Y coordinate */
  29.    double Z;   /* Z coordinate */
  30.    double W;
  31. };
  32. /* Describes a series of points (used to store a list of vertices that 
  33. describe a polygon; each vertex is assumed to connect to the two adjacent 
  34. vertices, and the last vertex is assumed to connect to the first) */
  35. struct PointListHeader {
  36.    int Length;                /* # of points */
  37.    struct Point * PointPtr;   /* pointer to list of points */
  38. };
  39. /* Describes beginning and ending X coordinates of a single horizontal line */
  40. struct HLine {
  41.    int XStart; /* X coordinate of leftmost pixel in line */
  42.    int XEnd;   /* X coordinate of rightmost pixel in line */
  43. };
  44. /* Describes a Length-long series of horizontal lines, all assumed to be on 
  45. contiguous scan lines starting at YStart and proceeding downward (describes
  46. a scan-converted polygon to low-level hardware-dependent drawing code) */
  47. struct HLineList {
  48.    int Length;                /* # of horizontal lines */
  49.    int YStart;                /* Y coordinate of topmost line */
  50.    struct HLine * HLinePtr;   /* pointer to list of horz lines */
  51. };
  52. struct Rect { int Left, Top, Right, Bottom; };
  53. /* Structure describing one face of an object (one polygon) */
  54. struct Face {
  55.    int * VertNums;   /* pointer to vertex ptrs */
  56.    int NumVerts;     /* # of vertices */
  57.    int Color;        /* polygon color */
  58. };
  59. /* Structure describing an object */
  60. struct Object {
  61.    int NumVerts;
  62.    struct Point3 * VertexList;
  63.    struct Point3 * XformedVertexList;
  64.    struct Point3 * ProjectedVertexList;
  65.    struct Point * ScreenVertexList;
  66.    int NumFaces;
  67.    struct Face * FaceList;
  68. };
  69.  
  70. extern void XformVec(double Xform[4][4], double * SourceVec,
  71.    double * DestVec);
  72. extern void ConcatXforms(double SourceXform1[4][4],
  73.    double SourceXform2[4][4], double DestXform[4][4]);
  74. extern void XformAndProjectPoly(double Xform[4][4],
  75.    struct Point3 * Poly, int PolyLength, int Color);
  76. extern int FillConvexPolygon(struct PointListHeader *, int, int, int);
  77. extern void Set320x240Mode(void);
  78. extern void ShowPage(unsigned int StartOffset);
  79. extern void FillRectangleX(int StartX, int StartY, int EndX,
  80.    int EndY, unsigned int PageBase, int Color);
  81. extern void XformAndProjectPoints(double Xform[4][4],
  82.    struct Object * ObjectToXform);
  83. extern void DrawVisibleFaces(struct Object * ObjectToXform);
  84. extern void AppendRotationX(double XformToChange[4][4], double Angle);
  85. extern void AppendRotationY(double XformToChange[4][4], double Angle);
  86. extern void AppendRotationZ(double XformToChange[4][4], double Angle);
  87. extern int DisplayedPage, NonDisplayedPage;
  88. extern struct Rect EraseRect[];
  89.  
  90.