home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / d_sky.c < prev    next >
C/C++ Source or Header  |  2000-06-17  |  3KB  |  140 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. #if !defined(M68KASM) && !defined(PPCASM)
  23. #include "quakedef.h"
  24. #include "r_local.h"
  25. #include "d_local.h"
  26.  
  27. #define SKY_SPAN_SHIFT  5
  28. #define SKY_SPAN_MAX  (1 << SKY_SPAN_SHIFT)
  29.  
  30.  
  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.  
  61. /*
  62. =================
  63. D_DrawSkyScans8
  64. =================
  65. */
  66. void D_DrawSkyScans8 (espan_t *pspan)
  67. {
  68.   int       count, spancount, u, v;
  69.   unsigned char *pdest;
  70.   fixed16_t   s, t, snext, tnext, sstep, tstep;
  71.   int       spancountminus1;
  72.  
  73.   sstep = 0;  // keep compiler happy
  74.   tstep = 0;  // ditto
  75.  
  76.   do
  77.   {
  78.     pdest = (unsigned char *)((byte *)d_viewbuffer +
  79.         (screenwidth * pspan->v) + pspan->u);
  80.  
  81.     count = pspan->count;
  82.  
  83.   // calculate the initial s & t
  84.     u = pspan->u;
  85.     v = pspan->v;
  86.     D_Sky_uv_To_st (u, v, &s, &t);
  87.  
  88.     do
  89.     {
  90.       if (count >= SKY_SPAN_MAX)
  91.         spancount = SKY_SPAN_MAX;
  92.       else
  93.         spancount = count;
  94.  
  95.       count -= spancount;
  96.  
  97.       if (count)
  98.       {
  99.         u += spancount;
  100.  
  101.       // calculate s and t at far end of span,
  102.       // calculate s and t steps across span by shifting
  103.         D_Sky_uv_To_st (u, v, &snext, &tnext);
  104.  
  105.         sstep = (snext - s) >> SKY_SPAN_SHIFT;
  106.         tstep = (tnext - t) >> SKY_SPAN_SHIFT;
  107.       }
  108.       else
  109.       {
  110.       // calculate s and t at last pixel in span,
  111.       // calculate s and t steps across span by division
  112.         spancountminus1 = (float)(spancount - 1);
  113.  
  114.         if (spancountminus1 > 0)
  115.         {
  116.           u += spancountminus1;
  117.           D_Sky_uv_To_st (u, v, &snext, &tnext);
  118.  
  119.           sstep = (snext - s) / spancountminus1;
  120.           tstep = (tnext - t) / spancountminus1;
  121.         }
  122.       }
  123.  
  124.       do
  125.       {
  126.         *pdest++ = r_skysource[((t & R_SKY_TMASK) >> 8) +
  127.             ((s & R_SKY_SMASK) >> 16)];
  128.         s += sstep;
  129.         t += tstep;
  130.       } while (--spancount > 0);
  131.  
  132.       s = snext;
  133.       t = tnext;
  134.  
  135.     } while (count > 0);
  136.  
  137.   } while ((pspan = pspan->pnext) != NULL);
  138. }
  139. #endif
  140.