Moving the camera center away from the window center

I have a window that has both 3d and 2d content. The 3d content is all inside a rectangle thats to the left of the window. Because the camera is set in the center of the window, the perspective looks wrong.

I would like to have my camera centered on the rectangle containing my 3d content instead of the window. Is that possible? Im currently using ofEasyCam.

Hey the cameras inherit from ofNode, so you can move them around, rotate them, etc, with the functions in ofNode. There are also some examples for the camera classes but I haven’t looked at them too closely.

you can pass an ofRectangle to the cameras draw funtion to define its viewport. Which is what I think you want.

//ofEasyCam cam;
cam.draw(ofRectangle(0,100,200,200);// put the correct numbers here
1 Like

That would be amazing, but are you sure this is supposed to work with an “ofEasyCam”? i have the most recent version of the framework and the draw method is to draw the node of the camera. There seems to be only one signature and it doesnt have any arguments.

I’ve found something that works but it’s really weird. cam.setTarget(aVec3). You would assume this would change only the camera orientation to point at a target, but it does seem to move the entire camera over the target. Whats weirder: the axis system for this method is 0,0,0 center of the screen, X and Y pointing left and up.

Tks! I’ve tried moving the node around. I’ve also tried creating a “position node” and setting it has the camera parent. In both case i ended up getting funky results. For example when moving the node around, the camera moves, but the perspective (or more likely the frustum?) seems to remain in the middle of the screen. Same when unsing “setPosition, setGlobalPosition or even ofTranslate”. if you do a “drawAxis” within the camera “begin/end”, you can see what’s happening. The axis does move to the new location, but they appear distorted by the perspective. The only way i’ve found to move the camera and the frustum is “camera.setTarget”. It has a weird axis system and doesnt do what’s expected, but it works :slight_smile:

Hey yeah I think playing around and getting something that works is a viable approach. ofNode has a lot of math things that I half-understand, or that I could someday understand much better if I took the time.

ofNode::lookAt() and ::getLookAtDir() might be helpful in pointing the camera, and I think I remember some posts in the forum about using these methods. And yes drawing the camera (and lights and etc for that matter) definitely help in seeing how various things are oriented in space at any given time.

I love ofNode and I think its a really powerful and fundamental class in oF, but its also been one of the more abstract and difficult for me to learn.

Hey this is really good to know; I need to learn more about the cameras and ofNode and stuff.

ofNode has a .draw() but it doesn’t take an arg (?). So maybe you’re of the thinking of ofCamera::drawFustrum(), which can take an ofRectangle as an arg. I’ll have to try this out the next time I do something with a camera!

Ohh sorry I meant begin not draw.

//ofEasyCam cam;
cam.begin(ofRectangle(0,100,200,200);// put the correct numbers here
1 Like

Thank you so much for taking the time to come back and answer. My project has to be done soon and the solution i had found was still impacting the perspective negatively. Just tested it and this is exactly what i needed. Tks again!