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.
26 #define SKY_SPAN_SHIFT 5
27 #define SKY_SPAN_MAX (1 << SKY_SPAN_SHIFT)
35 void D_Sky_uv_To_st (int u
, int v
, fixed16_t
*s
, fixed16_t
*t
)
40 if (r_refdef
.vrect
.width
>= r_refdef
.vrect
.height
)
41 temp
= (float)r_refdef
.vrect
.width
;
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];
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);
65 void D_DrawSkyScans8 (espan_t
*pspan
)
67 int count
, spancount
, u
, v
;
69 fixed16_t s
, t
, snext
, tnext
, sstep
, tstep
;
72 sstep
= 0; // keep compiler happy
77 pdest
= (unsigned char *)((byte
*)d_viewbuffer
+
78 (screenwidth
* pspan
->v
) + pspan
->u
);
82 // calculate the initial s & t
85 D_Sky_uv_To_st (u
, v
, &s
, &t
);
89 if (count
>= SKY_SPAN_MAX
)
90 spancount
= SKY_SPAN_MAX
;
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
;
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)];
129 } while (--spancount
> 0);
136 } while ((pspan
= pspan
->pnext
) != NULL
);