View Full Version : Calculating orthographic matrix parameters from perspective matrix

07-20-2014, 01:44 PM
I have the following two matrix creation methods:

GLK_INLINE GLKMatrix4 GLKMatrix4MakePerspective(float fovyRadians, float aspect, float nearZ, float farZ)
float cotan = 1.0f / tanf(fovyRadians / 2.0f);

GLKMatrix4 m = { cotan / aspect, 0.0f, 0.0f, 0.0f,
0.0f, cotan, 0.0f, 0.0f,
0.0f, 0.0f, (farZ + nearZ) / (nearZ - farZ), -1.0f,
0.0f, 0.0f, (2.0f * farZ * nearZ) / (nearZ - farZ), 0.0f };

return m;

GLK_INLINE GLKMatrix4 GLKMatrix4MakeOrtho(float left, float right,
float bottom, float top,
float nearZ, float farZ)
float ral = right + left;
float rsl = right - left;
float tab = top + bottom;
float tsb = top - bottom;
float fan = farZ + nearZ;
float fsn = farZ - nearZ;

GLKMatrix4 m = { 2.0f / rsl, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f / tsb, 0.0f, 0.0f,
0.0f, 0.0f, -2.0f / fsn, 0.0f,
-ral / rsl, -tab / tsb, -fan / fsn, 1.0f };

return m;

Is there a good way to create an Orthographic matrix from a given perspective matrix so that the transition will be as smooth as possible?

carsten neumann
07-20-2014, 03:29 PM
For very small FoV angles the two projections are (somewhat) similar. That suggests to me you want to keep near/far planes at the same world space position and move the eye point further and further away (making the FoV angle smaller in the process).