Skip to content

Commit

Permalink
Refactor|GL: Moved 3D projection matrix to its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Nov 17, 2013
1 parent 9fb12ad commit 9f99a1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions doomsday/client/include/gl/gl_main.h
Expand Up @@ -36,6 +36,7 @@
#include "gl/gltextureunit.h"
#include "render/viewports.h"
#include "Texture"
#include <de/Matrix>

struct colorpalette_s;
struct ColorRawf_s;
Expand Down Expand Up @@ -127,6 +128,12 @@ void GL_Restore2DState(int step, viewport_t const *port, viewdata_t const *viewD

void GL_ProjectionMatrix();

/**
* Returns the projection matrix that is used for rendering the current frame's
* 3D portions.
*/
de::Matrix4f GL_GetProjectionMatrix();

/**
* The first selected unit is active after this call.
*/
Expand Down
17 changes: 11 additions & 6 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -584,7 +584,7 @@ void GL_Restore2DState(int step, viewport_t const *port, viewdata_t const *viewD
}
}

void GL_ProjectionMatrix()
Matrix4f GL_GetProjectionMatrix()
{
// We're assuming pixels are squares.
float aspect = viewpw / (float) viewph;
Expand Down Expand Up @@ -618,17 +618,22 @@ void GL_ProjectionMatrix()
frustumShift = VR::eyeShift * glNearClip / VR::hudDistance;
}

return Matrix4f::frustum(-fW - frustumShift, fW - frustumShift,
-fH, fH,
glNearClip, glFarClip) *
Matrix4f::translate(Vector3f(-VR::eyeShift, 0, 0)) *
Matrix4f::scale(Vector3f(1, 1, -1));
}

void GL_ProjectionMatrix()
{
DENG_ASSERT_IN_MAIN_THREAD();
DENG_ASSERT_GL_CONTEXT_ACTIVE();

// Actually shift the player viewpoint
// We'd like to have a left-handed coordinate system.
glMatrixMode(GL_PROJECTION);
glLoadMatrixf((Matrix4f::frustum(-fW - frustumShift, fW - frustumShift,
-fH, fH,
glNearClip, glFarClip) *
Matrix4f::translate(Vector3f(-VR::eyeShift, 0, 0)) *
Matrix4f::scale(Vector3f(1, 1, -1))).values());
glLoadMatrixf(GL_GetProjectionMatrix().values());
}

#undef GL_UseFog
Expand Down

0 comments on commit 9f99a1a

Please sign in to comment.