PDA

View Full Version : Perspective and Ortho switch

Valentino
05-31-2000, 01:52 AM
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.

Bob
05-31-2000, 06:58 AM
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.

MikeC
05-31-2000, 07:07 AM
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.

Marrcke
05-31-2000, 10:14 AM
This is what I use to switch between ortho and perspective:

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

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

redraw() {
glMatrixMode( GL_PROJECTION );
glMatrixMode( GL_MODELVIEW );

(perspective mode instructions)

glMatrixMode( GL_PROJECTION );
glMatrixMode( GL_MODELVIEW );