home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / QuakeC / qtools0.2-src.lha / src / libqdisplay / draw-opti8wire.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-11  |  2.0 KB  |  81 lines

  1. #ifdef    USE_ZBUFFER
  2. #define    inc()   { w += dw; }
  3. #define    fill(z) { *zBuffer++ = (unsigned short int)(z); }
  4.  
  5. unsigned short int *draw_affine8wire(int n, unsigned short int *zBuffer, int w, int dw)
  6. {
  7.   while (n--) {
  8.     fill(w);
  9.     inc();
  10.   }
  11.   return zBuffer;
  12. }
  13. #endif
  14.  
  15. /* given a span (x0,y)..(x1,y), draw a perspective-correct span for it */
  16. /*
  17.  * the zbuffer is interesting for dynamic model-draw etc.
  18.  * the buffers values (1/z) are all under 0, we can try to
  19.  * store them as 16bit-wide-fraction
  20.  *
  21.  * while(n--) {
  22.  *   *zbuf++ = (unsigned short int)(w); / we need only the lower part /
  23.  *   w += dw;
  24.  * }
  25.  *
  26.  */
  27. void draw_spans8wire(int y, int ey)
  28. {
  29. #ifdef    USE_ZBUFFER
  30.   float prew = tmap[6] + y * tmap[8];
  31. #endif
  32.  
  33.   for (; y < ey; y++) {
  34.     int sx = scan[y][0];
  35.     int len = scan[y][1] - sx;
  36.  
  37.     if (len > 0) {
  38.       unsigned char *pBuffer = (unsigned char *)localDim.frameBuffer + multRows[y] + sx;
  39.  
  40. #ifdef    USE_ZBUFFER
  41.       unsigned short int *zBuffer = localDim.zBuffer + multRows[y] + sx;
  42.       float w0;
  43.       int w, dw;                        /* 1/zbuffer */
  44.       int slen;
  45.  
  46.       /* compute (u,v) at left end */
  47.       w0 = 1 / (prew + sx * tmap[7]);                /* 1/zbuffer */
  48.  
  49.       w = FLOAT_TO_FIX(w0);                    /* 1/zbuffer */
  50.  
  51.       for (slen = len >> SUBDIV_SHIFT; slen > 0; slen--) {
  52.     sx += SUBDIV;
  53.     w0 = 1 / (prew + sx * tmap[7]);
  54.  
  55.     dw = (FLOAT_TO_FIX(w0) - w) >> SUBDIV_SHIFT;        /* 1/zbuffer */
  56.  
  57.     zBuffer = draw_affine8wire(SUBDIV, zBuffer, w, dw);
  58.     w = FLOAT_TO_FIX(w0);                    /* 1/zbuffer */
  59.       }
  60.  
  61.       if ((slen = (len & SUBDIV_MASK) - 1)) {            /* a) do not calc if only draw 1 pixel */
  62.     float w1;
  63.  
  64.     sx += slen;
  65.     w1 = 1 / (prew + sx * tmap[7]);
  66.  
  67.     dw = FLOAT_TO_FIX((w1 - w0) / slen);            /* 1/zbuffer */
  68.       }
  69.       /* a) but draw that pixel surely */
  70.       draw_affine8wire(slen + 1, zBuffer, w, dw);        /* for the last pixel the du and dv are thrown away */
  71. #endif
  72.       pBuffer[0] = 0x15;                    /* startpoint */
  73.       pBuffer[len] = 0x15;                    /* endpoint */
  74.     }
  75.  
  76. #ifdef    USE_ZBUFFER
  77.     prew += tmap[8];
  78. #endif
  79.   }
  80. }
  81.