透视相机模式
下面展示一些 内联代码片 。
public static Vector3[] GetCorners(Camera _camera,float distance)
{
Vector3[] corners = new Vector3[ 4 ];
float halfFOV = ( _camera.fieldOfView * 0.5f ) * Mathf.Deg2Rad;
float aspect = _camera.aspect;
float height = distance * Mathf.Tan( halfFOV );
float width = height * aspect;
Transform cameraTransform = _camera.transform;
var position = cameraTransform.position;
var right = cameraTransform.right;
var up = cameraTransform.up;
var forward = cameraTransform.forward;
corners[ 0 ] = position - ( right * width );
corners[ 0 ] += up * height;
corners[ 0 ] += forward * distance;
corners[ 1 ] = position + ( right * width );
corners[ 1 ] += up * height;
corners[ 1 ] += forward * distance;
corners[ 2 ] = position - ( right * width );
corners[ 2 ] -= up * height;
corners[ 2 ] += forward * distance;
corners[ 3 ] = position + ( right * width );
corners[ 3 ] -= up * height;
corners[ 3 ] += forward * distance;
return corners;
}
|