/// <summary>
/// 在透视投影时,改变相机的fov或物体的位置,让物体保持在屏幕上看起来的大小一样的缩放值
/// </summary>
/// <returns></returns>
public static float KeepSizeLookSameScale(Vector3 pos, Camera cam)
{
float distance = Vector3.Distance(cam.transform.position, pos);
float size = distance * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad);
float max = 100f * Mathf.Tan(122 * 0.5f * Mathf.Deg2Rad);
float scale = size / max;
//scale = Mathf.Clamp(scale, 0.01f, 0.1f);//限定一个最大值和最小值
return scale;
}
转自:https://www.cnblogs.com/Jason-c/p/17119010.html
网友评论