Get mouse position in 3d world

Hi, I am trying to make a simple zoom function that zooms in to where the mouse is positioned.
My default position:
cam.setPosition(0, 0, 4000);

Get the mouse position in 3d space:
mousePos = ofVec3f(ofGetMouseX(), ofGetMouseY(), 4000); worldMousePos = cam.screenToWorld(ofVec3f(ofGetMouseX(), ofGetMouseY(), 0), ofGetCurrentViewport());

Is use worldMousePos to set the new camera position to create the zoom effect. But for some reason the screenToWorld doens’t return the correct ofVec3f. Does anybody know what I’am doing wrong or am I using a completly wrong aproach to create a camera zoom?

Hello Jelle. Usually, to get 3D coordinates of the mouse position in 3D world, you cast a ray from camera positon (x,y,z) to the the position of the mouse. There are different way to achieve this, you could use some addons, or write it by yourself. Have a look into this thread and you will find both solutions.

Thank you very much! I will be taking a look.