mirror of
https://github.com/fabiangreffrath/woof.git
synced 2025-09-23 03:52:12 -04:00
FOV adjustments for skies (#1474)
* Refactor FOV (again) * FOV affects `linearskyangle` calculations * FOV affects sky scale calculations * Apply fade to color for stretched skies To prevent tiling at a large FOV.
This commit is contained in:
parent
0c8600b07c
commit
bdd1deef59
45
src/r_main.c
45
src/r_main.c
@ -50,6 +50,7 @@ int centerx, centery;
|
|||||||
fixed_t centerxfrac, centeryfrac;
|
fixed_t centerxfrac, centeryfrac;
|
||||||
fixed_t focallength;
|
fixed_t focallength;
|
||||||
fixed_t projection;
|
fixed_t projection;
|
||||||
|
fixed_t skyiscale;
|
||||||
fixed_t viewx, viewy, viewz;
|
fixed_t viewx, viewy, viewz;
|
||||||
angle_t viewangle;
|
angle_t viewangle;
|
||||||
localview_t localview;
|
localview_t localview;
|
||||||
@ -260,8 +261,10 @@ static fixed_t centerxfrac_nonwide;
|
|||||||
static void R_InitTextureMapping(void)
|
static void R_InitTextureMapping(void)
|
||||||
{
|
{
|
||||||
register int i,x;
|
register int i,x;
|
||||||
|
double angle; // tan angle with offset applied like vanilla R_InitTables().
|
||||||
fixed_t slopefrac;
|
fixed_t slopefrac;
|
||||||
angle_t fov;
|
angle_t fov;
|
||||||
|
double slopebam;
|
||||||
|
|
||||||
// Use tangent table to generate viewangletox:
|
// Use tangent table to generate viewangletox:
|
||||||
// viewangletox will give the next greatest x
|
// viewangletox will give the next greatest x
|
||||||
@ -270,31 +273,32 @@ static void R_InitTextureMapping(void)
|
|||||||
// Calc focallength
|
// Calc focallength
|
||||||
// so FIELDOFVIEW angles covers SCREENWIDTH.
|
// so FIELDOFVIEW angles covers SCREENWIDTH.
|
||||||
|
|
||||||
if (custom_fov != FOV_DEFAULT)
|
if (custom_fov == FOV_DEFAULT)
|
||||||
{
|
{
|
||||||
const double slope = (tan(custom_fov * M_PI / 360.0) *
|
slopefrac = finetangent[FINEANGLES / 4 + FIELDOFVIEW / 2];
|
||||||
centerxfrac / centerxfrac_nonwide);
|
|
||||||
const double angle = atan(slope) + M_PI / FINEANGLES; // finetangent offset.
|
|
||||||
fov = angle * FINEANGLES / M_PI;
|
|
||||||
slopefrac = tan(angle) * FRACUNIT;
|
|
||||||
focallength = FixedDiv(centerxfrac, slopefrac);
|
|
||||||
projection = centerxfrac / slope;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fov = FIELDOFVIEW;
|
|
||||||
slopefrac = finetangent[FINEANGLES / 4 + fov / 2];
|
|
||||||
focallength = FixedDiv(centerxfrac_nonwide, slopefrac);
|
focallength = FixedDiv(centerxfrac_nonwide, slopefrac);
|
||||||
projection = centerxfrac_nonwide;
|
projection = centerxfrac_nonwide;
|
||||||
|
|
||||||
if (centerxfrac != centerxfrac_nonwide)
|
if (centerxfrac == centerxfrac_nonwide)
|
||||||
|
{
|
||||||
|
angle = (FIELDOFVIEW / 2.0 + 0.5) * 2.0 * M_PI / FINEANGLES;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
const double slope = (double)centerxfrac / centerxfrac_nonwide;
|
const double slope = (double)centerxfrac / centerxfrac_nonwide;
|
||||||
const double angle = atan(slope) + M_PI / FINEANGLES; // finetangent offset.
|
angle = atan(slope) + M_PI / FINEANGLES;
|
||||||
fov = angle * FINEANGLES / M_PI;
|
|
||||||
slopefrac = tan(angle) * FRACUNIT;
|
slopefrac = tan(angle) * FRACUNIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const double slope = (tan(custom_fov * M_PI / 360.0) *
|
||||||
|
centerxfrac / centerxfrac_nonwide);
|
||||||
|
angle = atan(slope) + M_PI / FINEANGLES;
|
||||||
|
slopefrac = tan(angle) * FRACUNIT;
|
||||||
|
focallength = FixedDiv(centerxfrac, slopefrac);
|
||||||
|
projection = centerxfrac / slope;
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0 ; i<FINEANGLES/2 ; i++)
|
for (i=0 ; i<FINEANGLES/2 ; i++)
|
||||||
{
|
{
|
||||||
@ -321,13 +325,15 @@ static void R_InitTextureMapping(void)
|
|||||||
// xtoviewangle will give the smallest view angle
|
// xtoviewangle will give the smallest view angle
|
||||||
// that maps to x.
|
// that maps to x.
|
||||||
|
|
||||||
|
slopebam = tan(angle) * ANG90;
|
||||||
|
|
||||||
for (x=0; x<=viewwidth; x++)
|
for (x=0; x<=viewwidth; x++)
|
||||||
{
|
{
|
||||||
for (i=0; viewangletox[i] > x; i++)
|
for (i=0; viewangletox[i] > x; i++)
|
||||||
;
|
;
|
||||||
xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90;
|
xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90;
|
||||||
// [FG] linear horizontal sky scrolling
|
// [FG] linear horizontal sky scrolling
|
||||||
linearskyangle[x] = ((viewwidth/2-x)*((video.unscaledw<<FRACBITS)/viewwidth))*(ANG90/(NONWIDEWIDTH<<FRACBITS));
|
linearskyangle[x] = (0.5 - x / (double)viewwidth) * slopebam;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take out the fencepost cases from viewangletox.
|
// Take out the fencepost cases from viewangletox.
|
||||||
@ -340,7 +346,8 @@ static void R_InitTextureMapping(void)
|
|||||||
|
|
||||||
clipangle = xtoviewangle[0];
|
clipangle = xtoviewangle[0];
|
||||||
|
|
||||||
vx_clipangle = clipangle - ((fov << ANGLETOFINESHIFT) - ANG90);
|
fov = angle * ANGLE_MAX / M_PI;
|
||||||
|
vx_clipangle = clipangle - (fov - ANG90);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -581,6 +588,8 @@ void R_ExecuteSetViewSize (void)
|
|||||||
pspritescale = FixedDiv(viewwidth_nonwide, SCREENWIDTH); // killough 11/98
|
pspritescale = FixedDiv(viewwidth_nonwide, SCREENWIDTH); // killough 11/98
|
||||||
pspriteiscale = FixedDiv(SCREENWIDTH, viewwidth_nonwide) + 1; // killough 11/98
|
pspriteiscale = FixedDiv(SCREENWIDTH, viewwidth_nonwide) + 1; // killough 11/98
|
||||||
|
|
||||||
|
skyiscale = FixedDiv(160 << FRACBITS, focallength);
|
||||||
|
|
||||||
for (i=0 ; i<viewwidth ; i++)
|
for (i=0 ; i<viewwidth ; i++)
|
||||||
{
|
{
|
||||||
fixed_t cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]);
|
fixed_t cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]);
|
||||||
|
@ -39,6 +39,7 @@ extern fixed_t centerxfrac;
|
|||||||
extern fixed_t centeryfrac;
|
extern fixed_t centeryfrac;
|
||||||
extern fixed_t focallength;
|
extern fixed_t focallength;
|
||||||
extern fixed_t projection;
|
extern fixed_t projection;
|
||||||
|
extern fixed_t skyiscale;
|
||||||
extern int validcount;
|
extern int validcount;
|
||||||
extern int linecount;
|
extern int linecount;
|
||||||
extern int loopcount;
|
extern int loopcount;
|
||||||
|
@ -390,6 +390,7 @@ static void do_draw_plane(visplane_t *pl)
|
|||||||
int texture;
|
int texture;
|
||||||
angle_t an, flip;
|
angle_t an, flip;
|
||||||
boolean vertically_scrolling = false;
|
boolean vertically_scrolling = false;
|
||||||
|
boolean stretch;
|
||||||
|
|
||||||
// killough 10/98: allow skies to come from sidedefs.
|
// killough 10/98: allow skies to come from sidedefs.
|
||||||
// Allows scrolling and/or animated skies, as well as
|
// Allows scrolling and/or animated skies, as well as
|
||||||
@ -447,19 +448,22 @@ static void do_draw_plane(visplane_t *pl)
|
|||||||
dc_colormap[0] = dc_colormap[1] = fullcolormap; // killough 3/20/98
|
dc_colormap[0] = dc_colormap[1] = fullcolormap; // killough 3/20/98
|
||||||
|
|
||||||
dc_texheight = textureheight[texture]>>FRACBITS; // killough
|
dc_texheight = textureheight[texture]>>FRACBITS; // killough
|
||||||
dc_iscale = pspriteiscale;
|
dc_iscale = skyiscale;
|
||||||
|
|
||||||
// [FG] stretch short skies
|
// [FG] stretch short skies
|
||||||
if (stretchsky && dc_texheight < 200)
|
stretch = (stretchsky && dc_texheight < 200);
|
||||||
{
|
if (stretch || !vertically_scrolling)
|
||||||
dc_iscale = dc_iscale * dc_texheight / SKYSTRETCH_HEIGHT;
|
|
||||||
dc_texturemid = dc_texturemid * dc_texheight / SKYSTRETCH_HEIGHT;
|
|
||||||
colfunc = R_DrawColumn;
|
|
||||||
}
|
|
||||||
else if (!vertically_scrolling)
|
|
||||||
{
|
{
|
||||||
|
fixed_t diff;
|
||||||
|
|
||||||
|
if (stretch)
|
||||||
|
{
|
||||||
|
dc_iscale = dc_iscale * dc_texheight / SKYSTRETCH_HEIGHT;
|
||||||
|
dc_texturemid = dc_texturemid * dc_texheight / SKYSTRETCH_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the fade-to-color effect doesn't happen too early
|
// Make sure the fade-to-color effect doesn't happen too early
|
||||||
fixed_t diff = dc_texturemid - SCREENHEIGHT / 2 * FRACUNIT;
|
diff = dc_texturemid - SCREENHEIGHT / 2 * FRACUNIT;
|
||||||
if (diff < 0)
|
if (diff < 0)
|
||||||
{
|
{
|
||||||
diff += textureheight[texture];
|
diff += textureheight[texture];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user