03-25-2021, 03:41 PM
What you are trying to achieve is viable in 2D or with orthographic camera, since you actually make a selection and then fit it onto the screen because orthographic camera is based on a rectangular bounding box. In 3D, when you draw a rectangle, it's not actually a rectangle but a frustum since each corner of the rectangle is projected onto a line. You have two ways to solve this:
1) You set a constant distance to get a rectangle out of the frustum. Then what you are trying to do reduces to fitting selection into view. The distance can be also acquired if you are working on top of a large object and the rectangle is on top of the object - you get the plane to fit into view based on the corners.
2) You can use perspective model of a camera used in computer vision. You do the focus there based on focus distance and field of view. For example, you would start with camera at origin, with fovy 45°. Then when you try to zoom using the rectangle you compute the aspect and update the fovy to the fraction of 45. The focus in this case would not update the position. The position would be updated only when you move the camera (rotation, drag move).
1) You set a constant distance to get a rectangle out of the frustum. Then what you are trying to do reduces to fitting selection into view. The distance can be also acquired if you are working on top of a large object and the rectangle is on top of the object - you get the plane to fit into view based on the corners.
2) You can use perspective model of a camera used in computer vision. You do the focus there based on focus distance and field of view. For example, you would start with camera at origin, with fovy 45°. Then when you try to zoom using the rectangle you compute the aspect and update the fovy to the fraction of 45. The focus in this case would not update the position. The position would be updated only when you move the camera (rotation, drag move).

