Hi, I’m trying to figure out how to make the camera have the same position and orientation as the default view matrix.
For example, let’s say if I want to draw a bouncing ball on screen and when I press the key, the camera will be enabled and start to slowly zoom out of the screen. In this case, I think the camera should have proper position and orientation as the current view before starting the animation.
The orientation is easy, but I don’t know how to properly get the z position of the default view.
why not just always use a camera? the default perspective is set so 0,0 is in the top left corner of the screen but ofCamera sets the origin a the center so trying to mix both can be innecesarily tricky. if you just start with a camera and position it wherever you want from the start you don’t need to worry about matching both views later
I thought it would be good to save some performance to use camera only when I need to use it. But if it’s not so easy, I will always use a camera like you said
using a camera doesn’t incur any performance penalty it’s just setting a perspective matrix the same way the default OF view does, it needs to calculate one more matrix but the whole thing probably takes nanoseconds. in general don’t worry about performance unless you have a performance problem
I figured out how to get position of the current view to use in ofCamera.
ofCamera::setPosition(ofVec3f(ofGetWidth() * 0.5, ofGetHeight() * 0.5, ofGetHeight() * 0.866));
With this setting, the camera’s view seemed like it is exactly the same as the default view.
I don’t know why the Z position is “height * 0.866” though but it works
There was even easier solution to do this.
By calling ofCamera::setupPerspective();