Unity中裁剪空间推导(使用FOV来调节)

文章目录


前言

在之前的文章中,我们控制透视相机使用的是SIze。但是,在透视相机中,我们使用的是FOV角度来控制。


一、使用FOV代替之前使用的Size(h)

c o t ( F O V 2 ) = n h 2 = 2 n h cot(\frac{FOV}{2}) = \frac{n}{\frac{h}{2}} = \frac{2n}{h} cot(2FOV)=2hn=h2n

  • OpenGL

    2 n w 0 0 0 0 2 n h 0 0 0 0 n + f n − f 2 n f n − f 0 0 − 1 0 \] \\begin{bmatrix} \\frac{2n}{w} \& 0 \& 0 \& 0 \\\\ 0 \& \\frac{2n}{h} \& 0 \&0\\\\ 0 \& 0 \& \\frac{n+f}{n-f} \&\\frac{2nf}{n-f}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} w2n0000h2n0000n−fn+f−100n−f2nf0

    2 n w 0 0 0 0 2 n h 0 0 0 0 n f − n n f f − n 0 0 − 1 0 \] \\begin{bmatrix} \\frac{2n}{w} \& 0 \& 0 \& 0 \\\\ 0 \& \\frac{2n}{h} \& 0 \&0\\\\ 0 \& 0 \& \\frac{n}{f-n} \&\\frac{nf}{f-n}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} w2n0000h2n0000f−nn−100f−nnf0

r = w h r = \frac{w}{h} r=hw

r在1920x1080下为1.77

2 n w = 2 n r h = 1 r c o t ( F O V 2 ) \frac{2n}{w} = \frac{2n}{rh} = \frac{1}{r}cot(\frac{FOV}{2}) w2n=rh2n=r1cot(2FOV)

2 n h = c o t ( F O V 2 ) \frac{2n}{h}=cot(\frac{FOV}{2}) h2n=cot(2FOV)

2、替换后

  • OpenGL

    1 r c o t ( F O V 2 ) 0 0 0 0 c o t ( F O V 2 ) 0 0 0 0 n + f n − f 2 n f n − f 0 0 − 1 0 \] \\begin{bmatrix} \\frac{1}{r}cot(\\frac{FOV}{2}) \& 0 \& 0 \& 0 \\\\ 0 \& cot(\\frac{FOV}{2}) \& 0 \&0\\\\ 0 \& 0 \& \\frac{n+f}{n-f} \&\\frac{2nf}{n-f}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} r1cot(2FOV)0000cot(2FOV)0000n−fn+f−100n−f2nf0

    1 r c o t ( F O V 2 ) 0 0 0 0 c o t ( F O V 2 ) 0 0 0 0 n f − n n f f − n 0 0 − 1 0 \] \\begin{bmatrix} \\frac{1}{r}cot(\\frac{FOV}{2}) \& 0 \& 0 \& 0 \\\\ 0 \& cot(\\frac{FOV}{2}) \& 0 \&0\\\\ 0 \& 0 \& \\frac{n}{f-n} \&\\frac{nf}{f-n}\\\\ 0 \& 0 \& -1 \& 0\\\\ \\end{bmatrix} r1cot(2FOV)0000cot(2FOV)0000f−nn−100f−nnf0

相关推荐
★YUI★8 小时前
学习游戏制作记录(玩家掉落系统,删除物品功能和独特物品)8.17
java·学习·游戏·unity·c#
SmalBox8 小时前
【渲染流水线】[光栅阶段]-[光栅插值]以UnityURP为例
unity·渲染
谷宇.8 小时前
【Unity3D实例-功能-拔枪】角色拔枪(二)分割上身和下身
游戏·unity·c#·游戏程序·unity3d·游戏开发·游戏编程
老歌老听老掉牙11 小时前
SymPy 矩阵到 NumPy 数组的全面转换指南
python·线性代数·矩阵·numpy·sympy
星期天要睡觉11 小时前
机器学习——CountVectorizer将文本集合转换为 基于词频的特征矩阵
人工智能·机器学习·矩阵
洋曼巴-young11 小时前
240. 搜索二维矩阵 II
数据结构·算法·矩阵
何妨重温wdys15 小时前
矩阵链相乘的最少乘法次数(动态规划解法)
c++·算法·矩阵·动态规划
NRatel1 天前
亚马逊S3的使用简记(游戏资源发布更新)
游戏·unity·amazon s3
SmalBox1 天前
【渲染流水线】[几何阶段]-[屏幕映射]以UnityURP为例
unity·渲染
Keying,,,,2 天前
力扣hot100 | 矩阵 | 73. 矩阵置零、54. 螺旋矩阵、48. 旋转图像、240. 搜索二维矩阵 II
python·算法·leetcode·矩阵