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

  1. /* clipping */
  2. static point_3d defaultPoints[32], *defaultVList[32];
  3. static fix scan[768][2];
  4.  
  5. void setup_default_point_list(void)
  6. {
  7.   int i;
  8.  
  9.   for (i = 32 - 1; i >= 0; --i)
  10.     defaultVList[i] = &defaultPoints[i];
  11. }
  12.  
  13. /* calculation */
  14. static short int compute_mip_level(__memBase, int face)
  15. {
  16.   /*
  17.    * dumb algorithm: grab 3d coordinate of some vertex,
  18.    * compute dist from viewer
  19.    */
  20.   double dist;
  21.   int se = bspMem->shared.quake1.dfaces[face].firstedge;
  22.   int e = bspMem->shared.quake1.dsurfedges[se];
  23.  
  24.   if (e < 0)
  25.     e = -e;
  26.   dist = scalw(dist2_from_viewer((vec_t *)&bspMem->shared.quake1.dvertexes[bspMem->shared.quake1.dedges[e].v[0]].point), -16);    /* / 65536; */
  27.   if (dist < 1)
  28.     return 0;
  29.   if (dist < 4)
  30.     return 1;
  31.   if (dist < 16)
  32.     return 2;
  33.   return 3;
  34. }
  35.  
  36. static float tmap[9];
  37.  
  38. static void compute_texture_gradients(__memBase, struct texture *Text, short int mip)
  39. {
  40.   float uu, vv;
  41.   float tmp0, tmp1, tmp2;
  42.   vec3_t P, M, N;
  43.  
  44.   /* project vectors onto face's plane, and transform */
  45.   transform_vector(M, Text->textGradient.uv0);
  46.   transform_vector(N, Text->textGradient.uv1);
  47.   transform_point_raw(P, Text->textGradient.scaled);
  48.  
  49.   uu = Text->textGradient.u;
  50.   vv = Text->textGradient.v;
  51.  
  52.   /*
  53.    * we could just subtract (u,v) every time we compute a new (u,v);
  54.    * instead we fold it into P:
  55.    */
  56.   P[0] += uu * M[0] + vv * N[0];
  57.   P[1] += uu * M[1] + vv * N[1];
  58.   P[2] += uu * M[2] + vv * N[2];
  59.  
  60.   /*
  61.    * offset by Center of screen--if this were folded into
  62.    * transform translation we could avoid it
  63.    */
  64.   tmp2 = N[0] * M[2] - N[2] * M[0];
  65.   tmp1 = N[1] * M[2] - N[2] * M[1];
  66.   tmp0 = N[0] * M[1] - N[1] * M[0];
  67.   tmp0 -= tmp1 * xCenter + tmp2 * yCenter;
  68.   tmap[8] = tmp2;
  69.   tmap[7] = tmp1;
  70.   tmap[6] = tmp0;
  71.  
  72.   tmp2 = P[2] * M[0] - P[0] * M[2];
  73.   tmp1 = P[2] * M[1] - P[1] * M[2];
  74.   tmp0 = P[1] * M[0] - P[0] * M[1];
  75.   tmp0 -= tmp1 * xCenter + tmp2 * yCenter;
  76.   tmap[5] = scalw(tmp2, -mip);
  77.   tmap[4] = scalw(tmp1, -mip);
  78.   tmap[3] = scalw(tmp0, -mip);
  79.  
  80.   tmp2 = P[0] * N[2] - P[2] * N[0];
  81.   tmp1 = P[1] * N[2] - P[2] * N[1];
  82.   tmp0 = P[0] * N[1] - P[1] * N[0];
  83.   tmp0 -= tmp1 * xCenter + tmp2 * yCenter;
  84.   tmap[2] = scalw(tmp2, -mip);
  85.   tmap[1] = scalw(tmp1, -mip);
  86.   tmap[0] = scalw(tmp0, -mip);
  87. }
  88.  
  89. /*
  90.  * NOTE: subdivision of 16 is a really hard thig, it works most, but you can see sometimes curved textures
  91.  *       if you have some processorpower use 8 instead!
  92.  */
  93. #define SUBDIV_SHIFT    4
  94. #define SUBDIV        (1 << SUBDIV_SHIFT)
  95. #define    SUBDIV_MASK    (SUBDIV - 1)
  96.  
  97. /* draw an affine (linear) span starting at dest, n pixels long, */
  98. /* starting at (u,v) in the texture and stepping by (du,dv) each pixel */
  99. /*
  100.  * if we are in liquid, we can calculate the average pixelcolor
  101.  * of the liquid texture (eg. *lava1) and do a transp with this color
  102.  * so we don't need to change the palette, and the accuracity
  103.  * is better
  104.  *
  105.  * we can make the liquid with a falloff if we use the zbuffer,
  106.  * we have the current z-value, and the z-value at that position
  107.  * we sub them and calculate the transparency-level from that
  108.  * (better use every 10th or like that transparency-level: first,
  109.  *  the transparency is not so accurate, that every percent makes
  110.  *  a change, second, all 100% transparency uses 6,5MB cached
  111.  *  tables, both in memory and on disk (horror!))
  112.  * the falloff is calculated from the brightness of the liquid texture
  113.  * and the type, so brighter texture are more transparent than darker
  114.  *
  115.  * the liquid looks more real if the textures after it also warps
  116.  * so we must determine, which textures lies in liquid, probably
  117.  * we can use the same procedure as the liquid itself, maybe
  118.  * we must project the liquids behaviour to the texture (uff)
  119.  *
  120.  * how to determine if a texture lies in liquid? as I know qbsp
  121.  * splits the plaes at every intersection of two polygons, that
  122.  * means we do not need to split the polygon at the liquid-line
  123.  * the disadvatage of the mark-texture-in-liquid is, that while
  124.  * we are in liquid, the textures outside the liquid doesn't warp
  125.  *
  126.  * probably we can do real wave in liquid, for that we do not change
  127.  * the du or dv, but the z-value (upwards) of the polygon in a
  128.  * reproducable caustics manner, the difficulty is, to calculate this
  129.  * values in the very inner loop (draw_affine), thats slow
  130.  *
  131.  * how to avoid this mipmap shiftig and masking in liquid textures:
  132.  * after building the waterblock convert the scanlines from this:
  133.  *
  134.  * +----+ example: memory-block-size is 64*64
  135.  * |****|          mipmap-size is 32*32
  136.  * |    |          memory is linear
  137.  * |    |
  138.  * |    |
  139.  * +----+
  140.  *
  141.  * interally handled as this:   to this:
  142.  *                              
  143.  * +--+                         +----+ we need no shiftig, on masking
  144.  * |**|                         |**  | and it is faster, 'cause the 
  145.  * |**|                         |**  | conversion could be cached and is
  146.  * +--+                         |    | out of the span-draw-inner-loop
  147.  *                              |    |
  148.  *                              +----+
  149.  *
  150.  * we can even remove all the shifting, if we put the warp-textures
  151.  * in a 256*64 block, so the offset is 0x0000xxyy (0b000000000000000000xxxxxx00yyyyyy)
  152.  * that is a 16k-block per watertexture, not too much
  153.  *
  154.  * probably it could be faster, if we call a hook defined in the TextureCache
  155.  */
  156.  
  157. #ifdef    DRIVER_8BIT
  158. #include "draw-orig8.c"
  159. #include "draw-orig8flat.c"
  160. #include "draw-orig8wire.c"
  161. #endif
  162. #ifdef    DRIVER_16BIT
  163. #include "draw-orig16.c"
  164. #endif
  165. #ifdef    DRIVER_24BIT
  166. #include "draw-orig24.c"
  167. #endif
  168. #ifdef    DRIVER_32BIT
  169. #endif
  170.  
  171. /* preparing */
  172. static inline void scan_convert(point_3d * a, point_3d * b)
  173. {
  174.   void *temp;
  175.   int right;
  176.   fix x, dx;
  177.   int y, ey;
  178.  
  179.   if (a->sy == b->sy)
  180.     return;
  181.  
  182.   if (a->sy < b->sy)
  183.     right = 0;
  184.   else {
  185.     temp = a;
  186.     a = b;
  187.     b = temp;
  188.     right = 1;
  189.   }
  190.  
  191.   /* compute dxdy */
  192.   dx = FLOAT_TO_INT(scalw((b->sx - a->sx), 16) / (b->sy - a->sy));    /* * 65536.0 */
  193.   x = a->sx;
  194.   y = FIX_INT(a->sy);
  195.   ey = FIX_INT(b->sy);
  196.   x += FLOAT_TO_INT(((double)dx * ((y << 16) - a->sy)) * (1 / 65534.0));
  197.  
  198.   while (y < ey) {
  199.     scan[y][right] = x;
  200.     x += dx;
  201.     ++y;
  202.   }
  203. }
  204.