ofEasyCam drawing not in center of screen

Hey, I cant get my head around this problem:

I would be super thankful for any tips :slight_smile:

I am using ofeasyCam to simply draw a mesh on the screen. I would like to have the center of the mesh in the middle of the screen. But it is shifted to the left (see image). When I zoom in, the mesh moves sideway, not in symmetry with the screen. I would like to zoom into the center of the mesh while setting:

easyCam.setPosition(0, 0, zoom);

The goal is to run the app in fullscreen mode and still have the image in the center while zooming.
I set the screen to (I believe) the size of my screen (15’’ retina display), but when I run the code I get strange results:

main():

ofGLWindowSettings settings;

settings.setGLVersion(3,2);
settings.setSize(2880 , 1800);

ofCreateWindow(settings);

cout << ofGetWidth() << endl;  --> this gives me 1440 --> shouldnt it be 2880?
cout << ofGetHeight() << endl; --> this is 852 which doesnt really makes sense to me!
ofRunApp(new ofApp());

so what am I actually setting here? The window covers my whole screen but the mesh is not in the middle of the screen. Its shifted more to the left.

This my drawing function:

easyCam.disableMouseInput();
easyCam.begin();

    ofPushMatrix();
        ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2);
        easyCam.setPosition(0, 0, zoom);

        //lets mesh rotate around the middle axis of the screen
        ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
            ofRotateXDeg(x); 
            ofRotateYDeg(y);
            ofRotateZDeg(z);
        ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2);

            mesh.draw();

        ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

    ofPopMatrix();
easyCam.end();

this is what the app draws on the screen:
Why is it shifted to the left?

ofEasyCam needs extra steps if you disable the mouse input.
Here is a simple example that should do what you need where 0,0 is the center of the screen.

Just add in your ofRotates but skip all the ofTranslate calls and you should be good to go.

    easyCam.disableMouseInput();
    easyCam.setupPerspective();
    easyCam.setPosition(0, 0, zoom);
    easyCam.begin();
         mesh.draw();
    easyCam.end();

Thank you for your answer! I tried it but nothing changed…
I found out that if I have the setting below in main() without specifically setting the size of the window it works. The app creates a window and the mesh stays in the center when I zoom in/out.

ofGLWindowSettings settings;
settings.setGLVersion(3,2);
ofCreateWindow(settings);
ofRunApp(new ofApp());

As soon as I enter full screen mode the mesh is shifted as in the picture above and zooming ends up shifted as well. Maybe I am dealing with some fillRateIssues in fullScreenMode?
I also noticed that when I resize the image to the size of the window in fullscreen, it works fine…
Any suggestions on how to make fullScreen work in my case without such workarounds?

This works fine for me on macOS.
( hit any key to toggle fullscreen )

If this works for you then you could try and debug the issues you are having line at a time.

//========================================================================
int main( ){

    ofGLWindowSettings settings;
    settings.setGLVersion(3,2);
    settings.setSize(1920, 1200);
    ofCreateWindow(settings);
    ofRunApp(new ofApp());

}
#include "ofApp.h"

ofEasyCam cam;

//--------------------------------------------------------------
void ofApp::setup(){
    cam.disableMouseInput();
}

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

}

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

    cam.setupPerspective();
    cam.setPosition(0, 0, 400);
    cam.begin();
        auto m = ofPlanePrimitive(50, 50, 4, 4, OF_PRIMITIVE_TRIANGLES);
        m.draw();
    cam.end();
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    ofToggleFullscreen();
}

Yes indeed, it does work with a Primitive!
But when I try to run the code with drawing an image instead of the Primitive, it doesnt get placed in the center of the screen. When I try to implement ofTranslate, the image doesnt show up at all. Am I missing something?

cam.begin();

    ofPushMatrix();

        ofTranslate(-ofGetWidth()/2, -ofGetHeight()/2);

            image.draw(0,0);

        ofTranslate(ofGetWidth()/2, ofGetHeight()/2);

    ofPopMatrix();
cam.end();
cam.setupPerspective();
cam.setPosition(0, 0, 400);
cam.begin();

    image.draw(0,0);

cam.end();

The plane primitive has the center of the mesh as 0,0
By default ofImage and ofTexture 0,0 is the top left.

If you want to draw an ofImage in the center of the screen do:
image.setAnchorPercent(0.5, 0.5);
after you load it.

Also no need for the ofTranslate calls.

yes, it does work as well. Thank you very much! I now tried it with a mesh. I just replaced the image.draw(0,0) with mesh.draw() and it is not centered… The center of the mesh is not in the center of the screen. Even ofTranslate doesnt work in this case. Any suggestions?

It might be that the mesh you are making doesn’t have 0,0 as the center.