home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / graphic / qrt / qrt.h < prev    next >
C/C++ Source or Header  |  1989-03-26  |  11KB  |  378 lines

  1. /**********************************************************
  2.  
  3.  
  4.              Header file for Quick Ray Trace
  5.  
  6.                      Steve Koren
  7.  
  8.  **********************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <math.h>
  12.  
  13. #define TRUE  1
  14. #define FALSE 0
  15.  
  16. #define BOOL short
  17.  
  18.  
  19. /**********************************************************
  20.  
  21.                      MACHINE TYPES
  22.  
  23.  **********************************************************/
  24.  
  25. #undef  AMIGA
  26. #undef  MAC_II
  27. #undef  ATARI_ST
  28. #define UNIX             TRUE
  29. #undef  IBM_OR_CLONE
  30. #undef  OS_2
  31. #undef  XENIX
  32. #undef  VMS
  33.  
  34.  
  35. /**********************************************************
  36.  
  37.                    MISC MATH CONSTANTS
  38.  
  39.  **********************************************************/
  40.  
  41. #define PI  3.141592
  42. #define PI2 1.570796
  43.  
  44.  
  45. /**********************************************************
  46.  
  47.                      OBJECT  NUMBERS
  48.  
  49.  **********************************************************/
  50.  
  51. #define LINE               1
  52. #define SPHERE             2
  53. #define PARALLELOGRAM      3
  54. #define TRIANGLE           4
  55. #define LAMP               5
  56. #define OBSERVER           6
  57. #define GROUND             7
  58. #define SKY                8
  59. #define BBOX               9
  60. #define RING               10
  61. #define QUADRATIC          11
  62.  
  63.  
  64. /**********************************************************
  65.  
  66.                    PROGRAM CONSTANTS
  67.  
  68.  **********************************************************/
  69.  
  70. #define SMALL    1.0e-3      /* a sorta small number    */
  71. #define BIG      1.0e15      /* a sorta big number      */
  72. #define CNUM     100         /* this many shades/color  */
  73. #define SLEN     64          /* max string length       */
  74. #define MAX_IX   4           /* maximum x interpolation */
  75. #define MAX_IY   4           /* maximum y interpolation */
  76. #define MAX_XRES 2500        /* maximum X resolution    */
  77. #define XYZZY    42          /* this is here for no     */
  78.                              /* reason whatsoever       */
  79.  
  80.  
  81. /**********************************************************
  82.  
  83.                       VECTOR STRUCTURES
  84.  
  85.  **********************************************************/
  86.  
  87. typedef struct vector {        /* a vector in 3 space   */
  88.   float x,y,z;
  89. } VECTOR, *VECT_PTR;
  90.  
  91. typedef struct svector {       /* an r,g,b color vector */
  92.   short r,g,b;
  93. } SVECTOR, *SVECT_PTR;
  94.  
  95. typedef struct cinfo_struct {  /* color information     */
  96.  
  97.   SVECTOR       amb,           /* ambient lighting      */
  98.                 diff,          /* diffuse lighting      */
  99.                 mirror,        /* % light reflected     */
  100.                 trans;         /* % light transmitted   */
  101.  
  102.   VECTOR        density;       /* density */
  103.  
  104.   float         sreflect,      /* specular refl coefficient */
  105.                 index;         /* index if refraction */
  106.  
  107.   short         fuzz,          /* currently unused */
  108.                 reflect,       /* percent specularly reflected */
  109.                 dither;        /* color dithering. 3..6 look ok */
  110.  
  111. } CINFO, *CINFO_PTR;
  112.  
  113.  
  114. /**********************************************************
  115.  
  116.                 PRECOMPUTED INFO FOR OBJECTS
  117.  
  118.  These fields can be used by object routines however
  119.  they wish.  They just make object/line intersections
  120.  faster.
  121.  
  122.  **********************************************************/
  123.  
  124. typedef struct _pre {
  125.  
  126.   float    sin1, cos1,         /* sin and cos */
  127.            sin2, cos2,
  128.            n1,                 /* misc number */
  129.            len1, len2;         /* lengths of vectors */
  130.  
  131.   VECTOR   vect1,              /* misc vector */
  132.            norm;               /* norm for planar objs */
  133.  
  134. } PRECOMP, PRECOMP_PTR;
  135.  
  136.  
  137. /**********************************************************
  138.  
  139.                       PATTERN STRUCTURE
  140.  
  141.  **********************************************************/
  142.  
  143. typedef struct patt {
  144.   short    type;               /* type of pattern */
  145.   float    xsize,              /* pattern size */
  146.            ysize,
  147.            startx,
  148.            starty,             /* x,y positions */
  149.            endx,
  150.            endy,
  151.            radius;             /* rad for circles */
  152.  
  153.   CINFO    cinfo;              /* color information */
  154.  
  155.   char     *name;              /* pattern name */
  156.  
  157.   struct patt *child, *sibling, *link;
  158.  
  159. } PATTERN, *PATTERN_PTR;
  160.  
  161.  
  162. /**********************************************************
  163.  
  164.                     OBJECT STRUCTURE
  165.  
  166.  **********************************************************/
  167.  
  168. typedef struct obj_struct {
  169.  
  170.   short         type,         /* object type */
  171.                 flag;         /* misc boolean flag */
  172.  
  173.   char          *name;        /* object name */
  174.  
  175.   VECTOR        loc,          /* object location */
  176.                 vect1,        /* three vectors */
  177.                 vect2,
  178.                 vect3,
  179.                 lower,        /* lower and upper bounds */
  180.                 upper;
  181.  
  182.   float         cterm,        /* for quadratic surfaces only */
  183.                 xmult,        /* x and y multipliers for patterns */
  184.                 ymult;
  185.  
  186.   CINFO         cinfo;        /* color information */
  187.  
  188.   PRECOMP       precomp;      /* precomputed information */
  189.  
  190.   struct obj_struct *nextobj, /* next obj in list */
  191.                     *child;   /* child for bounding boxes only */
  192.  
  193.   PATTERN_PTR   pattern,      /* pointer to pattern structure */
  194.                 remove;       /* remove section of object */
  195.  
  196. } OBJ_STRUCT, *OBJ_PTR;
  197.  
  198.  
  199. /**********************************************************
  200.  
  201.                    Plane Bbox structure
  202.  
  203.  **********************************************************/
  204.  
  205. typedef struct _PlaneBox {
  206.   int      min_x, min_y,
  207.            max_x, max_y;
  208.  
  209.   OBJ_PTR  object;
  210.  
  211.   struct _PlaneBox *next;
  212. } PLANE_BBOX, *PLANE_BBOX_PTR;
  213.  
  214.  
  215. /**********************************************************
  216.  
  217.                        WORLD STRUCTURE
  218.  
  219.  **********************************************************/
  220.  
  221. typedef struct world {
  222.   OBJ_PTR   stack,            /* here are the objects */
  223.             observer,         /* the observer */
  224.             sky,              /* sky */
  225.             lamps,            /* a lamp list */
  226.             instances;        /* instance list */
  227.  
  228.   int       objcount,         /* # objects and lamps */
  229.             lampcount;
  230.  
  231.   long      ray_intersects,   /* statistics */
  232.             primary_traced,
  233.             to_lamp,
  234.             refl_trans,
  235.             bbox_intersects,
  236.             intersect_tests,
  237.             pixels_hit,
  238.             pattern_matches;
  239.  
  240.   VECTOR    obsright,         /* obs up dir */
  241.             obsup;
  242.  
  243.   SVECTOR   skycolor_horiz,   /* skycolors */
  244.             skycolor_zenith;
  245.  
  246.   PATTERN_PTR patlist;        /* the pattern stack */
  247.  
  248.   float     flength,          /* focal length */
  249.             x_divisor,        /* used to find ray direction */
  250.             y_divisor,
  251.             globindex;        /* global index of refraction */
  252.  
  253.   char      *outfile;         /* output file name */
  254.   FILE      *filept;          /* output file pointer */
  255. } WORLD;
  256.  
  257.  
  258. /**********************************************************
  259.  
  260.                   FUNCTIONS FOR OBJECT TYPES
  261.  
  262.  **********************************************************/
  263.  
  264. typedef struct obj_data {
  265.   int (*ColTest)();           /* collision test function ptr */
  266.   int (*FindNorm)();          /* normal finding function ptr */
  267.   int (*FindBbox)();          /* object bound function ptr   */
  268.   int (*RelPos)();            /* object relative position    */
  269.   int (*PreComp)();           /* info pre-computing routine  */
  270.   int (*Offset)();            /* offset object by dx, dy, dz */
  271.   int (*Resize)();            /* resize object by a multiple */
  272. } OBJ_DATA;
  273.  
  274.  
  275. /**********************************************************
  276.  
  277.                       MATH DEFINES
  278.  
  279.  **********************************************************/
  280.  
  281. #define sqr(x) ((x)*(x))
  282. #define DotProd(v1,v2) (v1.x*v2.x+v1.y*v2.y+v1.z*v2.z)
  283. #define MIN(x,y) ((x)<(y) ? (x) : (y))
  284. #define MAX(x,y) ((x)>(y) ? (x) : (y))
  285. #define IABS(x)  ((x)>0   ? (x) : (-(x)))
  286.  
  287.  
  288. /**********************************************************
  289.  
  290.                       Default structure
  291.  
  292.  **********************************************************/
  293.  
  294. typedef struct def_struct {
  295.  
  296.   CINFO cinfo;             /* default colorinfo */
  297.  
  298.   short shadow,            /* shadows ? */
  299.         vlamp,             /* lamps visible (not yet implimented) */
  300.         int_x,             /* interpolate (def=1) */
  301.         int_y,
  302.  
  303.         x_res,             /* X resolution of image */
  304.         y_res,             /* Y resolution of image */
  305.         x_center,          /* X center of image */
  306.         y_center;          /* Y center of image */
  307.  
  308.   float threshold,         /* cutoff pt for min refl, refl rays */
  309.         aspect;            /* aspect ratio for image            */
  310.  
  311.  
  312.   short ithreshold;        /* integer version of above          */
  313.  
  314. } DEF, *DEF_PTR;
  315.  
  316.  
  317. /**********************************************************
  318.  
  319.                      EXTERNAL DECLARATIONS
  320.  
  321.  **********************************************************/
  322.  
  323. extern DEF def;
  324.  
  325. extern OBJ_DATA ObjData[];
  326.  
  327. extern WORLD THEWORLD;
  328.  
  329.  
  330. /**********************************************************
  331.  
  332.                        ERROR CODES
  333.  
  334.  **********************************************************/
  335.  
  336. #define ILLEGAL_PARAMETER 1
  337. #define TOO_FEW_PARMS     2
  338. #define ILLEGAL_OBJECT    3
  339. #define MALLOC_FAILURE    4
  340. #define SYNTAX_ERROR      5
  341. #define INTERNAL_ERROR    6
  342. #define FILE_ERROR        7
  343. #define PATTERN_NOT_FOUND 8
  344. #define PATTERN_EXISTS    9
  345. #define NO_OBSERVER       10
  346. #define UNDEFINED_PARAM   11
  347. #define NON_HOMOGENIOUS   12
  348. #define ZERO_INDEX        13
  349. #define COLOR_VALUE_ERR   14
  350. #define LESS_THAN_ZERO    15
  351. #define ZERO_MULTIPLIER   16
  352. #define UNDEFINED_NAME    17
  353. #define LPAREN_EXPECTED   18
  354. #define RPAREN_EXPECTED   19
  355. #define ILLEGAL_VECTOR    20
  356. #define ILLEGAL_SVECTOR   21
  357. #define ILLEGAL_OPTION    22
  358.  
  359.  
  360. /**********************************************************
  361.  
  362.                       WARNING CODES
  363.  
  364.  **********************************************************/
  365.  
  366. #define OBSOLETE_OPTION   1
  367.  
  368.  
  369. /**********************************************************
  370.  
  371.  Define this flag for more robust code (HIGHLY recommended)
  372.  
  373.  **********************************************************/
  374.  
  375. #define ROBUST TRUE
  376.  
  377.  
  378.