Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Calculating orthographic matrix parameters from perspective matrix

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2014
    Posts
    21

    Calculating orthographic matrix parameters from perspective matrix

    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?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    894
    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •