在 Unity 中,我有一个创建新边界的类,对于那些可能不知道统一边界实际上是一个立方体的人来说。然后我有一个像相机这样的对象,我想将此边界添加到相机并缩放它以适应视锥体。如果它从不旋转但相机确实旋转并且此刻我正在画一个空白,那将很容易。
当相机不旋转时,这就是我现在所拥有的
float h = Mathf.Tan(cam.fov * Mathf.Deg2Rad * .5f) * cam.farClipPlane * 2;
Vector3 scale = new Vector3(h * cam.aspect, h, cam.farClipPlane);
newBounds.center = cam.transform.position + cam.transform.forward * (cam.farClipPlane/2);
newBounds.size = scale;