Unity Camera Orthographic Size size camera

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/wangjiangrong/article/details/96338240

As shown, the Camera Unity projection (Projection) is provided with the following two, orthogonal (Orthographic) and perspective (Perspective).

Orthogonal modes , the camera is a fixed size (Size), then observed under parallel. It will not be observed object distance from the camera, which ultimately results in showing different positions of the screen size. Rotation of the object, the effect on the screen longer or shorter sides only, would not have a large effect after a small front (2D Effects)

Through mode , then the next, the camera is at an angle (Field of View), diffusion was observed. The object being observed due to the distance from the camera, resulting in the final size show different positions of the screen. Rotation of the object will be too large, too small a portion far effect (3D effect) from the camera is displayed near the site

 

This time, there is a problem, in a case where the object to be observed does not move when I orthogonal projection screen for a camera, when the camera case projection mode to the projection mode, how to set parameters, whereby guaranteed to see the same picture. (Actual scenario is orthogonal to the Stage Camera FairyGUI camera, but there art 3D UI wants to achieve the effect, it wants to Stage Camera camera perspective, but how to set the angle and position such that the UI may display the full screen on)

We can see that the camera perspective in cross-section of different distances are different screen sizes, so we have to find a distance where the screen size, just orthogonal camera and screen size as can be.

So we need to understand the concept of so-called camera Orthographic Size screen size under

Orthographic Size

在正交模式下,我们设置Size的值,摄像机的大小会随之变动,那么这个值和摄像机的大小是什么关系呢?

简单的理解就是,size的值是正交摄像机高度的一半。当你拉伸屏幕窗口的时候,摄像机的高度不变,宽度改变。比如,我们Size设置的为7,表示屏幕的高度为14unit。

我们可以通过建立几个单位为1unit的cube进行验证,如图,我们用七个单位为1unit的cube,排成一排,正好是屏幕高度的一半。

知道Size的概念后,我们如果要使透视摄像机也一样显示Size=7的屏幕大小的话,只需要使得,当透视摄像机Field of View 为α时,在距离x的情况下,横切面的高度的一半为7即可,如图

根据三角函数我们可以得出 x = 7÷ tan(α÷2)

为了方便计算,我们可以把Field of View设为90度,则,tan45=1,所以我们只要将摄像机的z轴位置设置为-7,即可达到和正交摄像机size=7时,一样的屏幕效果(被观察的物体z轴为0)。

Guess you like

Origin blog.csdn.net/wangjiangrong/article/details/96338240