Results 1 to 5 of 5

Thread: Perspective and Ortho switch

  1. #1
    Junior Member Newbie
    Join Date
    May 2000
    Location
    Lausanne, Switzerland
    Posts
    1

    Perspective and Ortho switch

    My question is:

    Does anyone know where I could find the mathematics (or code) to switch a 3D scene from Ortho to Perspective (and reverse)? Nearest vertex should stay at the same raster position.

    Thanx.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Perspective and Ortho switch

    As far as I know, calling glOrtho(l, r, b, t, n, f) and glFrustum(l, r, b, t, n, f), where l, b and n is the same in both cases, will always cause the point on the near clipping plane to be projected on the same pixels in the viewport. You can always calculate either l, b and n for glOrtho, or calculate fov and near for gluPerspective.

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Perspective and Ortho switch

    Bob, mathematically I think you're right, but I can imagine that some drivers might use the glOrtho call to optimize away perspective divides etc, but wouldn't spot that they could do the same thing with the special-case glFrustrum.

  4. #4
    Junior Member Newbie
    Join Date
    May 2000
    Location
    Annapolis, MD
    Posts
    20

    Re: Perspective and Ortho switch

    This is what I use to switch between ortho and perspective:

    double ortho_proj[16];
    double perspective_proj[16];

    init() {
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, 640, 0, 480, 0, 1 );
    glGetDoublev( GL_PROJECTION_MATRIX, ortho_proj );
    glLoadIdentity();
    gluPerspective( 40, 1, 1, 200 );
    glGetDoublev( GL_PROJECTION_MATRIX, perspective_proj );
    }

    redraw() {
    glMatrixMode( GL_PROJECTION );
    glLoadMatrixd( perspective_proj );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    (perspective mode instructions)

    glMatrixMode( GL_PROJECTION );
    glLoadMatrixd( ortho_proj );
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    (ortho mode instructions)
    }

    You will probablly have to play with the values for glOrtho and glFrustum as Bob suggested in order to get the Nearest Vertex effect you're looking for (I'm not sure what you mean).

    -Marrcke

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Perspective and Ortho switch

    When I read MikeC's post, something slipped into my mind. I'm partly correct in my post above. But only in one special case, when glOrtho's parameter fulfill the following requirements: l=-1*r and b=-1*t

    Since you can call glOrtho with "non-uniform" (is that what it's called?) parameters where they don't pass the above requirement, when l=1 and r=2 for exmample, you must take some special action if this is the case.

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2015, 07:35 AM
  2. Going from ortho to perspective
    By openglesuser in forum OpenGL ES
    Replies: 3
    Last Post: 09-05-2008, 02:16 PM
  3. ortho + perspective + ortho
    By mithun_daa in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-09-2004, 07:54 AM
  4. Perspective vs. Ortho
    By stout in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-26-2003, 12:05 AM
  5. changing from perspective to ortho back to perspective
    By crappy04 in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-19-2001, 09:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean