home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2214 / rt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  7.7 KB  |  305 lines

  1. /*
  2.  * rt.h - General information file for rt
  3.  * 
  4.  * Copyright (C) 1990, Kory Hamzeh
  5.  */
  6.  
  7. /*
  8.  * Define some stuff
  9.  */
  10.  
  11. #define    MAX_LIGHTS    8    /* maximum number of light sources */
  12. #define    MAX_PRIMS    80000    /* maximum number of primitives     */
  13. #define MAX_INSTANCE    64    /* maximum number of instances       */
  14. #define MAX_TOKENS    17
  15. #define MIN_T        1e-12
  16. #define MAX_LEVEL    5    /* maxmimum recursion level       */
  17. #define GROUP_SIZE    4
  18. #define STACK_SIZE    512
  19.  
  20. /*
  21.  * Object types
  22.  */
  23.  
  24. #define T_COMPOSITE    0
  25. #define T_POLYGON    1
  26. #define    T_SPHERE    2
  27. #define T_HSPHERE    3
  28. #define T_CONE        4
  29. #define T_RING        5
  30. #define T_QUADRIC    6
  31.  
  32. /*
  33.  * Instance type flags
  34.  */
  35.  
  36. #define I_OBJECT    0    /* object type             */
  37. #define I_SURFACE    1    /* surface properties         */
  38. #define I_LIGHT        2    /* light sources         */
  39.  
  40. /*
  41.  * Structures
  42.  */
  43.  
  44. /* vector */
  45.  
  46. typedef struct vector
  47. {
  48.     double          x;
  49.     double          y;
  50.     double          z;
  51. }               VECTOR;
  52.  
  53.  
  54. /* color pixel info */
  55.  
  56. typedef struct color
  57. {
  58.     double          r;
  59.     double          g;
  60.     double          b;
  61. }               COLOR;
  62.  
  63. /* surface properties */
  64.  
  65. typedef struct surface
  66. {
  67.     double          p_reflect;    /* percentage of reflection     */
  68.     double          p_refract;    /* percentage of refraction     */
  69.     COLOR           c_reflect;    /* reflect color         */
  70.     COLOR           c_refract;    /* refract color         */
  71.     COLOR           c_ambient;    /* ambient color         */
  72.     COLOR           c_diffuse;    /* diffues color         */
  73.     COLOR           c_specular;    /* specular color         */
  74.     double          spec_width;    /* specular width factor     */
  75.     double          i_refraction;    /* index of refraction         */
  76.     double          refl_diffuse;    /* circle of diffusion in refl.     */
  77.     double          refr_diffuse;    /* circle of diffusion in refr.     */
  78. }               SURFACE;
  79.  
  80. /* composite (slab) data */
  81.  
  82. typedef struct composite
  83. {
  84.     int             num;    /* number of object in this group */
  85.     struct object  *child[GROUP_SIZE];    /* pointer to members         */
  86. }               COMPOSITE;
  87.  
  88. /* n-point polygon */
  89.  
  90. typedef struct polygon
  91. {
  92.     int             npoints;/* number of points         */
  93.     VECTOR          normal;    /* surface normal (normalized)     */
  94.     double          d;    /* the D coefficient         */
  95.     int             p1, p2;    /* the dominant normals         */
  96.     VECTOR          points[1];    /* actual points         */
  97. }               POLYGON;
  98.  
  99.  
  100. /* sphere */
  101.  
  102. typedef struct sphere
  103. {
  104.     VECTOR          center;    /* center of sphere         */
  105.     double          radius;    /* and its radius         */
  106.     double          radius2;/* radius * radius         */
  107. }               SPHERE;
  108.  
  109. /* hallow sphere */
  110.  
  111. typedef struct hsphere
  112. {
  113.     VECTOR          center;    /* center of sphere         */
  114.     double          radius;    /* and its radius         */
  115.     double          radius2;/* radius * radius         */
  116.     double          i_radius;    /* inner_radius = outer - tickness */
  117.     double          i_radius2;    /* i_radius * i_radius         */
  118. }               HSPHERE;
  119.  
  120.  
  121. /* cone */
  122.  
  123. typedef struct cone
  124. {
  125.     VECTOR          base;    /* center of base         */
  126.     double          base_radius;    /* base radius             */
  127.     double          base_d;    /* base D coefficient         */
  128.     VECTOR          apex;    /* center of apex         */
  129.     double          apex_radius;    /* apex radius             */
  130.     VECTOR          u;
  131.     VECTOR          v;
  132.     VECTOR          w;
  133.     double          height;    /* apex - base             */
  134.     double          slope;    /* slope of the damn thing     */
  135.     double          min_d;
  136.     double          max_d;
  137. }               CONE;
  138.  
  139. /* ring */
  140.  
  141. typedef struct ring
  142. {
  143.     VECTOR          center;    /* center of ring         */
  144.     VECTOR          point1;    /* one point on surface         */
  145.     VECTOR          point2;    /* another point on surface     */
  146.     VECTOR          normal;    /* surface normal         */
  147.     double          d;    /* the D coefficient         */
  148.     double          o_radius;    /* outer radius             */
  149.     double          i_radius;    /* inner radius             */
  150.     double          o_radius2;    /* o_radius * o_radius         */
  151.     double          i_radius2;    /* i_radius * i_radius         */
  152. }               RING;
  153.  
  154. /*
  155.  * General form quadratic data type.
  156.  */
  157.  
  158. typedef struct quadric
  159. {
  160.     VECTOR          loc;    /* location of the quadratic     */
  161.     VECTOR          min;    /* minumum extent         */
  162.     VECTOR          max;    /* maximum extent         */
  163.     double          a, b, c, d, e;    /* coefficients a to J follow     */
  164.     double          f, g, h, i, j;
  165.     double          a2, b2, c2, d2;    /* a2 = A * 2, etc...         */
  166.     double          f2, g2, i2;
  167. }               QUADRIC;
  168.  
  169. /*
  170.  * The OBJECT data type is built from all of the previous types.
  171.  */
  172.  
  173. typedef struct object
  174. {
  175.     int             type;    /* T_* goes here         */
  176.     void           *obj;    /* actually point to type CONE, etc. */
  177.     VECTOR          b_min;    /* bounding box in values     */
  178.     VECTOR          b_max;    /* bounding box max values     */
  179.     int             active;    /* TRUE if on active hit list     */
  180.     SURFACE        *surf;    /* object surface properties     */
  181.     int             (*inter) ();    /* pointer to intersect routine  */
  182.     int             (*normal) ();    /* pointer to normal routine     */
  183. }               OBJECT;
  184.  
  185. /*
  186.  * This data type contains info about object intersection
  187.  */
  188.  
  189. typedef struct intersect
  190. {
  191.     OBJECT         *obj;    /* object that caused the intersect */
  192.     double          t;    /* distance                 */
  193.     int             inside;    /* 1 = ray is inside object         */
  194. }               INTERSECT;
  195.  
  196. /*
  197.  * This date type conatins info about the image and observer.
  198.  */
  199.  
  200. typedef struct view_info
  201. {
  202.     VECTOR          from;    /* observer's location             */
  203.     VECTOR          look_at;/* looking at here         */
  204.     VECTOR          up;    /* which way is up?         */
  205.     double          angle;    /* field of view         */
  206.     int             x_res;    /* x resolution             */
  207.     int             y_res;    /* y res             */
  208. }               VIEW_INFO;
  209.  
  210. /*
  211.  * This data type contains info about background colors and cueing.
  212.  */
  213.  
  214. typedef struct background
  215. {
  216.     COLOR           col;
  217.     char            cue;
  218. }               BACKGROUND;
  219.  
  220. /*
  221.  * This data type contains info about lights.
  222.  */
  223.  
  224. typedef struct light
  225. {
  226.     VECTOR          pos;    /* light position         */
  227.     COLOR           col;    /* color of light         */
  228.     double          intensity;    /* light intensity         */
  229.     OBJECT         *cache[MAX_LEVEL];    /* shadow cache             */
  230. }               LIGHT;
  231.  
  232. /*
  233.  * This data type contains info about rays.
  234.  */
  235.  
  236. typedef struct ray
  237. {
  238.     VECTOR          pos;    /* ray origin             */
  239.     VECTOR          dir;    /* ray direction         */
  240. }               RAY;
  241.  
  242. /*
  243.  * Instance info holder
  244.  */
  245.  
  246. typedef struct instance
  247. {
  248.     char           *name;    /* name of instance         */
  249.     void           *next;    /* next object pointer         */
  250.     void           *data;    /* points to object data     */
  251.     int             type;    /* I_* type             */
  252.     int             subtype;/* T_* type             */
  253. }               INSTANCE;
  254.  
  255. /* vector math stuff */
  256.  
  257. #define MakeVector(x, y, z, v)        (v).x=(x),(v).y=(y),(v).z=(z)
  258.  
  259. #define VecNegate(a)            {(a).x=0-(a).x;\
  260.                     (a).y=0-(a).y;\
  261.                     (a).z=0-(a).z;}
  262.  
  263. #define VecDot(a,b)            ((a).x*(b).x+(a).y*(b).y+(a).z*(b).z)
  264.  
  265. #define VecLen(a)            (sqrt(VecDot(a,a)))
  266.  
  267. #define VecCopy(a,b)             {(b).x=(a).x;(b).y=(a).y;(b).z=(a).z;}
  268.  
  269. #define VecAdd(a,b,c)             {(c).x=(a).x+(b).x;\
  270.                      (c).y=(a).y+(b).y;\
  271.                      (c).z=(a).z+(b).z;}
  272.  
  273. #define VecSub(a,b,c)             {(c).x=(a).x-(b).x;\
  274.                      (c).y=(a).y-(b).y;\
  275.                      (c).z=(a).z-(b).z;}
  276.  
  277. #define VecComb(A,a,B,b,c)        {(c).x=(A)*(a).x+(B)*(b).x;\
  278.                     (c).y=(A)*(a).y+(B)*(b).y;\
  279.                      (c).z=(A)*(a).z+(B)*(b).z;}
  280.  
  281. #define VecAddS(A,a,b,c)         {(c).x=(A)*(a).x+(b).x;\
  282.                      (c).y=(A)*(a).y+(b).y;\
  283.                      (c).z=(A)*(a).z+(b).z;}
  284.  
  285. #define VecSProd(A,a,b)             {(b).x=(A)*(a).x;\
  286.                      (b).y=(A)*(a).y;\
  287.                      (b).z=(A)*(a).z;}
  288.  
  289. #define VecCross(a,b,c)             {(c).x=(a).y*(b).z-(a).z*(b).y;\
  290.                      (c).y=(a).z*(b).x-(a).x*(b).z;\
  291.                      (c).z=(a).x*(b).y-(a).y*(b).x;};
  292.  
  293. #define MIN(a, b)            ((a) < (b) ? (a) : (b))
  294. #define MAX(a, b)            ((a) > (b) ? (a) : (b))
  295.  
  296. double          VecNormalize();
  297. OBJECT         *Pop_object();
  298.  
  299. /*
  300.  * This macro returns a random number between 0 and 1.0. It probably is not
  301.  * portable!!
  302.  */
  303.  
  304. #define RAND()                ((double) rand() / 32767.0)
  305.