From 027b8d29b8cf5b976cfe5cdea07e021a94b80370 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 28 Apr 2016 13:59:06 +0200 Subject: [PATCH] - make FieldOfView a real angle and remove all uses of finetangent. --- src/r_main.cpp | 4 ++-- src/r_sky.cpp | 4 ++-- src/r_state.h | 2 +- src/r_swrenderer.cpp | 6 ++---- src/r_utility.cpp | 47 +++++++++++--------------------------------- src/r_utility.h | 3 +-- src/tables.cpp | 8 -------- src/tables.h | 7 ------- 8 files changed, 19 insertions(+), 62 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index 3996ee9c9..5eb2e44f8 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -179,7 +179,7 @@ static inline int viewangletox(int i) // Don't waste time calculating the tangent of values outside the valid range. // Checking the index where tan(i) becomes too large is a lot faster - if (i <= 604) // 604 is the highest index with finetangent < -2*FRACUNIT + if (i <= 604) // 604 is the highest index with tan < -2 { return viewwidth + 1; } @@ -207,7 +207,7 @@ void R_InitTextureMapping () FocalLengthY = FocalLengthX * YaspectMul; // This is 1/FocalTangent before the widescreen extension of FOV. - viewingrangerecip = DivScale32(1, finetangent[FINEANGLES/4+(FieldOfView/2)]); + viewingrangerecip = FLOAT2FIXED(1. / tan(FieldOfView.Radians() / 2)); // [RH] Do not generate viewangletox, because texture mapping is no // longer done with trig, so it's not needed. diff --git a/src/r_sky.cpp b/src/r_sky.cpp index 0e0bc412a..9ea44db48 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -115,8 +115,8 @@ void R_InitSkyMap () skyiscale = float(r_Yaspect / freelookviewheight); skyscale = freelookviewheight / r_Yaspect; - skyiscale *= FieldOfView / 2048.f; - skyscale *= 2048.0 / FieldOfView; + skyiscale *= float(FieldOfView.Degrees / 90.); + skyscale *= float(90. / FieldOfView.Degrees); } if (skystretch) diff --git a/src/r_state.h b/src/r_state.h index 5a5501465..fe3a21060 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -82,7 +82,7 @@ extern AActor* camera; // [RH] camera instead of viewplayer extern sector_t* viewsector; // [RH] keep track of sector viewing from extern angle_t xtoviewangle[MAXWIDTH+1]; -extern int FieldOfView; +extern DAngle FieldOfView; int R_FindSkin (const char *name, int pclass); // [RH] Find a skin diff --git a/src/r_swrenderer.cpp b/src/r_swrenderer.cpp index 7eb1e13e9..d563986f7 100644 --- a/src/r_swrenderer.cpp +++ b/src/r_swrenderer.cpp @@ -50,8 +50,6 @@ void R_SetupColormap(player_t *); void R_SetupFreelook(); void R_InitRenderer(); -extern float LastFOV; - //========================================================================== // // DCanvas :: Init @@ -272,8 +270,8 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin unsigned char *savecolormap = fixedcolormap; FSpecialColormap *savecm = realfixedcolormap; - float savedfov = LastFOV; - R_SetFOV ((float)fov); + DAngle savedfov = FieldOfView; + R_SetFOV ((double)fov); R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); R_SetFOV (savedfov); if (Pixels == Canvas->GetBuffer()) diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 2374c9eea..c145998b7 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -138,7 +138,6 @@ angle_t LocalViewAngle; int LocalViewPitch; bool LocalKeyboardTurner; -float LastFOV; int WidescreenRatio; int setblocks; int extralight; @@ -147,7 +146,7 @@ double FocalTangent; unsigned int R_OldBlend = ~0; int validcount = 1; // increment every time a check is made -int FieldOfView = 2048; // Fineangles in the SCREENWIDTH wide window +DAngle FieldOfView = 90.; // Angles in the SCREENWIDTH wide window FCanvasTextureInfo *FCanvasTextureInfo::List; @@ -169,13 +168,6 @@ void R_InitTables (void) int i; const double pimul = M_PI*2/FINEANGLES; - // viewangle tangent table - finetangent[0] = (fixed_t)(FRACUNIT*g_tan ((0.5-FINEANGLES/4)*pimul)+0.5); - for (i = 1; i < FINEANGLES/2; i++) - { - finetangent[i] = (fixed_t)(FRACUNIT*g_tan ((i-FINEANGLES/4)*pimul)+0.5); - } - // finesine table for (i = 0; i < FINEANGLES/4; i++) { @@ -202,33 +194,18 @@ void R_InitTables (void) // //========================================================================== -void R_SetFOV (float fov) +void R_SetFOV (DAngle fov) { - if (fov < 5.f) - fov = 5.f; - else if (fov > 170.f) - fov = 170.f; - if (fov != LastFOV) + + if (fov < 5.) fov = 5.; + else if (fov > 170.) fov = 170.; + if (fov != FieldOfView) { - LastFOV = fov; - FieldOfView = (int)(fov * (float)FINEANGLES / 360.f); + FieldOfView = fov; setsizeneeded = true; } } -//========================================================================== -// -// R_GetFOV -// -// Returns the current field of view in degrees -// -//========================================================================== - -float R_GetFOV () -{ - return LastFOV; -} - //========================================================================== // // R_SetViewSize @@ -292,18 +269,16 @@ void R_SetWindow (int windowSize, int fullWidth, int fullHeight, int stHeight) } - int fov = FieldOfView; + DAngle fov = FieldOfView; // For widescreen displays, increase the FOV so that the middle part of the // screen that would be visible on a 4:3 display has the requested FOV. if (centerxwide != centerx) { // centerxwide is what centerx would be if the display was not widescreen - fov = int(atan(double(centerx)*tan(double(fov)*M_PI/(FINEANGLES))/double(centerxwide))*(FINEANGLES)/M_PI); - if (fov > 170*FINEANGLES/360) - fov = 170*FINEANGLES/360; + fov = DAngle::ToDegrees(2 * atan(centerx * tan(fov.Radians()/2) / double(centerxwide))); + if (fov > 170.) fov = 170.; } - - FocalTangent = FIXED2FLOAT(finetangent[FINEANGLES/4+fov/2]); + FocalTangent = tan(fov.Radians() / 2); Renderer->SetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio); } diff --git a/src/r_utility.h b/src/r_utility.h index f15d42052..8cabfa600 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -85,8 +85,7 @@ bool R_GetViewInterpolationStatus(); void R_ClearInterpolationPath(); void R_AddInterpolationPoint(const DVector3a &vec); void R_SetViewSize (int blocks); -void R_SetFOV (float fov); -float R_GetFOV (); +void R_SetFOV (DAngle fov); void R_SetupFrame (AActor * camera); void R_SetViewAngle (); diff --git a/src/tables.cpp b/src/tables.cpp index 9679e8547..9a88a9715 100644 --- a/src/tables.cpp +++ b/src/tables.cpp @@ -19,22 +19,14 @@ // Do not try to look them up :-). // In the order of appearance: // -// int finetangent[4096] - Tangens LUT. -// Should work with BAM fairly well (12 of 16bit, -// effectively, by shifting). -// // int finesine[10240] - Sine lookup. // Guess what, serves as cosine, too. // Remarkable thing is, how to use BAMs with this? -// -// int tantoangle[2049] - ArcTan LUT, -// maps tan(angle) to angle fast. Gotta search. // // //----------------------------------------------------------------------------- #include "tables.h" -fixed_t finetangent[4096]; fixed_t finesine[10240]; diff --git a/src/tables.h b/src/tables.h index e2cf93e63..1b2868a54 100644 --- a/src/tables.h +++ b/src/tables.h @@ -19,10 +19,6 @@ // Do not try to look them up :-). // In the order of appearance: // -// int finetangent[4096] - Tangens LUT. -// Should work with BAM fairly well (12 of 16bit, -// effectively, by shifting). -// // int finesine[10240] - Sine lookup. // Remarkable thing is, how to use BAMs with this? // @@ -46,9 +42,6 @@ // Effective size is 10240. extern fixed_t finesine[5*FINEANGLES/4]; -// Effective size is 4096. -extern fixed_t finetangent[FINEANGLES/2]; - // Binary Angle Measument, BAM. #define ANGLE_90 (0x40000000) #define ANGLE_180 (0x80000000)