- make FieldOfView a real angle and remove all uses of finetangent.

This commit is contained in:
Christoph Oelckers 2016-04-28 13:59:06 +02:00
parent f301cf7c57
commit 027b8d29b8
8 changed files with 19 additions and 62 deletions

View file

@ -179,7 +179,7 @@ static inline int viewangletox(int i)
// Don't waste time calculating the tangent of values outside the valid range. // 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 // 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; return viewwidth + 1;
} }
@ -207,7 +207,7 @@ void R_InitTextureMapping ()
FocalLengthY = FocalLengthX * YaspectMul; FocalLengthY = FocalLengthX * YaspectMul;
// This is 1/FocalTangent before the widescreen extension of FOV. // 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 // [RH] Do not generate viewangletox, because texture mapping is no
// longer done with trig, so it's not needed. // longer done with trig, so it's not needed.

View file

@ -115,8 +115,8 @@ void R_InitSkyMap ()
skyiscale = float(r_Yaspect / freelookviewheight); skyiscale = float(r_Yaspect / freelookviewheight);
skyscale = freelookviewheight / r_Yaspect; skyscale = freelookviewheight / r_Yaspect;
skyiscale *= FieldOfView / 2048.f; skyiscale *= float(FieldOfView.Degrees / 90.);
skyscale *= 2048.0 / FieldOfView; skyscale *= float(90. / FieldOfView.Degrees);
} }
if (skystretch) if (skystretch)

View file

@ -82,7 +82,7 @@ extern AActor* camera; // [RH] camera instead of viewplayer
extern sector_t* viewsector; // [RH] keep track of sector viewing from extern sector_t* viewsector; // [RH] keep track of sector viewing from
extern angle_t xtoviewangle[MAXWIDTH+1]; extern angle_t xtoviewangle[MAXWIDTH+1];
extern int FieldOfView; extern DAngle FieldOfView;
int R_FindSkin (const char *name, int pclass); // [RH] Find a skin int R_FindSkin (const char *name, int pclass); // [RH] Find a skin

View file

@ -50,8 +50,6 @@ void R_SetupColormap(player_t *);
void R_SetupFreelook(); void R_SetupFreelook();
void R_InitRenderer(); void R_InitRenderer();
extern float LastFOV;
//========================================================================== //==========================================================================
// //
// DCanvas :: Init // DCanvas :: Init
@ -272,8 +270,8 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
unsigned char *savecolormap = fixedcolormap; unsigned char *savecolormap = fixedcolormap;
FSpecialColormap *savecm = realfixedcolormap; FSpecialColormap *savecm = realfixedcolormap;
float savedfov = LastFOV; DAngle savedfov = FieldOfView;
R_SetFOV ((float)fov); R_SetFOV ((double)fov);
R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); R_RenderViewToCanvas (viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate);
R_SetFOV (savedfov); R_SetFOV (savedfov);
if (Pixels == Canvas->GetBuffer()) if (Pixels == Canvas->GetBuffer())

View file

@ -138,7 +138,6 @@ angle_t LocalViewAngle;
int LocalViewPitch; int LocalViewPitch;
bool LocalKeyboardTurner; bool LocalKeyboardTurner;
float LastFOV;
int WidescreenRatio; int WidescreenRatio;
int setblocks; int setblocks;
int extralight; int extralight;
@ -147,7 +146,7 @@ double FocalTangent;
unsigned int R_OldBlend = ~0; unsigned int R_OldBlend = ~0;
int validcount = 1; // increment every time a check is made 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; FCanvasTextureInfo *FCanvasTextureInfo::List;
@ -169,13 +168,6 @@ void R_InitTables (void)
int i; int i;
const double pimul = M_PI*2/FINEANGLES; 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 // finesine table
for (i = 0; i < FINEANGLES/4; i++) 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; if (fov < 5.) fov = 5.;
else if (fov > 170.f) else if (fov > 170.) fov = 170.;
fov = 170.f; if (fov != FieldOfView)
if (fov != LastFOV)
{ {
LastFOV = fov; FieldOfView = fov;
FieldOfView = (int)(fov * (float)FINEANGLES / 360.f);
setsizeneeded = true; setsizeneeded = true;
} }
} }
//==========================================================================
//
// R_GetFOV
//
// Returns the current field of view in degrees
//
//==========================================================================
float R_GetFOV ()
{
return LastFOV;
}
//========================================================================== //==========================================================================
// //
// R_SetViewSize // 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 // 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. // screen that would be visible on a 4:3 display has the requested FOV.
if (centerxwide != centerx) if (centerxwide != centerx)
{ // centerxwide is what centerx would be if the display was not widescreen { // 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); fov = DAngle::ToDegrees(2 * atan(centerx * tan(fov.Radians()/2) / double(centerxwide)));
if (fov > 170*FINEANGLES/360) if (fov > 170.) fov = 170.;
fov = 170*FINEANGLES/360;
} }
FocalTangent = tan(fov.Radians() / 2);
FocalTangent = FIXED2FLOAT(finetangent[FINEANGLES/4+fov/2]);
Renderer->SetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio); Renderer->SetWindow(windowSize, fullWidth, fullHeight, stHeight, trueratio);
} }

View file

@ -85,8 +85,7 @@ bool R_GetViewInterpolationStatus();
void R_ClearInterpolationPath(); void R_ClearInterpolationPath();
void R_AddInterpolationPoint(const DVector3a &vec); void R_AddInterpolationPoint(const DVector3a &vec);
void R_SetViewSize (int blocks); void R_SetViewSize (int blocks);
void R_SetFOV (float fov); void R_SetFOV (DAngle fov);
float R_GetFOV ();
void R_SetupFrame (AActor * camera); void R_SetupFrame (AActor * camera);
void R_SetViewAngle (); void R_SetViewAngle ();

View file

@ -19,22 +19,14 @@
// Do not try to look them up :-). // Do not try to look them up :-).
// In the order of appearance: // 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. // int finesine[10240] - Sine lookup.
// Guess what, serves as cosine, too. // Guess what, serves as cosine, too.
// Remarkable thing is, how to use BAMs with this? // 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" #include "tables.h"
fixed_t finetangent[4096];
fixed_t finesine[10240]; fixed_t finesine[10240];

View file

@ -19,10 +19,6 @@
// Do not try to look them up :-). // Do not try to look them up :-).
// In the order of appearance: // 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. // int finesine[10240] - Sine lookup.
// Remarkable thing is, how to use BAMs with this? // Remarkable thing is, how to use BAMs with this?
// //
@ -46,9 +42,6 @@
// Effective size is 10240. // Effective size is 10240.
extern fixed_t finesine[5*FINEANGLES/4]; extern fixed_t finesine[5*FINEANGLES/4];
// Effective size is 4096.
extern fixed_t finetangent[FINEANGLES/2];
// Binary Angle Measument, BAM. // Binary Angle Measument, BAM.
#define ANGLE_90 (0x40000000) #define ANGLE_90 (0x40000000)
#define ANGLE_180 (0x80000000) #define ANGLE_180 (0x80000000)