home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / texmap / tmapsky.c < prev    next >
C/C++ Source or Header  |  1998-06-08  |  6KB  |  216 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/texmap/rcs/tmapsky.c $
  15.  * $Revision: 1.4 $
  16.  * $Author: mike $
  17.  * $Date: 1994/11/28 13:34:33 $
  18.  * 
  19.  * Sky texture mapper for Sim City 2000 Drive Through
  20.  * 
  21.  * $Log: tmapsky.c $
  22.  * Revision 1.4  1994/11/28  13:34:33  mike
  23.  * optimizations.
  24.  * 
  25.  * Revision 1.3  1994/06/09  16:10:10  mike
  26.  * Kill definition of SC2000.
  27.  * 
  28.  * Revision 1.2  1994/03/15  14:49:58  mike
  29.  * *** empty log message ***
  30.  * 
  31.  * Revision 1.1  1994/03/15  10:30:53  mike
  32.  * Initial revision
  33.  * 
  34.  * 
  35.  */
  36.  
  37.  
  38. #pragma off (unreferenced)
  39. static char rcsid[] = "$Id: tmapsky.c 1.4 1994/11/28 13:34:33 mike Exp $";
  40. #pragma on (unreferenced)
  41.  
  42. // This is evil and it's all Matt's fault, and it is only here so Assert will work, but that
  43. // should work off ifdef, not if, so there!
  44. #define    DEBUG_ON 1
  45.  
  46. #include <math.h>
  47. #include <limits.h>
  48. #include <stdio.h>
  49. #include <conio.h>
  50. #include <stdlib.h>
  51.  
  52. #include "mono.h"
  53. #include "fix.h"
  54. #include "3d.h"
  55. #include "gr.h"
  56. #include "error.h"
  57.  
  58. #include "texmap.h"
  59. #include "texmapl.h"
  60.  
  61. #define F15_5 (F1_0*15 + F0_5)
  62.  
  63. int Do_sky_vertical = 0;
  64.  
  65. void tmap_scanline_lin_sky(grs_bitmap *srcb, int y, fix xleft, fix xright, fix uleft, fix uright, fix vleft, fix vright)
  66. {
  67.     fix    u,v;
  68.     fix    dx;
  69.  
  70.     u = uleft;
  71.     v = vleft;
  72.  
  73.     dx = xright - xleft;
  74.     if (dx < 0)
  75.         return;
  76.  
  77.     // setup to call assembler scanline renderer
  78.     fx_u = uleft;
  79.     fx_v = vleft;
  80.  
  81.     if (dx < f1_0) {
  82.         fx_du_dx = uright-uleft;
  83.         fx_dv_dx = vright-vleft;
  84.     } else {
  85.         fx_du_dx = fixdiv(uright - fx_u,dx);
  86.         fx_dv_dx = fixdiv(vright - fx_v,dx);
  87.     }
  88.  
  89.     fx_y = y;
  90.     fx_xleft = xleft;
  91.     fx_xright = xright;
  92.     pixptr = srcb->bm_data;
  93.  
  94.     asm_tmap_scanline_lin_sky();
  95.  
  96. }
  97.  
  98. // -------------------------------------------------------------------------------------
  99. //    Render a texture map.
  100. // Linear in outer loop, linear in inner loop.
  101. // -------------------------------------------------------------------------------------
  102. void texture_map_lin_lin_sky(grs_bitmap *srcb, g3ds_tmap *t)
  103. {
  104.     int    vlt,vrt,vlb,vrb;    // vertex left top, vertex right top, vertex left bottom, vertex right bottom
  105.     int    topy,boty,y;
  106.     int    left_break,right_break;
  107.  
  108.     fix    dx_dy_left,dx_dy_right;
  109.     fix    du_dy_left,du_dy_right;
  110.     fix    dv_dy_left,dv_dy_right;
  111.  
  112.     int    max_y_vertex;
  113.     fix    xleft,xright,uleft,vleft,uright,vright;
  114.     g3ds_vertex *v3d;
  115.  
  116. if (Do_sky_vertical) {
  117.     texture_map_lin_lin_sky_v(srcb, t);
  118.     return;
  119. }
  120.  
  121.     //--now called from g3_start_frame-- init_interface_vars_to_assembler();
  122.  
  123.     v3d = t->verts;
  124.  
  125.     // Determine top and bottom y coords.
  126.     compute_y_bounds(t,&vlt,&vlb,&vrt,&vrb,&max_y_vertex);
  127.  
  128.     // Set top and bottom (of entire texture map) y coordinates.
  129.     topy = f2i(v3d[vlt].y2d);
  130.     boty = f2i(v3d[max_y_vertex].y2d);
  131.  
  132.     // Set amount to change x coordinate for each advance to next scanline.
  133.     dx_dy_left = compute_dx_dy_lin(t,vlt,vlb);
  134.     dx_dy_right = compute_dx_dy_lin(t,vrt,vrb);
  135.  
  136.     du_dy_left = compute_du_dy_lin(t,vlt,vlb);
  137.     du_dy_right = compute_du_dy_lin(t,vrt,vrb);
  138.  
  139.     dv_dy_left = compute_dv_dy_lin(t,vlt,vlb);
  140.     dv_dy_right = compute_dv_dy_lin(t,vrt,vrb);
  141.  
  142.      // Set initial values for x, u, v
  143.     xleft = v3d[vlt].x2d;
  144.     xright = v3d[vrt].x2d;
  145.  
  146.     uleft = v3d[vlt].u;
  147.     uright = v3d[vrt].u;
  148.     vleft = v3d[vlt].v;
  149.     vright = v3d[vrt].v;
  150.  
  151.     // scan all rows in texture map from top through first break.
  152.     // @mk: Should we render the scanline for y==boty?  This violates Matt's spec.
  153.  
  154.     left_break = f2i(v3d[vlb].y2d);
  155.     right_break = f2i(v3d[vrb].y2d);
  156.  
  157.     for (y = topy; y < boty; y++) {
  158.  
  159.         // See if we have reached the end of the current left edge, and if so, set
  160.         // new values for dx_dy and x,u,v
  161.         if (y == left_break) {
  162.             // Handle problem of double points.  Search until y coord is different.  Cannot get
  163.             // hung in an infinite loop because we know there is a vertex with a lower y coordinate
  164.             // because in the for loop, we don't scan all spanlines.
  165.             while (y == f2i(v3d[vlb].y2d)) {
  166.                 vlt = vlb;
  167.                 vlb = prevmod(vlb,t->nv);
  168.             }
  169.             left_break = f2i(v3d[vlb].y2d);
  170.  
  171.             dx_dy_left = compute_dx_dy_lin(t,vlt,vlb);
  172.  
  173.             xleft = v3d[vlt].x2d;
  174.             uleft = v3d[vlt].u;
  175.             vleft = v3d[vlt].v;
  176.  
  177.             du_dy_left = compute_du_dy_lin(t,vlt,vlb);
  178.             dv_dy_left = compute_dv_dy_lin(t,vlt,vlb);
  179.         }
  180.  
  181.         // See if we have reached the end of the current left edge, and if so, set
  182.         // new values for dx_dy and x.  Not necessary to set new values for u,v.
  183.         if (y == right_break) {
  184.             while (y == f2i(v3d[vrb].y2d)) {
  185.                 vrt = vrb;
  186.                 vrb = succmod(vrb,t->nv);
  187.             }
  188.             right_break = f2i(v3d[vrb].y2d);
  189.  
  190.             dx_dy_right = compute_dx_dy_lin(t,vrt,vrb);
  191.  
  192.             xright = v3d[vrt].x2d;
  193.             uright = v3d[vrt].u;
  194.             vright = v3d[vrt].v;
  195.  
  196.             du_dy_right = compute_du_dy_lin(t,vrt,vrb);
  197.             dv_dy_right = compute_dv_dy_lin(t,vrt,vrb);
  198.         }
  199.  
  200.         tmap_scanline_lin_sky(srcb,y,xleft,xright,uleft,uright,vleft,vright);
  201.  
  202.         uleft += du_dy_left;
  203.         vleft += dv_dy_left;
  204.  
  205.         uright += du_dy_right;
  206.         vright += dv_dy_right;
  207.  
  208.         xleft += dx_dy_left;
  209.         xright += dx_dy_right;
  210.  
  211.     }
  212.     tmap_scanline_lin_sky(srcb,y,xleft,xright,uleft,uright,vleft,vright);
  213. }
  214.  
  215.  
  216.