Changing window dimensions affects ofCamera view?

Hi, I drew a sphere in the center of 640 x 480 sized window and created a camera to see the left side of the sphere like the image below.

And if I press the key, I can switch to camera’s view which is the below image.

And Now, I just swapped the orientation of the window so now it’s 480 x 640 sized.
And the camera and sphere have same property and same distance as before.

But this time if I switch to camera’s view, the sphere looks much larger than when the window was 640 x 480 sized.

Shouldn’t they look exactly the same since nothing has changed between camera and the sphere regardless of the window size or ratio?
Could someone please explain to me if it is natural and why it is happening?
Thanks in advance!

Here’s my test code in case any one wants to try.

in main.cpp

int main( ){

	ofSetupOpenGL(640, 480, OF_WINDOW);			// <-------- setup the GL context

	// this kicks off the running of my app
	// can be OF_WINDOW or OF_FULLSCREEN
	// pass in width and height too:
	ofRunApp( new ofApp());

}

in ofApp.h

ofLight light;
ofMaterial material;
ofCamera cam;
bool useCam;

in ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup(){
    
    ofSetVerticalSync(true);
    ofSetFrameRate(60);
    ofSetBackgroundColor(10, 10, 10);
    ofEnableDepthTest();
    
    //directionalLight
    light.setDirectional();
    light.setSpecularColor(ofColor(255));
    light.setDiffuseColor(ofColor(255));
    light.setAmbientColor(ofColor(100));
    light.setOrientation(ofVec3f(0,180,0));
    
    //material
    material.setShininess(120);
    material.setSpecularColor(ofColor(0,0,0));
    material.setDiffuseColor(ofColor(200));
    material.setAmbientColor(ofColor(100));
    
    useCam = false;
}

//--------------------------------------------------------------
void ofApp::update(){

    //cam
    cam.setPosition(50, 240, 0);
    cam.lookAt(ofVec3f(320, 240, 0));

}

//--------------------------------------------------------------
void ofApp::draw(){

    if (useCam)
        cam.begin();
    
    ofEnableLighting();
    light.enable();
    material.begin();
    
    ofSetSphereResolution(100);
    ofDrawSphere(320, 240, 100);
    
    material.end();
    light.disable();
    ofDisableLighting();
    
    if (useCam)
        cam.end();
    else
        cam.draw();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){

    //swap window dimension
    if (key == 's') {
        
        const int w = ofGetHeight();
        const int h = ofGetWidth();
        ofSetWindowShape(w, h);
    }
    //camera on/off
    else if (key == 'c') {
        
        useCam = useCam == false;
    }
}

Can you try positioning the camera manually? in setup for example call, camera.setPosition(...)

1 Like

I already did it in update () :slight_smile:

ofCamera uses your window heigth to adjust the “scale” of the rendering, so that it fits your viewport vertically.

So when you switch from landscape to portrait, the viewport height increases, and the scale of the sphere increases in pixels. But notice the sphere stays the same size relative to window height.

You can set a custom viewport if you call cam.begin(ofRectangle viewport) instead of cam.begin()

1 Like

Thank you so much.