- moved the aspect ratio correction factor from the projection to the view matrix where it should have been from the start.

- removed the mCameraPos variable in FGLRenderer because it was only used in one place where it is just as easy to use the global viewx/y/z variables directly.
This commit is contained in:
Christoph Oelckers 2014-12-29 22:42:19 +01:00
parent 045725de15
commit 45cf65afbd
3 changed files with 13 additions and 16 deletions

View file

@ -90,7 +90,6 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
mLightCount = 0;
mAngles = FRotator(0,0,0);
mViewVector = FVector2(0,0);
mCameraPos = FVector3(0,0,0);
mVBO = NULL;
mSkyVBO = NULL;
gl_spriteindex = 0;

View file

@ -67,7 +67,6 @@ public:
FRotator mAngles;
FVector2 mViewVector;
FVector3 mCameraPos;
FFlatVertexBuffer *mVBO;
FSkyVertexBuffer *mSkyVBO;
@ -83,7 +82,7 @@ public:
void SetViewport(GL_IRECT *bounds);
sector_t *RenderViewpoint (AActor * camera, GL_IRECT * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen);
void RenderView(player_t *player);
void SetCameraPos(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle);
void SetViewAngle(angle_t viewangle);
void SetupView(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle, bool mirror, bool planemirror);
void Initialize();
@ -121,7 +120,7 @@ public:
void Flush() {}
void SetProjection(float fov, float ratio, float fovratio);
void SetViewMatrix(bool mirror, bool planemirror);
void SetViewMatrix(fixed_t viewx, fixed_t viewy, fixed_t viewz, bool mirror, bool planemirror);
void ProcessScene(bool toscreen = false);
bool StartOffscreen();

View file

@ -86,6 +86,7 @@ CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_aspect, 1.2f, 0)
EXTERN_CVAR (Int, screenblocks)
EXTERN_CVAR (Bool, cl_capfps)
@ -228,13 +229,12 @@ void FGLRenderer::SetViewport(GL_IRECT *bounds)
//
//-----------------------------------------------------------------------------
void FGLRenderer::SetCameraPos(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle)
void FGLRenderer::SetViewAngle(angle_t viewangle)
{
float fviewangle=(float)(viewangle>>ANGLETOFINESHIFT)*360.0f/FINEANGLES;
mAngles.Yaw = 270.0f-fviewangle;
mViewVector = FVector2(cos(DEG2RAD(fviewangle)), sin(DEG2RAD(fviewangle)));
mCameraPos = FVector3(FIXED2FLOAT(viewx), FIXED2FLOAT(viewy), FIXED2FLOAT(viewz));
R_SetViewAngle();
}
@ -261,16 +261,16 @@ void FGLRenderer::SetProjection(float fov, float ratio, float fovratio)
//
//-----------------------------------------------------------------------------
void FGLRenderer::SetViewMatrix(bool mirror, bool planemirror)
void FGLRenderer::SetViewMatrix(fixed_t viewx, fixed_t viewy, fixed_t viewz, bool mirror, bool planemirror)
{
float mult = mirror? -1:1;
float planemult = planemirror? -1:1;
float planemult = planemirror? -gl_aspect:gl_aspect;
gl_RenderState.mViewMatrix.loadIdentity();
gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Roll, 0.0f, 0.0f, 1.0f);
gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Pitch, 1.0f, 0.0f, 0.0f);
gl_RenderState.mViewMatrix.rotate(GLRenderer->mAngles.Yaw, 0.0f, mult, 0.0f);
gl_RenderState.mViewMatrix.translate( GLRenderer->mCameraPos.X * mult, -GLRenderer->mCameraPos.Z*planemult, -GLRenderer->mCameraPos.Y);
gl_RenderState.mViewMatrix.translate(FIXED2FLOAT(viewx) * mult, -FIXED2FLOAT(viewz) * planemult , -FIXED2FLOAT(viewy));
gl_RenderState.mViewMatrix.scale(-mult, planemult, 1);
}
@ -283,8 +283,8 @@ void FGLRenderer::SetViewMatrix(bool mirror, bool planemirror)
//-----------------------------------------------------------------------------
void FGLRenderer::SetupView(fixed_t viewx, fixed_t viewy, fixed_t viewz, angle_t viewangle, bool mirror, bool planemirror)
{
SetCameraPos(viewx, viewy, viewz, viewangle);
SetViewMatrix(mirror, planemirror);
SetViewAngle(viewangle);
SetViewMatrix(viewx, viewy, viewz, mirror, planemirror);
gl_RenderState.ApplyMatrices();
}
@ -795,8 +795,8 @@ sector_t * FGLRenderer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, flo
SetViewport(bounds);
mCurrentFoV = fov;
SetProjection(fov, ratio, fovratio); // switch to perspective mode and set up clipper
SetCameraPos(viewx, viewy, viewz, viewangle);
SetViewMatrix(false, false);
SetViewAngle(viewangle);
SetViewMatrix(viewx, viewy, viewz, false, false);
gl_RenderState.ApplyMatrices();
clipper.Clear();
@ -851,16 +851,15 @@ void FGLRenderer::RenderView (player_t* player)
// I stopped using BaseRatioSizes here because the information there wasn't well presented.
#define RMUL (1.6f/1.333333f)
// 4:3 16:9 16:10 17:10 5:4
static float ratios[]={RMUL*1.333333f, RMUL*1.777777f, RMUL*1.6f, RMUL*1.7f, RMUL*1.25f};
static float ratios[]={1.333333f, 1.777777f, 1.6f, 1.7f, 1.25f};
// now render the main view
float fovratio;
float ratio = ratios[WidescreenRatio];
if (!(WidescreenRatio&4))
{
fovratio = 1.6f;
fovratio = 1.333333f;
}
else
{