diff --git a/src/r_main.c b/src/r_main.c index 9223a0a3..00ed7491 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -48,6 +48,7 @@ int validcount = 1; // increment every time a check is made lighttable_t *fixedcolormap; int centerx, centery; fixed_t centerxfrac, centeryfrac; +fixed_t focallength; fixed_t projection; fixed_t viewx, viewy, viewz; angle_t viewangle; @@ -259,7 +260,7 @@ static fixed_t centerxfrac_nonwide; static void R_InitTextureMapping(void) { register int i,x; - fixed_t focallength, slopefrac; + fixed_t slopefrac; angle_t fov; // Use tangent table to generate viewangletox: @@ -273,8 +274,9 @@ static void R_InitTextureMapping(void) { const double slope = (tan(custom_fov * M_PI / 360.0) * centerxfrac / centerxfrac_nonwide); - fov = atan(slope) * FINEANGLES / M_PI; - slopefrac = finetangent[FINEANGLES / 4 + fov / 2]; + 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; } @@ -285,10 +287,12 @@ static void R_InitTextureMapping(void) focallength = FixedDiv(centerxfrac_nonwide, slopefrac); projection = centerxfrac_nonwide; - if (widescreen != RATIO_ORIG) + if (centerxfrac != centerxfrac_nonwide) { - fov = atan((double)centerxfrac / centerxfrac_nonwide) * FINEANGLES / M_PI; - slopefrac = finetangent[FINEANGLES / 4 + fov / 2]; + const double slope = (double)centerxfrac / centerxfrac_nonwide; + const double angle = atan(slope) + M_PI / FINEANGLES; // finetangent offset. + fov = angle * FINEANGLES / M_PI; + slopefrac = tan(angle) * FRACUNIT; } } diff --git a/src/r_main.h b/src/r_main.h index 6dfb6b20..1c4ab2c0 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -37,6 +37,7 @@ extern int centerx; extern int centery; extern fixed_t centerxfrac; extern fixed_t centeryfrac; +extern fixed_t focallength; extern fixed_t projection; extern int validcount; extern int linecount; diff --git a/src/r_segs.c b/src/r_segs.c index ca1a6b94..99d3c9aa 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -157,7 +157,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, int x1, int x2) { if (!fixedcolormap) // calculate lighting { // killough 11/98: - unsigned index = FixedDiv(spryscale, video.xscale) >> LIGHTSCALESHIFT; + unsigned index = FixedDiv(spryscale * 160, focallength) >> LIGHTSCALESHIFT; if (index >= MAXLIGHTSCALE ) index = MAXLIGHTSCALE-1; @@ -378,7 +378,7 @@ static void R_RenderSegLoop (void) texturecolumn >>= FRACBITS; // calculate lighting - index = FixedDiv(rw_scale, video.xscale) >> LIGHTSCALESHIFT; // killough 11/98 + index = FixedDiv(rw_scale * 160, focallength) >> LIGHTSCALESHIFT; if (index >= MAXLIGHTSCALE ) index = MAXLIGHTSCALE-1; diff --git a/src/r_things.c b/src/r_things.c index 7ba025d1..7a8b9a32 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -664,7 +664,7 @@ void R_ProjectSprite (mobj_t* thing) vis->colormap[0] = vis->colormap[1] = fullcolormap; // full bright // killough 3/20/98 else { // diminished light - int index = FixedDiv(xscale, video.xscale) >> LIGHTSCALESHIFT; // killough 11/98 + int index = FixedDiv(xscale * 160, focallength) >> LIGHTSCALESHIFT; if (index >= MAXLIGHTSCALE) index = MAXLIGHTSCALE-1; vis->colormap[0] = spritelights[index]; diff --git a/src/r_voxel.c b/src/r_voxel.c index ac3d1ec3..bed1736f 100644 --- a/src/r_voxel.c +++ b/src/r_voxel.c @@ -724,7 +724,7 @@ boolean VX_ProjectVoxel (mobj_t * thing) else { // diminished light - int index = FixedDiv(xscale, video.xscale) >> LIGHTSCALESHIFT; // killough 11/98 + int index = FixedDiv(xscale * 160, focallength) >> LIGHTSCALESHIFT; if (index < 0) index = 0; if (index > MAXLIGHTSCALE-1) index = MAXLIGHTSCALE-1;