git-svn-id: http://bladebattles.com/kurok/SVN@11 20cd92bb-ff49-0410-b73e-96a06e42c3b9
[kurok.git] / d_sky.c
blob6007b6a641747ff3593ce493274ed1ffb604c45d
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
20 // d_sky.c
22 #include "quakedef.h"
23 #include "r_local.h"
24 #include "d_local.h"
26 #define SKY_SPAN_SHIFT 5
27 #define SKY_SPAN_MAX (1 << SKY_SPAN_SHIFT)
31 =================
32 D_Sky_uv_To_st
33 =================
35 void D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t)
37 float wu, wv, temp;
38 vec3_t end;
40 if (r_refdef.vrect.width >= r_refdef.vrect.height)
41 temp = (float)r_refdef.vrect.width;
42 else
43 temp = (float)r_refdef.vrect.height;
45 wu = 8192.0 * (float)(u-((int)vid.width>>1)) / temp;
46 wv = 8192.0 * (float)(((int)vid.height>>1)-v) / temp;
48 end[0] = 4096*vpn[0] + wu*vright[0] + wv*vup[0];
49 end[1] = 4096*vpn[1] + wu*vright[1] + wv*vup[1];
50 end[2] = 4096*vpn[2] + wu*vright[2] + wv*vup[2];
51 end[2] *= 3;
52 VectorNormalize (end);
54 temp = skytime*skyspeed; // TODO: add D_SetupFrame & set this there
55 *s = (int)((temp + 6*(SKYSIZE/2-1)*end[0]) * 0x10000);
56 *t = (int)((temp + 6*(SKYSIZE/2-1)*end[1]) * 0x10000);
61 =================
62 D_DrawSkyScans8
63 =================
65 void D_DrawSkyScans8 (espan_t *pspan)
67 int count, spancount, u, v;
68 unsigned char *pdest;
69 fixed16_t s, t, snext, tnext, sstep, tstep;
70 int spancountminus1;
72 sstep = 0; // keep compiler happy
73 tstep = 0; // ditto
77 pdest = (unsigned char *)((byte *)d_viewbuffer +
78 (screenwidth * pspan->v) + pspan->u);
80 count = pspan->count;
82 // calculate the initial s & t
83 u = pspan->u;
84 v = pspan->v;
85 D_Sky_uv_To_st (u, v, &s, &t);
89 if (count >= SKY_SPAN_MAX)
90 spancount = SKY_SPAN_MAX;
91 else
92 spancount = count;
94 count -= spancount;
96 if (count)
98 u += spancount;
100 // calculate s and t at far end of span,
101 // calculate s and t steps across span by shifting
102 D_Sky_uv_To_st (u, v, &snext, &tnext);
104 sstep = (snext - s) >> SKY_SPAN_SHIFT;
105 tstep = (tnext - t) >> SKY_SPAN_SHIFT;
107 else
109 // calculate s and t at last pixel in span,
110 // calculate s and t steps across span by division
111 spancountminus1 = (float)(spancount - 1);
113 if (spancountminus1 > 0)
115 u += spancountminus1;
116 D_Sky_uv_To_st (u, v, &snext, &tnext);
118 sstep = (snext - s) / spancountminus1;
119 tstep = (tnext - t) / spancountminus1;
125 *pdest++ = r_skysource[((t & R_SKY_TMASK) >> 8) +
126 ((s & R_SKY_SMASK) >> 16)];
127 s += sstep;
128 t += tstep;
129 } while (--spancount > 0);
131 s = snext;
132 t = tnext;
134 } while (count > 0);
136 } while ((pspan = pspan->pnext) != NULL);