home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / REND386 / JIREND / 3DSTRUCT.H < prev    next >
C/C++ Source or Header  |  1993-04-11  |  9KB  |  290 lines

  1. /* Data structures for 3D modelling */
  2.   
  3. /* Written by Bernie Roehl and Dave Stampe, December 1991 */
  4. /* updated 10/1/91 for renderer clip (first stage */
  5. /* Integerizaation finished 19/1/91 and comments added */
  6.   
  7. /* Copyright 1991, 1992 by Dave Stampe and Bernie Roehl.
  8.    May be freely used to write software for release into the public domain;
  9.    all commercial endeavours MUST contact Bernie Roehl and Dave Stampe
  10.     for permission to incorporate any part of this software into their
  11.    products!
  12.  */
  13.   
  14. /* NOTE ON FORMATS:
  15.  <nn.ff> means that nn bits are available as the integer part, and
  16.  ff bits are used as a fractional part.  Multiply a float by 2^ff
  17.  to get a long value to feed in.
  18.   
  19.  World coordinates should be kept below signed 24 bits (16.7M) to
  20.  assure no errors.  This allows a range of 1mm->16.7 km, which
  21.  should be plenty!
  22.   
  23.  Angles are in <16.16> format, where the integer part is in degrees.
  24. */
  25.   
  26.   
  27. #ifndef MATRIXDEF
  28. typedef long MATRIX[4][3];      /* 3x3 rotate plus 3 translate para's */
  29.          /* rotate matrix is <3.29>, translate is <32.0> */
  30. #define MATRIXDEF 1
  31. #endif
  32.   
  33. /* new vertex copies, internal to renderer */
  34.   
  35. typedef struct nV NVERTEX;
  36. struct nV{
  37.    long  x, y, z;            /* viewport coordinates (used for saving time) */
  38.    long  xs, ys ;          /* screen coordinates */
  39.    unsigned char outcode;  /* XY clip outcodes */
  40.    unsigned char perspect; /* flags perspective done */
  41. };
  42.   
  43. #define LEFT   1  /* XY outcode bits */
  44. #define RIGHT  2
  45. #define TOP    4
  46. #define BOTTOM 8
  47.   
  48. /* world database vertices */
  49. /* object coords are referenced to object */
  50. /* world coords are updated when moving or rotating object */
  51. /* all others are renderer workspace */
  52.   
  53. typedef struct {
  54.    long ox, oy, oz;   /* object coordinates */
  55.    long x, y, z;      /* world coordinates  */
  56.    long cz;    /* converted Z coord  */
  57.    NVERTEX *new_copy;  /* non-zero if x and y transformed */
  58.    unsigned char z_transformed;   /* non-zero if z has been transformed */
  59.    unsigned char z_outcode;       /* 1 set if hither, 2 set if yon */
  60. } VERTEX;
  61.   
  62. #define HITHER 1  /* Z outcode bits */
  63. #define YON    2
  64.   
  65. /* world database polys */
  66. /* object-based normal must be rotated to world copy with object */
  67. /* color will have 8-bit color, 8-bit reflectance field */
  68.   
  69. #ifndef POLYDEF
  70. #define POLYDEF 1
  71.   
  72. typedef struct {
  73.    unsigned color;   /* color (not used yet-- will set chroma, reflectance */
  74.    VERTEX **points;  /* array of pointers to the vertices of this polygon */
  75.    int npoints;      /* number of entries in points[] */
  76.    long onormalx,
  77.    onormaly,
  78.    onormalz;    /* unit length surface normal (OBJECT) */
  79.    long normalx,
  80.    normaly,
  81.    normalz;     /* unit length surface normal (WORLD)*/
  82.    struct _object *object;
  83. } POLY;
  84.   
  85. #endif
  86.   
  87. /* renderer poly copy */
  88. /* paernt points back to original poly for lighting */
  89. /* color computed by cosine lighting (currently 0-15) */
  90. /* maxz is deepest poly point for sorting */
  91.   
  92. typedef struct {
  93.    int npoints;       /* number of entries in points[] MUST BE FIRST */
  94.    POLY *parent;
  95.    unsigned color;      /* color after illumination */
  96.    long maxz;        /* maximum Z value (for sorting) */
  97. } NPOLY;
  98.   
  99.   
  100. typedef struct { NPOLY *ptr; long depth; } DSORT; /* used for depth sorting */
  101.   
  102. #ifndef REPDEF
  103. #define REPDEF 1
  104.   
  105. typedef struct _rep {     /* a representation for an object */
  106.    long size;            /* if the object is bigger than this, use this rep */
  107.    int nverts, npolys;   /* number of vertices, number of polys */
  108.    VERTEX *verts;        /* array of vertices */
  109.    POLY *polys;          /* array of polygons */
  110.    struct _rep *next;    /* pointer to next rep in list */
  111.    long update_count;    /* inc. every time rep moves */
  112.    unsigned flags;
  113. } REP;
  114.   
  115. #endif
  116.   
  117.   
  118. /* world database object */
  119. /* sphx, sphy, sphz, sphr used for sphere object clipping */
  120.   
  121. #define OBJ_FLAG_MASK 0x7C00
  122. #define OBJ_DEPTH_MASK 0x03FF
  123.   
  124. #ifndef OBJDEF
  125. #define OBJDEF 1
  126.   
  127. typedef struct _object
  128. {
  129.    unsigned int oflags;
  130. #define OBJ_NONSEL       0x0800 /* can't be selected (i.e. pointer) */
  131. #define OBJ_INVIS        0x1000
  132. #define OBJ_HIGHLIGHTED  0x2000
  133. #define OBJLIST_HEADER   0x4000
  134. #define IS_OBJECT        0x8000  /* required by renderer: it will set */
  135.   
  136. #define DEEPEST 0x0000     /* sort polys by deepest point */
  137. #define ATBACK  0x0001     /* push this object's poly's waaaay back */
  138. #define AVERAGE 0x0002     /* sort polys by average depth */
  139.   
  140. #define BYOBJECT   0x0100  /* sort by object */
  141. #define BYPOLY     0x0000  /* put polys in world before sort */
  142.   
  143.    struct _object *prev;
  144.    struct _object *nnext;
  145.   
  146.    void *owner;       /* for example, a body segment description struct */
  147.    REP *replist;              /* pointer to list of representations */
  148.    REP *current_rep;          /* the currently-active rep */
  149.    int (*coll_eval)();          /* evaluate collision */
  150.   
  151.    long osphx, osphy, osphz;     /* object-coord sphere center */
  152.    long sphx, sphy, sphz, sphr;  /* bounding sphere center and radius */
  153.    long update_count;         /* inc. every time object moved */
  154. } OBJECT;
  155.   
  156. #endif
  157.   
  158.   
  159. /* world database object list head */
  160. /* dual linked for fast remove/insert needed for splits */
  161.   
  162. #ifndef OBJLDEF
  163. #define OBJLDEF 1
  164.   
  165. typedef struct _objlist
  166. {
  167.    unsigned int oflags;
  168. #define OBJ_INVIS        0x1000
  169. #define OBJ_HIGHLIGHTED  0x2000
  170. #define OBJLIST_HEADER   0x4000
  171. #define IS_OBJECT        0x8000  /* required by renderer: it will set */
  172.   
  173.    struct _object *prev;
  174.    struct _object *nnext;
  175. } OBJLIST;
  176.   
  177. #endif
  178.   
  179.   
  180. #ifndef VIEWDEF
  181. /* renderer viewpoint/screen control structure */
  182. /* viewoint in X, Y, Z coords */
  183. /* pan, tilt, roll in (float*65536) formats */
  184. /* zoom is equiv. to magnification from 90 deg. FOV (also float*65536) */
  185. /* aspect sets how much to magnify Y more than X to fix up displays */
  186. /* light source point in world coordinates */
  187. /* left, right, top, bottom set edges of screen */
  188. /* hither sets closest point: keep >16 for best range of world coords */
  189. /* yon sets max. distance: keep it 1<<26 if not used */
  190. /* all others are renderer workspace */
  191.   
  192. #define NOFLIP 0      /* for orientation flags */
  193. #define XFLIP  1
  194. #define YFLIP  2
  195.   
  196. typedef struct {
  197.            /* VIEWPOINT */
  198.    long ex, ey, ez;        /* <25.0>  location of eyepoint         */
  199.    long pan, tilt, roll;   /* <16.16> viewing angles (deg) +/- 128 */
  200.    long zoom;              /* <16.16> 1/tan(H FOV/2) 0.5 to 16     */
  201.       /* Light source stuff... will eventually be separate from view struct */
  202.    long lx,ly,lz;    /* <25.0>  location of light source     */
  203.    int  directional; /* 0 for point, 1 for normal (not unit) */
  204.    int  ambient;     /* ambient light: 0-256 (72 recc.)      */
  205.   
  206.              /* SCREEN DATA */
  207.    long left,right;        /* <25.0> clipping planes */
  208.    long top, bottom;
  209.    long hither, yon;   /* <25.0> near and far clipping planes   */
  210.    long aspect;      /* <16.16> x:y fixup factor (magnify Y by..*/
  211.   
  212.    /* RENDERING CONTROL */
  213.    unsigned flags;     /* 16 bits of flags */
  214.   
  215.              /* ADVANCED SCREEN DATA */
  216.    long x_offset, y_offset; /* amount to move screen center in pixels */
  217.    unsigned orientation;    /* used to mirror screen image */
  218.    MATRIX eye_xform;
  219.   
  220.            /* INTERNAL RECORDS */
  221.    long hsw, hsh;    /* half screen width, height */
  222.    long hsc, vsc;    /* screen center (with offset) */
  223.    long scx, scy;    /* full-resolution scaling for horizon */
  224.    long sx,sy;    /* mantissa of screen scaling  */
  225.    int  xshift, yshift;    /* scaling bit shifts */
  226.   
  227.    long left_C, left_M;    /* spherical clip coefficients */
  228.    long right_C, right_M;
  229.    long top_C, top_M;
  230.    long bot_C, bot_M;
  231.   
  232.    long fac1,fac2,fac3,
  233.    fac4,fac5,fac6,
  234.    fac7,fac8,fac9;    /* conversion coefficients */
  235.   
  236.    long sfac1,sfac2,sfac3, /* scaled conversion factors */
  237.    sfac4,sfac5,sfac6;
  238.   
  239.    long hor_C, vert_C;     /* spherical clip coefficients */
  240.    long hor_M, vert_M;
  241.   
  242. } VIEW;
  243.   
  244. /* View flags: */
  245.   
  246. #define WIREFRAME           0x0001
  247. #define HIDE_HIGHLIGHTED    0x0002
  248. #define HIDE_UNHIGHLIGHTED  0x0004
  249. #define VIEWDEF 1
  250. #endif
  251.   
  252. /* Prescaling (used in hrendo5.c and 3dsupp.c (in where_screen_pt()) */
  253.   
  254. #define PRESCALE  2  /* frac bits in XY coords */
  255. #define PRESCALEZ 2
  256.   
  257. #ifndef SCRIDEF
  258. #define SCRIDEF 1
  259. struct Screeninfo {
  260.    int xmin, ymin, xmax, ymax, xcent, ycent, colors, pages, bw;
  261.    long aspect;
  262.    char id[80];
  263. };
  264. #endif
  265.   
  266.   
  267. extern struct Screeninfo *screeninfo;
  268.   
  269. extern long isine(long angle);
  270. extern long icosine(long angle);
  271.                /* create rotation/translation */
  272.                /* "matrix" from angle data    */
  273.                /* CALL setup_render FIRST!    */
  274.   
  275. /* End of structs */
  276.   
  277. extern void set_screen_monitor(int x, int y);
  278. extern void clear_screen_monitor();
  279. extern POLY * read_screen_monitor();
  280.   
  281. /* Provided by user, in render.c: */
  282.   
  283. extern void user_render_poly(int vertex_count, int *pcoords,
  284. unsigned poly_color, long max_depth);
  285. extern void user_setup_blitter();
  286. extern void user_reset_blitter();
  287.   
  288. /* End of 3dstruct.h */
  289.   
  290.