home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / prev.tar.gz / prev.tar / art.h next >
C/C++ Source or Header  |  1991-03-20  |  10KB  |  569 lines

  1. /*
  2.  * include file for pixel data
  3.  */
  4. #include "vort.h"
  5. #include "objs.h"
  6. #include "status.h"
  7.  
  8. /*
  9.  * types and defs for the ray tracer
  10.  */
  11.  
  12. #define    TRUE    1
  13. #define    FALSE    0
  14.  
  15. #define    MESLEN    100
  16.  
  17. /*
  18.  * tolerance value used for tolerance calculation also serves
  19.  * as minimum distance we must be from the last surface before
  20.  * we register another hit.
  21.  */
  22. #define    TOLERANCE    0.0001
  23.  
  24. /*
  25.  * basic raddi for bounding spheres used for calculating object
  26.  * tolerance values
  27.  */
  28. #define    BS_SQRT2    1.414213563
  29. #define    BS_SQRT0PNT5    0.707106782
  30. #define    BS_SQRT1PNT25    1.118033990
  31.  
  32. /*
  33.  * where we put infinity
  34.  */
  35. #define    HUGE_DIST    1.0e24
  36.  
  37. typedef float    matrix[4][4];
  38. typedef float    mat3x3[3][3];
  39.  
  40. typedef struct cmplx {
  41.     float    r;
  42.     float    i;
  43. } complex;
  44.  
  45. typedef struct v {
  46.     float    x, y, z;
  47. } vector;
  48.  
  49. typedef struct uvv {
  50.     float    u, v;
  51. } uvvec;
  52.  
  53. typedef struct col {
  54.     float    r, g, b;
  55. } colour;
  56.  
  57. typedef struct pix {
  58.     float    r, g, b, a;
  59. } pixel;
  60.  
  61. typedef struct td {
  62.     vector        trans,
  63.             nscales;
  64.     mat3x3        mat;
  65. } transdata;
  66.  
  67. typedef struct w {
  68.     vector  center;
  69.     float   amp;
  70.     float   len;
  71.     float   phase;
  72.     float   damp;
  73.     struct w        *nxt;
  74. } wlist;
  75.  
  76. /*
  77.  * typedefs for texture, bumps, and tile patterns
  78.  */
  79. typedef struct {
  80.     float        blend;
  81.     int        octaves;    /* range for noise function */
  82.     colour        blendcolour;
  83.     float        var[3];
  84.     unsigned short    pixw, pixh;
  85.     char        *map;
  86. } proctxt;
  87.  
  88. typedef struct {
  89.     float        blend;
  90.     float        scalew, scaleh;
  91.     char        *map;
  92.     unsigned short    pixw, pixh;
  93. } tiletxt;
  94.  
  95. typedef struct t {
  96.     void        (*txtcol)();    /* texturing function */
  97.     union {
  98.         wlist        *w;        /* List of wave sources */
  99.         proctxt        *p;        /* procedural texture stuff */
  100.         tiletxt        *t;        /* tile texture stuff */
  101.     } u;
  102.     transdata    *td;
  103.     struct t    *nxt;
  104. } texture;
  105.     
  106. /*
  107.  * general structure for a surface
  108.  */
  109. typedef struct surf {
  110.     colour    c, a;            /* surface and ambient light colour */
  111.     float    kd, ks;            /* diffuse, specular */
  112.     int    ksexp;            /* specular exponent */
  113.     float    refl,            /* reflection */
  114.         ri,            /* refractive index */
  115.         falloff,        /* falloff in the media */
  116.         trans;            /* transparency */
  117. } surface;
  118.  
  119. #define STACKSIZE    12        /* maximum size of stack structure */
  120.  
  121. /*
  122.  * attribute stack structure
  123.  */
  124. typedef struct at {
  125.     int        options;    /* shading options */
  126.     int        shadows;    /* shadows on or off */
  127.     texture        *txtlist;    /* texturing info */
  128.     surface        *s;        /* surface properties */
  129.     int        slevel;        /* level of most recent suface data */
  130. } attr;
  131.  
  132. /*
  133.  * matrix stack structure
  134.  */
  135. typedef struct mt {
  136.     matrix        ray2obj,    /* ray to object transformation */
  137.             obj2ray;    /* object to ray transformation */
  138.     matrix        om;        /* current object matrix */
  139.     char        omused;        /* was om used at this level? */
  140.     matrix        vm;        /* current viewing matrix */
  141.     char        vmused;        /* was vm used at this level? */
  142.     float        maxscale;    /* maximum scale applied to an object */
  143.     vector        nscales;    /* scaling factors for normals */
  144.     transdata    *td;        /* transformation data */
  145.     int        tdlevel;    /* level of most recent trans data */
  146. } mats;
  147.  
  148. /*
  149.  * shader stack structure
  150.  */
  151. typedef struct st {
  152.     float   ri;
  153.     float   falloff;
  154. } shadedata;
  155.  
  156. /*
  157.  * nodes for storing hit lists
  158.  */
  159.  
  160. #define    ENTRY    1
  161. #define    EXIT    2
  162.  
  163. typedef struct hl {
  164.     float        t;
  165.     struct o    *obj;
  166.     int        type;
  167.     struct hl    *nxt;
  168. } hlist;
  169.  
  170. /*
  171.  * defs for lights
  172.  */
  173. #define    POINT        0
  174. #define    DIRECTIONAL    1
  175. #define    DISTANT        2
  176.  
  177. typedef struct l {
  178.     int        type;
  179.     vector        org;
  180.     vector        dir;
  181.     colour        c;
  182.     float        rad;
  183.     float        cosedge;
  184.     float        cosin;
  185.     float        beamdist;
  186.     int        rays;
  187.     int        shadows;
  188.     struct o        **lasthits;
  189.     struct l    *nxt;
  190. } light;
  191.  
  192. /*
  193.  * the ray structure
  194.  */
  195. typedef struct r {
  196.     short    raynumber;
  197.     float    ri, fallof;
  198.     vector    org, dir;
  199. } ray;
  200.  
  201. /*
  202.  * major axis flags
  203.  */
  204. #define    XAXIS    0
  205. #define    YAXIS    1
  206. #define    ZAXIS    2
  207.  
  208. #define    DIMS    3
  209.  
  210. /*
  211.  * hit types
  212.  */
  213.  
  214. #define    NXFACE    0        /* face faces negative axis */
  215. #define    NYFACE    1
  216. #define    NZFACE    2
  217.  
  218. #define    PXFACE    3        /* face faces positive axis */
  219. #define    PYFACE    4
  220. #define    PZFACE    5
  221.  
  222. #define    SIDE    6        /* side of quadric */
  223.  
  224. /*
  225.  * bounding shapes details
  226.  */
  227.  
  228. typedef struct b {
  229.     float    max[DIMS];
  230.     float    min[DIMS];
  231. } bbox;
  232.  
  233. /*
  234.  * object model definitions
  235.  */
  236.  
  237. typedef struct s {
  238.     float    radsqu;
  239.     vector    orig;
  240. } sphere;
  241.  
  242. typedef struct rg {
  243.     vector    n;
  244.     float    intrad, intradsqu;
  245. } ring;
  246.  
  247. typedef struct to {
  248.     float    cnst;
  249. } torus;
  250.  
  251. typedef struct sq {
  252.     int    ord;
  253. } superquadric;
  254.  
  255. /*
  256.  * typedefs for polygons and polygon models
  257.  */
  258. #define    ART_MAXVERTS    256        /* maximum number of vertices */
  259.  
  260. #define    ART_BACKFACING    0x1        /* backfacing bit */
  261. #define    PHONGSHADING    0x2        /* phong shading bit */
  262.  
  263. typedef struct pgy {
  264.     unsigned char    axis;        /* major axis of normal */
  265.     unsigned short    nsides;        /* number of sides */
  266.     float        cnst;        /* const for the polygon's plane */
  267.     vector        n, on;        /* normal - ray/object space */
  268.     union {
  269.         mat3x3    *mat;        /* 3x3 matrix for triangles */
  270.         uvvec    *verts;        /* vertices in u, v space */
  271.     } u;
  272.     vector        *norms;        /* vertex normals */
  273.     vector        *colours;    /* vertex colours */
  274. } polygon;
  275.  
  276. /*
  277.  * types for organisation of polygons in geometry
  278.  */
  279. typedef unsigned short  vertno;
  280.  
  281. typedef struct fct {
  282.     unsigned char   nsides;        /* number of sides */
  283.     unsigned short    index;        /* generic index */
  284.     vector        n;        /* unnormalised normal */
  285.     float        cnst;        /* const for the faces plane */
  286.     vertno        *vertnos;    /* vertex numbers */
  287.     float        minu, maxu,    /* min max in u value */
  288.             minv, maxv;    /* min max in v value */
  289. } facet;
  290.  
  291. typedef struct gty {
  292.     bbox            bb;             /* bounding box */
  293.     int             options;        /* shading options */
  294.     vector          *pnorms;         /* normals at each polygon */
  295.     vector          *vnorms;        /* normals at each vertex */
  296.     vertno        **vnormtable;    /* table of indexes into norms */
  297.     vector        *colours;    /* colour array */
  298.     unsigned short    *colourtable;    /* indexes into colour array */
  299.     float           *xs, *ys, *zs;  /* x, y, and z values for each vertex */
  300.     facet        *faces;         /* polygon array */
  301.     int             ntris[DIMS];    /* number of triangles in each axis */
  302.     int             npolys[DIMS];   /* number of polygons in each axis */
  303.     facet        *midts[DIMS];   /* middle of triangle array */
  304.     float        midtval[DIMS];  /* smallest minv in top half of tris */
  305.     facet        *midps[DIMS];   /* middle of polygon array */
  306.     float           midpval[DIMS];  /* smallest minv in top half of polys */
  307. } geometry;
  308.              
  309. /*
  310.  * algebraic equation term def and node structure
  311.  */
  312. typedef struct trm {
  313.     double        coef;
  314.     int        type;
  315.     int        xp, yp, zp;
  316.     double        *xcoefs, *ycoefs, *zcoefs;
  317.     struct trm    *nxt;
  318. } term;
  319.  
  320. typedef struct pwl {
  321.     int        pw;
  322.     double        *coefs;
  323.     struct pwl    *nxt;
  324. } pwlist;
  325.  
  326. typedef struct eq {
  327.     int     order;
  328.     int    maxxp, maxyp, maxzp;
  329.     pwlist    *xpws, *ypws, *zpws;
  330.     term    *trmlist,
  331.         *dxlist, *dylist, *dzlist;    /* terms for the partial derivatives */
  332. } eqn;
  333.  
  334.  
  335. /*
  336.  * csg node structure and defs
  337.  */
  338. #define    UNION        1
  339. #define    INTERSECT    2
  340. #define    SUBTRACT    3
  341.  
  342. #define ADDED        1
  343. #define SUBTRACTED    2    /* need to flip normal in this case */
  344.  
  345. typedef struct cs {
  346.     int        rightb, leftb;
  347.     struct o    *hitobj, *left, *right;
  348. } csg;
  349.  
  350. /*
  351.  * the composite object
  352.  */
  353. typedef struct co {
  354.     struct o    *oblist;
  355. } composite;
  356.  
  357. /*
  358.  * expression defs
  359.  */
  360. #define    EXP_FLOAT    1
  361. #define    EXP_INT        2
  362. #define    EXP_VAR        3
  363. #define    EXP_ADD        4
  364. #define    EXP_SUB        5
  365. #define    EXP_MUL        6
  366. #define    EXP_DIV        7
  367. #define    EXP_UMINUS    8
  368.  
  369. typedef struct ex {
  370.     int    type;
  371.     union {
  372.         float        f;
  373.         int        i;
  374.         char        *s;
  375.     } u;
  376. } expression;
  377.  
  378. /*
  379.  * csg tree def
  380.  */
  381.  
  382. typedef struct cn {
  383.     int    type;
  384.     union {
  385.         struct {
  386.             struct cn    *left, *right;
  387.         } branch;
  388.         struct sy    *sym;
  389.     } u;
  390. } csgnode;
  391.  
  392. /*
  393.  * user colourmap for textures
  394.  */
  395. typedef struct m {
  396.     char    *m;
  397.     int    n;
  398. } cmap;
  399.  
  400. /*
  401.  * details to go in objects
  402.  */
  403. typedef struct det {
  404.     int        type;
  405.     union {
  406.         vector        v;
  407.         colour        c;
  408.         float        f;
  409.         int        i;
  410.         term        *t;
  411.         char        *s;
  412.         texture        *txt;
  413.         struct sy    *sym;
  414.         wlist        *w;
  415.         cmap        *cm;
  416.         struct det    *det;
  417.         struct {
  418.             float    ri, kd, ks;
  419.             int    ksexp;
  420.         } mat;
  421.         struct {
  422.             float    ang;
  423.             int    axis;
  424.         } rot;
  425.         struct {
  426.             struct sy    *sym;
  427.             struct det    *det;
  428.         } obj;
  429.         struct {
  430.             csgnode        *tree;
  431.             struct det    *det;
  432.         } csgobj;
  433.         struct {
  434.             expression    *expr;
  435.             struct det    *stmt;
  436.         } rpt;
  437.     } u;
  438.     struct det    *nxt;
  439. } details;
  440.  
  441. /*
  442.  * symbol table structure
  443.  */
  444. typedef struct sy {
  445.     char    *name;
  446.     char    type;
  447.     union {
  448.         float        f;
  449.         int        i;
  450.         details        *det;
  451.         struct {
  452.             geometry    *geom;
  453.             vector        *pnorms;
  454.             vector        *vnorms;
  455.         } geo;
  456.         struct {
  457.             vector    *norms;
  458.             vertno    **ntable;
  459.         } norm;
  460.         struct {
  461.             vector        *colours;
  462.             unsigned short    *colourtable;
  463.         } cols;
  464.         struct {
  465.             unsigned short    width, height;
  466.             char        *pic;
  467.         } tile;
  468.     } u;
  469.     struct sy    *left, *right;
  470. } symbol;
  471.  
  472. /*
  473.  * tree structure
  474.  */
  475. #define    X    0
  476. #define    Y    1
  477. #define    Z    2
  478.  
  479. #define DIMS    3
  480.  
  481. #define    LEAF    4
  482. #define    SPLITABLELEAF    (0x08 | LEAF)
  483.  
  484. #define    SPLITCUTOFF1    40 /* below this value we use a more conservative splitting strategy */
  485. #define    SPLITCUTOFF2    3
  486.  
  487. #define    splittable(a)    ((a)->type & 0x08)
  488.  
  489. typedef struct ol {
  490.     struct o    *obj;
  491.     struct ol    *nxt;
  492. } olist;
  493.  
  494. typedef struct kdt {
  495.     unsigned char    type;
  496.     float        splitval;
  497.     bbox        bb;
  498.     union {
  499.         struct {
  500.             int        depth;
  501.             struct ol    *oblist;
  502.         } leaf;
  503.         struct {
  504.             struct kdt    *left, *right;
  505.         } branch;
  506.     } u;
  507. } stree;
  508.  
  509. /*
  510.  * ray mailbox data
  511.  */
  512. typedef struct rd {
  513.     float    t;
  514.     int    type;
  515.     short    raynumber;
  516. } raydata;
  517.  
  518. /*
  519.  * general object structure and defs
  520.  */
  521. typedef struct o {
  522.     unsigned char    type,
  523.             incsg;
  524.     bbox        bb;
  525.     surface        *s;
  526.     transdata    *td;
  527.     texture        *txtlist;
  528.     raydata        lastray;
  529.     union {
  530.         float        cne_tipval;
  531.         int        spq_order;
  532.         csg        *csgt;
  533.         eqn        *alg;
  534.         ring        *rng;
  535.         torus        *trs;
  536.         stree        *tree;
  537.         sphere        *sph;
  538.         polygon        *ply;
  539.         geometry    *geo;
  540.         superquadric    *spq;
  541.         composite    *cmp;
  542.     } obj;
  543.     struct o    *nxt;
  544. } object;
  545.  
  546. #ifndef M_PI
  547. #define M_PI    3.14159265358979323846
  548. #endif
  549.  
  550. #ifdef MSC
  551.  
  552. extern char    *smalloc();
  553.  
  554. #define yywrap()    1
  555. #endif
  556.  
  557. #ifdef VMS
  558.  
  559. extern char     *smalloc();
  560.  
  561. #define yywrap()        1
  562. #endif
  563.  
  564. extern float    eval_fexpr();
  565. extern int    eval_iexpr();
  566.  
  567. extern symbol    *insertsym();
  568. extern symbol    *findsym();
  569.