home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / rendpriv.h < prev    next >
C/C++ Source or Header  |  1996-03-19  |  8KB  |  211 lines

  1. // private declarations for renderer pipeline
  2.  
  3. /*
  4.  This code is part of the VR-386 project, created by Dave Stampe.
  5.  VR-386 is a desendent of REND386, created by Dave Stampe and
  6.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  7.  Stampre for VR-386.
  8.  
  9.  Copyright (c) 1994 by Dave Stampe:
  10.  May be freely used to write software for release into the public domain
  11.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  12.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  13.  this software or source code into their products!  Usually there is no
  14.  charge for under 50-100 items for low-cost or shareware products, and terms
  15.  are reasonable.  Any royalties are used for development, so equipment is
  16.  often acceptable payment.
  17.  
  18.  ATTRIBUTION:  If you use any part of this source code or the libraries
  19.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  20.  and any other authors in your documentation, source code, and at startup
  21.  of your program.  Let's keep the freeware ball rolling!
  22.  
  23.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  24.  REND386, improving programmer access by rewriting the code and supplying
  25.  a standard API.  If you write improvements, add new functions rather
  26.  than rewriting current functions.  This will make it possible to
  27.  include you improved code in the next API release.  YOU can help advance
  28.  VR-386.  Comments on the API are welcome.
  29.  
  30.  CONTACT: dstampe@psych.toronto.edu
  31. */
  32.  
  33.  
  34.  
  35. #include "vr_ctypes.h"
  36.  
  37. // from HORMATH.ASM
  38.  
  39.     // computes if point on screen is above or below horizon
  40.     // used to determine how to draw horizon
  41. extern int above_horizon(long x, long y, VIEW *v, long offset);
  42.  
  43.     // computes y coord of horizon given x coordinarte
  44. extern long y_horizon(long x, VIEW *v, long offset);
  45.  
  46.     // computes y coord of horizon given x coordinarte
  47. extern long x_horizon(long y, VIEW *v, long offset);
  48.  
  49. // from horizon.c
  50.  
  51. // 2-color horizon: if sky and ground color are same,
  52. // just clears window in one pass
  53. // these colors are usually direct entries into the pallette
  54.  
  55.     // sets sky color of 2-color horizon
  56. extern void set_skycolor(int color);
  57.  
  58.     // get ground clor of 2-color horizon
  59. extern void set_groundcolor(int color);
  60.  
  61.  
  62. /** EXTERNAL HORIZON TYPE SETUP **/
  63.  
  64. // args: ncolor = 0 for no clear (i.e if you clear full page before)
  65. //       ncolor = 1 for solid clear to skycolor, or skycolor=groundcolor
  66. //       ncolor = 2 for normal horizon, or skycolor<>groundcolor
  67. //       ncolor > 2 for banded horizon with array of colors from palette
  68. //     leave bandsize 0 (unchanged), or use 64 for best size
  69.  
  70. // an example colorset: { 0xaf, 0xae, 0xad, 0xac, 0x79, 0x7a, 0x7b, 0x7c }
  71.  
  72. extern void set_horizon(int ncolors, int colors[16], int bandsize);
  73.  
  74. /** DRAW HORIZON/CLEAR WINDOW CALL ***/
  75.  
  76. extern void horizon(VIEW *v, int page);    // clear window or draw horizon
  77.  
  78. // from LIGHTING.ASM
  79.  
  80.     /* compute vector from light source to surface  */
  81.     /* find dot product, normalize by vector length */
  82.     /* returns -128<light<128 (signed 8-bit)        */
  83.     /* args: ligh characteristics, poly normal, point on poly */
  84.     /* point on poly is 0,0,0 for spotlight     */
  85.     /* takes about 200 clocks!            */
  86. extern int light_cosine(long nx, long ny, long nz,
  87.              long vx, long vy, long vz,
  88.              long lx, long ly, long lz );
  89.  
  90. // from VIEWREND.ASM
  91.  
  92.  
  93.     // ASSEMBLER: copies viewport data to statics
  94.     // viewport must have been processed by
  95.     // initialize_screen_factors() in the past,
  96.     // and then viewpoint can be changed with
  97.     // fast_view_factors() or matrix_view_factors
  98.  
  99.     /* copy viewport data to fast access area */
  100.     /* to prepare renderer to draw a view     */
  101.     /* do after viewpoint or look angle has changed */
  102. extern void render_set_view(VIEW *v);
  103.  
  104.  
  105.     /* compute screen and viewport factors.  These stay constant   */
  106.     /* over eye point changes.  Call this to initialize a viewport */
  107.     /* and after the view parameters such as zoom or stereo change */
  108. extern void initialize_screen_factors(VIEW *v);
  109.  
  110. // from OBJREND.ASM
  111.  
  112.     // quicksort of poly/object array of DSORT <pointer,depth>
  113.     // sorts into descending order.  Fastest for lots of polys
  114. extern void qsort_dsort(DSORT far *first, DSORT far *last);
  115.  
  116.     // insertion sort of poly/object array of DSORT <pointer,depth>
  117.     // faster than quicksort if less than 16 items (i.e with splits)
  118.     // sorts in descending order
  119. extern void insertion_dsort(DSORT far *first, DSORT far *last);
  120.  
  121.     // determines if any part of object's bounding sphere
  122.     // is within view volume.  Very fast.  It returns
  123.     // the prescaled (x4) depth of the object center for sorting.
  124.     // if not visible, returns OUT_OF_VIEW
  125. #define OUT_OF_VIEW 0x80000000L    // returned if we can't see object
  126. extern long obj_clip_by_volume(VISOBJ *obj);
  127.  
  128.     // determine width of bounding sphere of object
  129.     // on the screen in pixels: used to decide which
  130.     // representation to use.
  131.     // only use if object has passed preclip!
  132. extern long compute_obj_screen_size(VISOBJ *obj, long center_z);
  133.  
  134.     // prepares object for rendering by clearing its
  135.     // caching flags and pointers
  136.     // a representation must be current!
  137. extern void prerender_clear_object(VISOBJ *obj);
  138.  
  139. // from XYCLIP.ASM
  140.  
  141.     // optimized semi-recursive Sutherland-Hodgeman clipper
  142.     // XY clips screen coordinates of an array of pointers to NVERTEX
  143.     // (renderer vertex copies), and stores pointers to output vertices
  144.     // in a new array.  May create new, clipped vertex copies
  145.     // returns number of vertex pointers placed in array
  146. extern int XY_clip_array(NVERTEX **src, NVERTEX **dest, int count);
  147.  
  148. // from POLYPROC.ASM
  149.  
  150.     // transforms coordinates of vertex to X, Y camera coords.
  151.     // It will re-use previous calculations and vertices if possible
  152.     // (i.e when several polys share a vertex).  It will create a
  153.     // new copy of the vertex if transformation is needed.
  154. extern NVERTEX *xy_transform(VERTEX *v);
  155.  
  156.     // final processing for vertex after XY transform. Figure the
  157.     // perspective and XY screen positions and XY poly outcodes
  158.     // returns the outcodes
  159. extern int z_output(NVERTEX *nv);
  160.  
  161.     // convert vertex to determine camera Z coordinate.  Fills in
  162.     // the outcode field and can re-use previously transformed
  163.     // results from other polys.  Returns Z outcode
  164. extern int z_convert_vertex(VERTEX *vtx);
  165.  
  166.     // returns sign of visibility dot product of poly normal
  167.     // with line connecting viewpoint to vertex 0.  Used for
  168.     // BSP sorting and backface removal
  169. extern int is_poly_facing(POLY *p);
  170.  
  171.     // creates new vertex from hither plane intercept of edge
  172.     // between two vertices.  Always allocates new vertex
  173.     // we don't clip yon plane at all, just discard polys
  174.     // that are too far away
  175. extern NVERTEX *z_hither_clip(NVERTEX *v1, NVERTEX *v2);
  176.  
  177.     // finds the average depth of a ploy by going therough
  178.     // the list of NVERTEX pointers for the poly.  THe
  179.     // returned depth is prescaled (x4)
  180. extern long average_nvertex_depth(NVERTEX **nvp, int ncount);
  181.  
  182.     // same as average_nvertex_depth, but returns deepest depth
  183. extern long deepest_nvertex_depth(NVERTEX **nvp, int ncount);
  184.  
  185.  
  186. // from POLYOUT.ASM
  187.  
  188.     // unpack poly's vertices to array, in X,Y pair order (CCW)
  189.     // vertices order can be reversed for drawing to the screen
  190.     // with X (xor) Y mirroring.  De-prescales XY coords.
  191.     // returns number of vertices unpacked
  192. extern int unpack_poly_vertices(NPOLY *poly, int *vtxarray, int direction);
  193.  
  194.     // given array of screen vertices from unpack_poly_vertices()
  195.     // checks to see if point (x,y) is inside of poly.
  196.     // returns -1 for point not in poly, else 0
  197. extern int monitor_test_poly(int x, int y, int n, int *array);
  198.  
  199.  
  200. // from RENDCORE.C
  201.  
  202. // no routines from rendcore.c need to be declared in this private file
  203. // except for the use of HORIZON.C.
  204.  
  205.  
  206. // external renderer poly interface
  207.  
  208. extern void render_ext_poly(int npoints, int xv[20], int yv[20], unsigned color);
  209.  
  210.  
  211.