What happens to perspective on window resize?

Hello there,

I’m drawing a 3d-scene in a window with very high aspect ratio ( 16 : 3) and I’m trying to figure out how to gain control over the perspective / field of view. I noticed that, when resizing the window, the perspective will change exactly the way I intend to, however, I didn’t succeed in reproducing the effect with opengl calls:

    // mouseY for testing  
    float fov = ofRadToDeg( PI/3.0)  - mouseY ;  
    // mouseX for testing  
    gluPerspective( fov , float(ofGetWidth())/float(ofGetHeight()+mouseX), 1.0, 5000.0);   
    glMatrixMode (GL_MODELVIEW);  
    ofTranslate(ofGetWidth()*0.5, ofGetHeight()*0.5, 300);  
    // DRAW 3D SCENE  

The values controlled by mouse only “stretch” the scene like it was a 2d-picture; what I intend to do is really changing the perspective of the scene, which is exactly what happens on resizing the window height.

Could anybody hint me in the right direction or explain to me, how openframeworks handles the perspective from window width and height (or where this calculation takes place in the source)?

Thanks in advance!

OF internally uses ofSetupPerspective to calculate the perspective of the window. You can chec how that works inside ofGLRenderer::setupPerspective

Thanks for the hint, arturo!
I just found out what the problem was – I’ve been looking too much at the perspective shifts and later noticed that there’s also a Z transform involved. So what does the trick is to shift FOV and at the same time transform the scene in the z-axis.

In case anyone’s curious, i achieved some sort of lens / vertigo zoom by doing that:

    cam.begin(); // ofCamera  
    float zoomShift = 900.0; // this is animated between 200.0 and 900.0.  
    float fov = ofRadToDeg( PI/3.0) + zoomShift*0.085;  
    gluPerspective( fov , float(ofGetWidth())/float(ofGetHeight()), 1.0, 5000.0);  
    glMatrixMode (GL_MODELVIEW);  
    cam.setPosition(0, 0, 600-sqrt(zoomShift)*10.6);  
    // draw scene