Question

I'm building a little shape editor with two viewmodes: orthogonal and perspective view. So i found it would be nice, if the zoomvalues of the perspective and the ortho are equal (or as equal as they can be).

The zoomvalue of the perspective view is simply archived through setting the position on the z-axies. For the ortho, i scale the Left, Right, Top and Bottom corners from 0.0 to X.

Is it possible to zoom them equally? Is there a solution?

Was it helpful?

Solution

I will interpret an equal zoom value as meaning the shape will appear to be the same size in each zoom mode. Since, in perspective, the apparent size of the portions of the shape will depend on their distance from the camera, this "equal zoom" can only be achieved at a particular depth within the shape.

Let's assume you want the portion of the shape closest to the camera to appear equal in the two view modes.

To produce an equivalent orthographic view from the perspective view, first calculate the width and height of the view frustum at the closest point of the shape.

width = tan(fovX) * distance

height = tan (fovY) * distance

where distance is the distance from the camera to the closest point on the shape and fovX, fovY are the horizontal and vertical angles of the field of view in perspective mode.

You can then set the orthographic view rectangle to 0,0,width,height, assuming you center the camera on the shape.

To produce an equivalent perspective view from an orthographic view, just invert the equation:

distance = width / tan(fovX)

or

distance = height / tan(fovY)

Then set the z value of your camera to the closest point on the object - distance, assuming you are looking down the positive z axis. If your camera is always at the origin, you can set the z value of the object such that its closest point's z value is equal to distance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top