Camera parameter settings for perspective projection

In the case of perspective projection, the field of view angles in the two axes of the viewport during initialization are determined by the Keep Aspect setting and the FOV parameter: the field of view angle in the direction kept is locked to the FOV parameter (default 70 degrees), and the other axis direction The field of view is determined by the viewport aspect ratio.
When the viewport is adjusted during operation, the field of view angle of the specified axis is always locked (when initialized), and only the field of view FOV of the other active axis is adjusted, and the camera position does not change. If you adjust the size of the viewport in both directions at the same time, the result is the same as adjusting it in two separate steps.

  1. First determine the possible position range of all objects as the camera's observation range:
    Assume that the objects are all within the rectangular range of w*h;
  2. Determine (the minimum value of) camera height H:

If the camera position is directly above the center of the rectangle during initialization, looking towards the center of the rectangle, and allowing the viewport to exactly display the entire range of the rectangle in a certain direction, then: if the camera configuration is Keep Wide, the horizontal field of view angle of the viewport will no longer
be has changed, then the distance between the camera and the center of the rectangle should be (w/2)*cot(70/2);
if the camera configuration is Keep Height, the angle of view in the vertical direction of the viewport will not change, then the distance between the camera and the center of the rectangle Should be (h/2)*cot(70/2).

Example: It is known that w=154, h=104, and the initial size of the viewport is 1920*1080. Find the best initialization parameter configuration of the camera (display all w*h, as large as possible).
Solution:
When the camera's Keep Aspect is set to

  • Keep Width
    The vertical display range h'=154*1080/1920=86.625 < h, the rectangular range cannot be fully displayed
  • The range displayed in the horizontal direction of Keep Height
    is w'=104*1920/1080=184.89 > w, which can completely display the rectangular range.
    At this time, the minimum value of the camera height is =104*cot(35)/2=74.26, so H=75
    should be set. Keep Height and H=75.

Continuing from the previous example: If the viewport size is adjusted to 1080x1920 (vertical screen) after initialization, since Keep Height has been set, the viewing angle in the h direction remains unchanged.
The horizontal display range w'=104*1080/1920=58.5, the horizontal field of view is narrower, and the visible range is smaller.

Continuing from the previous example: If you want to fully display the range of w*h in the above two viewport sizes, find the best initialization parameter configuration of the viewport and camera.
Solution:
For a viewport of 1920*1920, when a certain direction is reduced to 1080, if the field of view angle in this direction is not locked, then the field of view (the visible part of the straight line parallel to the axis direction observed through the viewport) is cut off by 7 /16, w or h must be in the remaining 9/16.
Therefore, the minimum side length of the large viewport display range d=min(w, h)/(9/16)=h*16/9 is
obtained from the known conditions: d=104*16/9=184.9, camera height H=(d/2)*cot(35)=132.0, initialize the viewport size to 1920*1920, and set Keep Width (because the minimum value of d in the previous solution process is obtained from h, and the h direction is reduced).
If the initial viewport is 1920*1080 or 1080*1920, the 1920 side is set to locked (because it is assumed that the unlocked side is adjusted to 1080).

Reverse thinking: For a 1080*1080 viewport, when it expands to 1920 in a certain direction, if the field of view in this direction is locked, then the field of view in the other direction becomes the original 9/16, w or h must be Within this 9/16, so there is also d=min(w, h)/(9/16).

In practice, it should be noted that the viewport size is not equal to the window size, and is also affected by space factors such as the title bar and status bar; the camera height setting may be affected by the size of the object and the distance of the object from the plane where the rectangle is located.

  1. Determine the far plane and near plane
    . According to the solid geometric distance formula, set the far plane as:
    Far = sqrt(H^2 + (w/2)^2 + (h/2)^2)
    According to the estimated maximum height hmax of the object, Set the near plane as:
    Near = H - hmax

Guess you like

Origin blog.csdn.net/feiyunw/article/details/127135445