home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / XSHP15.ZIP / POLYGON.H < prev    next >
Text File  |  1991-12-26  |  6KB  |  108 lines

  1. /* POLYGON.H: Header file for polygon-filling code, also includes
  2.    a number of useful items for 3D animation. */
  3. #define MAX_OBJECTS  100   /* max simultaneous # objects supported */
  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. #define NUM_CUBE_VERTS 8              /* # of vertices per cube */
  10. #define NUM_CUBE_FACES 6              /* # of faces per cube */
  11. /* Ratio: distance from viewpoint to projection plane / width of
  12.    projection plane. Defines the width of the field of view. Lower
  13.    absolute values = wider fields of view; higher values = narrower */
  14. #define PROJECTION_RATIO -2.0 /* negative because visible Z
  15.                                  coordinates are negative */
  16. /* Draws the polygon described by the point list PointList in color
  17.    Color with all vertices offset by (X,Y) */
  18. #define DRAW_POLYGON(PointList,NumPoints,Color,X,Y)          \
  19.    Polygon.Length = NumPoints; Polygon.PointPtr = PointList; \
  20.    FillConvexPolygon(&Polygon, Color, X, Y);
  21. #define INT_TO_FIXED(x) (((long)(int)x) << 16)
  22. #define DOUBLE_TO_FIXED(x) ((long) (x * 65536.0 + 0.5))
  23.  
  24. typedef long Fixedpoint;
  25. typedef unsigned int TAngle;  /* angle in tenths of degrees */
  26. typedef Fixedpoint Xform[3][4];
  27. /* Describes a single 2D point */
  28. typedef struct _Point { int X; int Y; } Point;
  29. /* Describes a single 3D point in homogeneous coordinates; the W
  30.    coordinate isn't present, though; assumed to be 1 and implied */
  31. typedef struct _Point3 { Fixedpoint X, Y, Z; } Point3;
  32. typedef struct { int X; int Y; int Z; } IntPoint3;
  33. /* Describes a series of points (used to store a list of vertices that
  34.    describe a polygon; each vertex is assumed to connect to the two
  35.    adjacent vertices; last vertex is assumed to connect to first) */
  36. typedef struct { int Length; Point * PointPtr; } PointListHeader;
  37. /* Describes the beginning and ending X coordinates of a single
  38.    horizontal line */
  39. typedef struct { int XStart; int XEnd; } HLine;
  40. /* Describes a Length-long series of horizontal lines, all assumed to
  41.    be on contiguous scan lines starting at YStart and proceeding
  42.    downward (used to describe a scan-converted polygon to the
  43.    low-level hardware-dependent drawing code) */
  44. typedef struct { int Length; int YStart; HLine * HLinePtr;} HLineList;
  45. typedef struct { int Left, Top, Right, Bottom; } Rect;
  46. /* Structure describing one face of an object (one polygon) */
  47. typedef struct { int * VertNums; int NumVerts; int Color; }  Face;
  48. typedef struct { TAngle RotateX, RotateY, RotateZ; } RotateControl;
  49. typedef struct { Fixedpoint MoveX, MoveY, MoveZ, MinX, MinY, MinZ,
  50.    MaxX, MaxY, MaxZ; } MoveControl;
  51. /* Fields common to every object */
  52. #define BASE_OBJECT                                              \
  53.    struct _Object *NextObject;                                   \
  54.    struct _Object *PreviousObject;                               \
  55.    Point3 CenterInView;    /* coord of center in view space */   \
  56.    void (*DrawFunc)();     /* draws object */                    \
  57.    void (*RecalcFunc)();   /* prepares object for drawing */     \
  58.    void (*MoveFunc)();     /* moves object */                    \
  59.    int RecalcXform;        /* 1 to indicate need to recalc */    \
  60.    Rect EraseRect[2];      /* rectangle to erase in each page */
  61. /* Basic object */
  62. typedef struct _Object { BASE_OBJECT } Object;
  63. /* Structure describing a polygon-based object */
  64. typedef struct {
  65.    BASE_OBJECT
  66.    int RDelayCount, RDelayCountBase; /* controls rotation speed */
  67.    int MDelayCount, MDelayCountBase; /* controls movement speed */
  68.    Xform XformToWorld;        /* transform from object->world space */
  69.    Xform XformToView;         /* transform from object->view space */
  70.    RotateControl Rotate;      /* controls rotation change over time */
  71.    MoveControl Move;          /* controls object movement over time */
  72.    int NumVerts;              /* # vertices in VertexList */
  73.    Point3 * VertexList;       /* untransformed vertices */
  74.    Point3 * XformedVertexList;   /* transformed into view space */
  75.    Point3 * ProjectedVertexList; /* projected into screen space */
  76.    Point * ScreenVertexList;     /* converted to screen coordinates */
  77.    int NumFaces;              /* # of faces in object */
  78.    Face * FaceList;           /* pointer to face info */
  79. } PObject;
  80.  
  81. extern void XformVec(Xform, Fixedpoint *, Fixedpoint *);
  82. extern void ConcatXforms(Xform, Xform, Xform);
  83. extern int FillConvexPolygon(PointListHeader *, int, int, int);
  84. extern void Set320x240Mode(void);
  85. extern void ShowPage(unsigned int);
  86. extern void FillRectangleX(int, int, int, int, unsigned int, int);
  87. extern void XformAndProjectPObject(PObject *);
  88. extern void DrawPObject(PObject *);
  89. extern void AppendRotationX(Xform, TAngle);
  90. extern void AppendRotationY(Xform, TAngle);
  91. extern void AppendRotationZ(Xform, TAngle);
  92. extern near Fixedpoint FixedMul(Fixedpoint, Fixedpoint);
  93. extern near Fixedpoint FixedDiv(Fixedpoint, Fixedpoint);
  94. extern void InitializeFixedPoint(void);
  95. extern void RotateAndMovePObject(PObject *);
  96. extern void InitializeCubes(void);
  97. extern void InitializeBalls(void);
  98. extern int DisplayedPage, NonDisplayedPage, RecalcAllXforms;
  99. extern int NumObjects;
  100. extern Object ObjectListStart, ObjectListEnd;
  101. extern Xform WorldViewXform;
  102. extern Object *ObjectList[];
  103. extern Point3 CubeVerts[];
  104. extern void CosSin(TAngle, Fixedpoint *, Fixedpoint *);
  105. extern void AddObject(Object *);
  106. extern void SortObjects(void);
  107. extern void InitializeObjectList(void);
  108.