home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / 3dstruct.inc < prev    next >
Text File  |  1996-03-19  |  11KB  |  451 lines

  1.     COMMENT $
  2.  
  3. /* Data structures for 3D modelling */
  4.  
  5. /* Written for assembly by Dave Stampe, December 1993 */
  6. /* base on 3dstruct.h */
  7.  
  8. /*
  9.  This code is part of the REND386 project, created by Dave Stampe and
  10.  Bernie Roehl.
  11.  
  12.  Copyright 1992, 1993, 1994 by Dave Stampe and Bernie Roehl.
  13.  
  14.  May be freely used to write software for release into the public domain;
  15.  all commercial endeavours MUST contact BOTH Bernie Roehl and Dave Stampe
  16.  for permission to incorporate any part of this software into their
  17.  products!  Usually there is no charge for under 50-100 items for
  18.  low-cost or shareware, and terms are reasonable.  Any royalties are used
  19.  for development, so equipment is often acceptable payment.
  20.  
  21.  ATTRIBUTION:  If you use any part of this source code or the libraries
  22.  in your projects, you must give attribution to REND386, Dave Stampe,
  23.  and Bernie Roehl in your documentation, source code, and at startup
  24.  of your program.  Let's keep the freeware ball rolling!  No more
  25.  code ripoffs please.
  26.  
  27.  CONTACTS: dstampe@psych.toronto.edu, broehl@sunee.uwaterloo.ca
  28.  See the COPYRITE.H file for more information.
  29. */
  30.  
  31.  
  32.  
  33. /* NOTE ON FORMATS:
  34.  <nn.ff> means that nn bits are available as the integer part, and
  35.  ff bits are used as a fractional part.  Multiply a float by 2^ff
  36.  to get a long value to feed in.
  37.  
  38.  World coordinates should be kept below signed 24 bits (16.7M) to
  39.  assure no errors.  This allows a range of 1mm->16.7 km, which
  40.  should be plenty!
  41.  
  42.  Angles are in <16.16> format, where the integer part is in degrees.
  43. */
  44.         $
  45.  
  46.  
  47.         ; Actual structure of a homogenous matrix
  48.  
  49.  
  50. MATRIX STRUC
  51. MAT_xx    dd ?    ; col. 1
  52. MAT_yx    dd ?
  53. MAT_zx    dd ?
  54. MAT_xy    dd ?    ; col. 2
  55. MAT_yy    dd ?
  56. MAT_zy    dd ?
  57. MAT_xz    dd ?    ; col. 3
  58. MAT_yz    dd ?
  59. MAT_zz    dd ?
  60. MAT_xt    dd ?    ; translations
  61. MAT_yt    dd ?
  62. MAT_zt    dd ?
  63. MATRIX ENDS
  64.  
  65. ;/* new vertex copies, internal to renderer */
  66. ;typedef struct nV NVERTEX;
  67. ;struct nV{
  68. ;        long  x, y, z;             /* viewport coordinates (used for saving time) */
  69. ;          long  xs, ys ;          /* screen coordinates */
  70. ;        unsigned char outcode;  /* XY clip outcodes */
  71. ;        unsigned char perspect; /* flags perspective done */
  72. ;        };
  73.  
  74. NVERTEX STRUC
  75. NV_x    dd ?
  76. NV_y    dd ?
  77. NV_z    dd ?
  78.  
  79. NV_xs    dd ?
  80. NV_ys    dd ?
  81.  
  82. NV_ocode db ?
  83. NV_persp db ?
  84. NVERTEX ENDS
  85.  
  86. OLEFT   equ 1          ; /* XY outcode bits */
  87. ORIGHT  equ 2
  88. OTOP    equ 4
  89. OBOTTOM equ 8
  90.  
  91.  
  92. ;/* world database vertices */
  93. ;/* object coords are referenced to object */
  94. ;/* world coords are updated when moving or rotating object */
  95. ;/* all others are renderer workspace */
  96. ;
  97. ;typedef struct {
  98. ;    long ox, oy, oz;   /* object coordinates */
  99. ;    long x, y, z;      /* world coordinates  */
  100. ;    long cz;       /* converted Z coord  */
  101. ;    NVERTEX *new_copy;  /* non-zero if x and y transformed */
  102. ;    unsigned char z_transformed;   /* non-zero if z has been transformed */
  103. ;    unsigned char z_outcode;       /* 1 set if hither, 2 set if yon */
  104. ;    } VERTEX;
  105.  
  106. VERTEX STRUC
  107. V_ox    dd ?
  108. V_oy    dd ?
  109. V_oz    dd ?
  110.  
  111. V_x    dd ?
  112. V_y    dd ?
  113. V_z    dd ?
  114.  
  115. V_cz    dd ?
  116.  
  117. V_nvptr dd ?
  118.  
  119. V_zxflag db ?
  120. V_zocode db ?
  121. VERTEX ENDS
  122.  
  123.  
  124. OHITHER equ 16        ; /* Z outcode bits */
  125. OYON    equ 32
  126.  
  127.  
  128. ;/* world database polys */
  129. ;/* object-based normal must be rotated to world copy with object */
  130. ;/* color will have 8-bit color, 8-bit reflectance field */
  131. ;
  132. ;typedef struct {
  133. ;    unsigned color;   /* color (not used yet-- will set chroma, reflectance */
  134. ;    VERTEX **points;  /* array of pointers to the vertices of this polygon */
  135. ;    int npoints;      /* number of entries in points[] */
  136. ;    long onormalx,
  137. ;         onormaly,
  138. ;         onormalz;    /* unit length surface normal (VISOBJ) */
  139. ;    long normalx,
  140. ;         normaly,
  141. ;         normalz;     /* unit length surface normal (WORLD)*/
  142. ;    struct _object *object;
  143. ;    } POLY;
  144.  
  145.  
  146. POLY STRUC
  147. P_color     dw ?
  148. P_points    dd ?
  149. P_npoints    dw ?
  150.  
  151. P_onormx    dd ?
  152. P_onormy    dd ?
  153. P_onormz    dd ?
  154.  
  155. P_normx     dd ?
  156. P_normy     dd ?
  157. P_normz     dd ?
  158.  
  159. P_objptr    dd ?
  160. POLY ENDS
  161.  
  162.  
  163. ;/* renderer poly copy */
  164. ;/* paernt points back to original poly for lighting */
  165. ;/* color computed by cosine lighting */
  166. ;/* maxz is deepest poly point for sorting */
  167. ;
  168. ;typedef struct {
  169. ;    int npoints;       /* number of entries in points[] MUST BE FIRST */
  170. ;    POLY *parent;
  171. ;    unsigned color;       /* color after illumination */
  172. ;    long maxz;        /* maximum Z value (for sorting) */
  173. ;    } NPOLY;
  174.  
  175. NPOLY STRUC
  176. NP_npoints    dw ?
  177. NP_parent    dd ?
  178. NP_color    dw ?
  179. NP_maxz        dd ?
  180. NPOLY ENDS
  181.  
  182.  
  183. ;typedef struct { NPOLY *ptr; long depth; } DSORT; /* used for depth sorting */
  184.  
  185. DSORT STRUC
  186. DS_ptr      dd ?
  187. DS_depth    dd ?
  188. DSORT ENDS
  189.  
  190.  
  191. ;typedef struct _rep {        /* a representation for an object */
  192. ;    long size;            /* if the object is bigger than this, use this rep */
  193. ;    int nverts, npolys;   /* number of vertices, number of polys */
  194. ;    VERTEX *verts;        /* array of vertices */
  195. ;    POLY *polys;          /* array of polygons */
  196. ;    struct _rep *next;    /* pointer to next rep in list */
  197. ;    long update_count;    /* inc. every time rep moves */
  198. ;    unsigned flags;
  199. ;    } REP;
  200.  
  201.  
  202. REPR STRUC
  203. R_size        dw ?
  204. R_nverts    dw ?
  205. R_npolys    dw ?
  206.  
  207. R_verts        dd ?
  208. R_polys     dd ?
  209. R_next        dd ?
  210.  
  211. R_ucount    dd ?
  212. R_flags        dw ?
  213. REPR ENDS
  214.  
  215.  
  216. ;/* world database object */
  217. ;/* sphx, sphy, sphz, sphr used for sphere object clipping */
  218. ;
  219. ;#define OBJ_FLAG_MASK 0x7C00
  220. ;#define OBJ_DEPTH_MASK 0x03FF
  221. ;
  222. ;
  223. ;struct _object
  224. ; {
  225. ;    unsigned int oflags;
  226. ;#define OBJ_REPLOCK      0x0400
  227. ;#define OBJ_NONSEL       0x0800 /* can't be selected (i.e. pointer) */
  228. ;#define OBJ_INVIS        0x1000
  229. ;#define OBJ_HIGHLIGHTED  0x2000
  230. ;#define OBJLIST_HEADER   0x4000
  231. ;#define IS_VISOBJ        0x8000    /* required by renderer: it will set */
  232. ;
  233. ;#define DEEPEST 0x0000        /* sort polys by deepest point */
  234. ;#define ATBACK  0x0001        /* push this object's poly's waaaay back */
  235. ;#define AVERAGE 0x0002        /* sort polys by average depth */
  236. ;
  237. ;#define BYOBJECT   0x0100    /* sort by object */
  238. ;#define BYPOLY     0x0000    /* put polys in world before sort */
  239. ;
  240. ;    struct _object *prev;
  241. ;    struct _object *nnext;
  242. ;
  243. ;    void *owner;       /* for example, a body segment description struct */
  244. ;    REP *replist;              /* pointer to list of representations */
  245. ;    REP *current_rep;          /* the currently-active rep */
  246. ;
  247. ;    long osphx, osphy, osphz;     /* object-coord sphere center */
  248. ;    long sphx, sphy, sphz, sphr;  /* bounding sphere center and radius */
  249. ;    long update_count;         /* inc. every time object moved */
  250. ; };
  251. ;
  252.  
  253. VISOBJ     STRUC
  254. O_flags        dw ?
  255.  
  256. O_prev        dd ?
  257. O_nnext        dd ?
  258. O_owner        dd ?
  259.  
  260. O_replist    dd ?
  261. O_currep     dd ?
  262.  
  263. O_osphx       dd ?
  264. O_osphy       dd ?
  265. O_osphz       dd ?
  266.  
  267. O_sphx       dd ?
  268. O_sphy       dd ?
  269. O_sphz       dd ?
  270. O_sphr       dd ?
  271.  
  272. O_ucount    dd ?
  273. VISOBJ    ENDS
  274.  
  275.  
  276. OBJ_FLAG_MASK     equ    7C00h
  277. OBJ_DEPTH_MASK    equ    03FFh
  278.  
  279. OBJ_REPLOCK      equ    0400h
  280. OBJ_NONSEL       equ    0800h   ;/* can't be selected (i.e. pointer) */
  281. OBJ_INVIS        equ    1000h
  282. OBJ_HIGHLIGHTED    equ    2000h
  283. OBJLIST_HEADER    equ    4000h
  284. IS_VISOBJ       equ    8000h    ;/* required by renderer: it will set */
  285.  
  286. DEEPEST     equ    0000h     ;/* sort polys by deepest point */
  287. ATBACK      equ    0001h     ;/* push this object's poly's waaaay back */
  288. AVERAGE     equ    0002h    ;/* sort polys by average depth */
  289.  
  290. BYOBJECT       equ    0100h    ;/* sort by object */
  291. BYPOLY         equ    0000h    ;/* put polys in world before sort */
  292.  
  293.  
  294. ;/* world database object list head */
  295. ;/* dual linked for fast remove/insert needed for splits */
  296. ;
  297. ;typedef struct _objlist
  298. ; {
  299. ;    unsigned int oflags;
  300. ;
  301. ;    struct _object *prev;
  302. ;    struct _object *nnext;
  303. ; } OBJLIST;
  304.  
  305. OBJLIST STRUC
  306. OL_flags    dw ?
  307. OL_prev        dd ?
  308. OL_nnext    dd ?
  309. OBJLIST ENDS
  310.  
  311.  
  312. ;/* renderer viewpoint/screen control structure */
  313. ;/* viewoint in X, Y, Z coords */
  314. ;/* pan, tilt, roll in (float*65536) formats */
  315. ;/* zoom is equiv. to magnification from 90 deg. FOV (also float*65536) */
  316. ;/* aspect sets how much to magnify Y more than X to fix up displays */
  317. ;/* light source point in world coordinates */
  318. ;/* left, right, top, bottom set edges of screen */
  319. ;/* hither sets closest point: keep >16 for best range of world coords */
  320. ;/* yon sets max. distance: keep it 1<<26 if not used */
  321. ;/* all others are renderer workspace */
  322. ;
  323. ;typedef struct {
  324. ;             /* VIEWPOINT */
  325. ;    long zoom;              /* <16.16> 1/tan(H FOV/2) 0.5 to 16     */
  326.  
  327. ;                 /* SCREEN DATA */
  328. ;    long left,right;        /* <25.0> clipping planes */
  329. ;    long top, bottom;
  330. ;    long hither, yon;   /* <25.0> near and far clipping planes   */
  331. ;    long aspect;        /* <16.16> x:y fixup factor (magnify Y by..*/
  332. ;
  333. ;    /* RENDERING CONTROL */
  334. ;    unsigned flags;     /* 16 bits of flags */
  335. ;
  336. ;                 /* ADVANCED SCREEN DATA */
  337. ;    long x_offset, y_offset; /* amount to move screen center in pixels */
  338. ;    unsigned orientation;    /* used to mirror screen image */
  339. ;    MATRIX eye_xform;
  340. ;
  341. ;             /* INTERNAL RECORDS */
  342. ;    long hsw, hsh;        /* half screen width, height */
  343. ;    long hsc, vsc;        /* screen center (with offset) */
  344. ;    long scx, scy;        /* full-resolution scaling for horizon */
  345. ;    long sx,sy;        /* mantissa of screen scaling  */
  346. ;    int  xshift, yshift;    /* scaling bit shifts */
  347. ;
  348. ;    long left_C, left_M;    /* spherical clip coefficients */
  349. ;    long right_C, right_M;
  350. ;    long top_C, top_M;
  351. ;    long bot_C, bot_M;
  352. ;
  353. ;    long fac1,fac2,fac3,
  354. ;         fac4,fac5,fac6,
  355. ;         fac7,fac8,fac9;    /* conversion coefficients */
  356. ;
  357. ;    long sfac1,sfac2,sfac3, /* scaled conversion factors */
  358. ;             sfac4,sfac5,sfac6;
  359. ;           } VIEW;
  360.  
  361. VIEW STRUC
  362. VP_zoom        dd ?
  363.  
  364. VP_left        dd ?
  365. VP_right    dd ?
  366. VP_top        dd ?
  367. VP_bottom    dd ?
  368. VP_hither    dd ?
  369. VP_yon        dd ?
  370.  
  371. VP_aspect    dd ?
  372. VP_flags    dw ?
  373.  
  374. VP_xoffset    dd ?
  375. VP_yoffset    dd ?
  376. VP_orientation    dw ?
  377.  
  378. VP_xform00    dd ?    ; MATRIX
  379. VP_xform01    dd ?
  380. VP_xform02    dd ?
  381. VP_xform10    dd ?
  382. VP_xform11    dd ?
  383. VP_xform12    dd ?
  384. VP_xform20    dd ?
  385. VP_xform21    dd ?
  386. VP_xform22    dd ?
  387. VP_xform30    dd ?
  388. VP_xform31    dd ?
  389. VP_xform32    dd ?
  390.  
  391. VP_hsw        dd ?
  392. VP_hsh        dd ?
  393. VP_hsc        dd ?
  394. VP_vsc        dd ?
  395.  
  396. VP_scx        dd ?
  397. VP_scy        dd ?
  398. VP_sx        dd ?
  399. VP_sy        dd ?
  400.  
  401. VP_xshift    dw ?
  402. VP_yshift    dw ?
  403.  
  404. VP_left_C    dd ?
  405. VP_left_M    dd ?
  406. VP_right_C    dd ?
  407. VP_right_M    dd ?
  408. VP_top_C     dd ?
  409. VP_top_M     dd ?
  410. VP_bot_C     dd ?
  411. VP_bot_M     dd ?
  412.  
  413. VIEW ENDS
  414.  
  415. NOFLIP     equ    0      ;/* for orientation flags */
  416. XFLIP     equ    1
  417. YFLIP     equ    2
  418.  
  419. WIREFRAME           equ    0001h ;/* View flags: */
  420. HIDE_HIGHLIGHTED    equ    0002h
  421. HIDE_UNHIGHLIGHTED  equ    0004h
  422.  
  423.  
  424. PRESCALE      equ    2      ;/* frac bits in XY coords */
  425. PRESCALEZ     equ    2
  426.  
  427. ;struct Screeninfo {
  428. ;    int xmin, ymin, xmax, ymax, xcent, ycent, colors, pages, bw;
  429. ;    long aspect;
  430. ;    char id[80];
  431. ;    };
  432.  
  433. SCREENINFO STRUC
  434. S_xmin      dw ?
  435. S_ymin      dw ?
  436. S_xmax       dw ?
  437. S_ymax       dw ?
  438.  
  439. S_xcent      dw ?
  440. S_ycent      dw ?
  441. S_colors    dw ?
  442. S_pages     dw ?
  443. S_bw        dw ?
  444.  
  445. S_aspect    dd ?
  446. S_id        db 80 dup (?)
  447. SCREENINFO ENDS
  448.  
  449. OUT_OF_VIEW     equ    80000000h  ; returned by clip_by_volume() if out
  450.  
  451.