From 1bce4446685da941e9ffed40ecbabacd9109d5a7 Mon Sep 17 00:00:00 2001 From: Bart Trzynadlowski Date: Tue, 28 Feb 2012 04:34:32 +0000 Subject: [PATCH] Brought in the near clipping plane for Step 1.5+. Objects close to camera are no longer cut-off (e.g., driver arms and steering wheels in cockpit views). Note: This change should probably be applied to Step 1.0 as well in the future. For now, I am leaving the old distance because Step 1.0 coordinates need closer investigation. Bringing in the near clipping plane extends the view frustum depth and will worsen Z-buffer accuracy. Be on the lookout for Z-fighting that did not previously exist. --- Src/Graphics/Render3D.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Src/Graphics/Render3D.cpp b/Src/Graphics/Render3D.cpp index 3649cad..4a20c9c 100644 --- a/Src/Graphics/Render3D.cpp +++ b/Src/Graphics/Render3D.cpp @@ -815,7 +815,7 @@ void CRender3D::RenderViewport(UINT32 addr, int pri) int curPri; int vpX, vpY, vpWidth, vpHeight; int spotColorIdx; - GLfloat vpTopAngle, vpBotAngle, fovYDegrees; + GLfloat vpTopAngle, vpBotAngle, fovYDegrees, near, far; GLfloat scrollFog, scrollAtt; // Translate address and obtain pointer @@ -848,8 +848,20 @@ void CRender3D::RenderViewport(UINT32 addr, int pri) vpTopAngle = (float) asin(*(float *)&vpnode[0x0E]); // FOV Y upper half-angle (radians) vpBotAngle = (float) asin(*(float *)&vpnode[0x12]); // FOV Y lower half-angle fovYDegrees = (vpTopAngle+vpBotAngle)*(float)(180.0/3.14159265358979323846); - // TO-DO: investigate clipping planes - + // TO-DO: figure out how near and far planes are stored + if (step >= 0x15) + { + near = 1e-2; + far = 1e5; + } + else + { + // Move near plane out a bit on Step 1.0 to avoid issues w/ Z-fighting. + // This may be unnecessary. + near = 1e-1; + far = 1e5; + } + // Set up viewport and projection (TO-DO: near and far clipping) glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -860,7 +872,8 @@ void CRender3D::RenderViewport(UINT32 addr, int pri) viewportY = yOffs + (GLint) ((float)(384-(vpY+vpHeight))*yRatio); viewportWidth = totalXRes; viewportHeight = (GLint) ((float)vpHeight*yRatio); - gluPerspective(fovYDegrees,(GLfloat)viewportWidth/(GLfloat)viewportHeight,0.1f,1e5); // use actual full screen ratio to get proper X FOV + gluPerspective(fovYDegrees,(GLfloat)viewportWidth/(GLfloat)viewportHeight,0.01f,1e5); + //gluPerspective(fovYDegrees,(GLfloat)viewportWidth/(GLfloat)viewportHeight,0.1f,1e5); // use actual full screen ratio to get proper X FOV //printf("viewportX=%d, viewportY=%d, viewportWidth=%d, viewportHeight=%d\tvpY=%d vpHeight=%d\n", viewportX, viewportY, viewportWidth, viewportHeight, vpY,vpHeight); } else