home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 15 / MA_Cover_15.iso / source / winquake / d_sky.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-03  |  3.1 KB  |  143 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // d_sky.c
  21.  
  22. #include "quakedef.h"
  23. #include "r_local.h"
  24. #include "d_local.h"
  25.  
  26. #define SKY_SPAN_SHIFT    5
  27. #define SKY_SPAN_MAX    (1 << SKY_SPAN_SHIFT)
  28.  
  29.  
  30. #if !id68k
  31. /*
  32. =================
  33. D_Sky_uv_To_st
  34. =================
  35. */
  36. void D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t)
  37. {
  38.     float    wu, wv, temp;
  39.     vec3_t    end;
  40.  
  41.     if (r_refdef.vrect.width >= r_refdef.vrect.height)
  42.         temp = (float)r_refdef.vrect.width;
  43.     else
  44.         temp = (float)r_refdef.vrect.height;
  45.  
  46.     wu = 8192.0 * (float)(u-((int)vid.width>>1)) / temp;
  47.     wv = 8192.0 * (float)(((int)vid.height>>1)-v) / temp;
  48.  
  49.     end[0] = 4096*vpn[0] + wu*vright[0] + wv*vup[0];
  50.     end[1] = 4096*vpn[1] + wu*vright[1] + wv*vup[1];
  51.     end[2] = 4096*vpn[2] + wu*vright[2] + wv*vup[2];
  52.     end[2] *= 3;
  53.     VectorNormalize (end);
  54.  
  55.     temp = skytime*skyspeed;    // TODO: add D_SetupFrame & set this there
  56.     *s = (int)((temp + 6*(SKYSIZE/2-1)*end[0]) * 0x10000);
  57.     *t = (int)((temp + 6*(SKYSIZE/2-1)*end[1]) * 0x10000);
  58. }
  59.  
  60. #endif
  61.  
  62. #if !id68k
  63. /*
  64. =================
  65. D_DrawSkyScans8
  66. =================
  67. */
  68. void D_DrawSkyScans8 (espan_t *pspan)
  69. {
  70.     int                count, spancount, u, v;
  71.     unsigned char    *pdest;
  72.     fixed16_t        s, t, snext, tnext, sstep, tstep;
  73.     int                spancountminus1;
  74.  
  75.     sstep = 0;    // keep compiler happy
  76.     tstep = 0;    // ditto
  77.  
  78.     do
  79.     {
  80.         pdest = (unsigned char *)((byte *)d_viewbuffer +
  81.                 (screenwidth * pspan->v) + pspan->u);
  82.  
  83.         count = pspan->count;
  84.  
  85.     // calculate the initial s & t
  86.         u = pspan->u;
  87.         v = pspan->v;
  88.         D_Sky_uv_To_st (u, v, &s, &t);
  89.  
  90.         do
  91.         {
  92.             if (count >= SKY_SPAN_MAX)
  93.                 spancount = SKY_SPAN_MAX;
  94.             else
  95.                 spancount = count;
  96.  
  97.             count -= spancount;
  98.  
  99.             if (count)
  100.             {
  101.                 u += spancount;
  102.  
  103.             // calculate s and t at far end of span,
  104.             // calculate s and t steps across span by shifting
  105.                 D_Sky_uv_To_st (u, v, &snext, &tnext);
  106.  
  107.                 sstep = (snext - s) >> SKY_SPAN_SHIFT;
  108.                 tstep = (tnext - t) >> SKY_SPAN_SHIFT;
  109.             }
  110.             else
  111.             {
  112.             // calculate s and t at last pixel in span,
  113.             // calculate s and t steps across span by division
  114.                 spancountminus1 = (float)(spancount - 1);
  115.  
  116.                 if (spancountminus1 > 0)
  117.                 {
  118.                     u += spancountminus1;
  119.                     D_Sky_uv_To_st (u, v, &snext, &tnext);
  120.  
  121.                     sstep = (snext - s) / spancountminus1;
  122.                     tstep = (tnext - t) / spancountminus1;
  123.                 }
  124.             }
  125.  
  126.             do
  127.             {
  128.                 *pdest++ = r_skysource[((t & R_SKY_TMASK) >> 8) +
  129.                         ((s & R_SKY_SMASK) >> 16)];
  130.                 s += sstep;
  131.                 t += tstep;
  132.             } while (--spancount > 0);
  133.  
  134.             s = snext;
  135.             t = tnext;
  136.  
  137.         } while (count > 0);
  138.  
  139.     } while ((pspan = pspan->pnext) != NULL);
  140. }
  141.  
  142. #endif
  143.