Move viewport stuff to its own function

This commit is contained in:
Magnus Norddahl 2016-11-18 14:40:53 +01:00
parent dbb6c7ca27
commit 5d6ceb868e
2 changed files with 19 additions and 12 deletions

View file

@ -40,6 +40,7 @@ void RenderPolyScene::Render()
return;
ClearBuffers();
SetSceneViewport();
SetupPerspectiveMatrix();
Cull.CullScene(WorldToClip);
RenderSectors();
@ -67,6 +68,18 @@ void RenderPolyScene::ClearBuffers()
NextSubsectorDepth = 0;
}
void RenderPolyScene::SetSceneViewport()
{
int height;
if (screenblocks >= 10)
height = SCREENHEIGHT;
else
height = (screenblocks*SCREENHEIGHT / 10) & ~7;
int bottom = SCREENHEIGHT - (height + viewwindowy - ((height - viewheight) / 2));
PolyTriangleDrawer::set_viewport(viewwindowx, SCREENHEIGHT - bottom - height, viewwidth, height, screen);
}
void RenderPolyScene::SetupPerspectiveMatrix()
{
static bool bDidSetup = false;
@ -77,29 +90,22 @@ void RenderPolyScene::SetupPerspectiveMatrix()
bDidSetup = true;
}
int height;
if (screenblocks >= 10)
height = SCREENHEIGHT;
else
height = (screenblocks*SCREENHEIGHT / 10) & ~7;
int bottom = SCREENHEIGHT - (height + viewwindowy - ((height - viewheight) / 2));
PolyTriangleDrawer::set_viewport(viewwindowx, SCREENHEIGHT - bottom - height, viewwidth, height, screen);
// Code provided courtesy of Graf Zahl. Now we just have to plug it into the viewmatrix code...
// We have to scale the pitch to account for the pixel stretching, because the playsim doesn't know about this and treats it as 1:1.
double radPitch = ViewPitch.Normalized180().Radians();
double angx = cos(radPitch);
double angy = sin(radPitch) * glset.pixelstretch;
double alen = sqrt(angx*angx + angy*angy);
//mAngles.Pitch = (float)RAD2DEG(asin(angy / alen));
float adjustedPitch = (float)asin(angy / alen);
float adjustedViewAngle = (float)(ViewAngle - 90).Radians();
float ratio = WidescreenRatio;
float fovratio = (WidescreenRatio >= 1.3f) ? 1.333333f : ratio;
float fovy = (float)(2 * DAngle::ToDegrees(atan(tan(FieldOfView.Radians() / 2) / fovratio)).Degrees);
TriMatrix worldToView =
TriMatrix::rotate((float)asin(angy / alen), 1.0f, 0.0f, 0.0f) *
TriMatrix::rotate((float)(ViewAngle - 90).Radians(), 0.0f, -1.0f, 0.0f) *
TriMatrix::rotate(adjustedPitch, 1.0f, 0.0f, 0.0f) *
TriMatrix::rotate(adjustedViewAngle, 0.0f, -1.0f, 0.0f) *
TriMatrix::scale(1.0f, glset.pixelstretch, 1.0f) *
TriMatrix::swapYZ() *
TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z);

View file

@ -88,6 +88,7 @@ public:
private:
void ClearBuffers();
void SetSceneViewport();
void SetupPerspectiveMatrix();
void RenderSectors();
void RenderSubsector(subsector_t *sub);