各种变换的原理----DX版本
DX 提供了D3DXMatrixPerspectiveLH,D3DXMatrixPerspectiveOffCenterLH以及D3DXMatrixPerspectiveFovLH来实现透视投影。提供了D3DXMatrixOrthoLH和D3DXMatrixOrthoOffCenterLH来实现正投影
(以上各函数都有右手坐标系下面的版本,只是把后面的LH改成RH)
先看D3DXMatrixPerspectiveLH
D3DXMatrixPerspectiveLH
Builds a left-handed perspective projection matrix
D3DXMATRIX * D3DXMatrixPerspectiveLH(D3DXMATRIX * pOut,FLOAT w,FLOAT h,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- w
- [in] Width of the view volume at the near view-plane.
- h
- [in] Height of the view volume at the near view-plane.
- zn
- [in] Z-value of the near view-plane.
- zf
- [in] Z-value of the far view-plane.
Return Values
Pointer to a D3DXMATRIX structure that is a left-handed perspective projection matrix.
这个函数的投影平面在z=n处
最后看下MSDN的结果
OK,为了完整把D3DXMatrixPerspectiveRH也推导下吧.囧....
D3DXMatrixPerspectiveRH
Builds a right-handed perspective projection matrix.
D3DXMATRIX * D3DXMatrixPerspectiveRH(D3DXMATRIX * pOut,FLOAT w,FLOAT h,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- w
- [in] Width of the view volume at the near view-plane.
- h
- [in] Height of the view volume at the near view-plane.
- zn
- [in] Z-value of the near view-plane.
- zf
- [in] Z-value of the far view-plane.
Return Values
Pointer to a D3DXMATRIX structure that is a right-handed perspective projection matrix.
这个函数的投影平面在z=-n处
最后看下MSDN的结果
再看下D3DXMatrixPerspectiveOffCenterLH
D3DXMatrixPerspectiveOffCenterLH
Builds a customized, left-handed perspective projection matrix.
D3DXMATRIX * D3DXMatrixPerspectiveOffCenterLH(D3DXMATRIX *pOut,FLOAT l,FLOAT r,FLOAT b,FLOAT t,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- l
- [in] Minimum x-value of the view volume.
- r
- [in] Maximum x-value of the view volume.
- b
- [in] Minimum y-value of the view volume.
- t
- [in] Maximum y-value of the view volume.
- zn
- [in] Minimum z-value of the view volume.
- zf
- [in] Maximum z-value of the view volume.
Return Values
Pointer to a D3DXMATRIX structure that is a customized, left-handed perspective projection matrix.
最后看下MSDN
接着看下D3DXMatrixPerspectiveOffCenterRH
D3DXMatrixPerspectiveOffCenterRH
Builds a customized, right-handed perspective projection matrix.
D3DXMATRIX * D3DXMatrixPerspectiveOffCenterRH(D3DXMATRIX *pOut,FLOAT l,FLOAT r,FLOAT b,FLOAT t,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- l
- [in] Minimum x-value of the view volume.
- r
- [in] Maximum x-value of the view volume.
- b
- [in] Minimum y-value of the view volume.
- t
- [in] Maximum y-value of the view volume.
- zn
- [in] Minimum z-value of the view volume.
- zf
- [in] Maximum z-value of the view volume.
Return Values
Pointer to a D3DXMATRIX structure that is a customized, right-handed perspective projection matrix.
看下MSDN
继续看D3DXMatrixPerspectiveFovLH
D3DXMatrixPerspectiveFovLH
Builds a left-handed perspective projection matrix based on a field of view.
D3DXMATRIX * D3DXMatrixPerspectiveFovLH(D3DXMATRIX *pOut,FLOAT fovy,FLOAT Aspect,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- fovy
- [in] Field of view in the y direction, in radians.
- Aspect
- [in] Aspect ratio, defined as view space width divided by height.
- zn
- [in] Z-value of the near view-plane.
- zf
- [in] Z-value of the far view-plane.
Return Values
Pointer to a D3DXMATRIX structure that is a left-handed perspective projection matrix.
看MSDN
继续看D3DXMatrixPerspectiveFovRH
D3DXMatrixPerspectiveFovRH
Builds a right-handed perspective projection matrix based on a field of view.
D3DXMATRIX * D3DXMatrixPerspectiveFovRH(D3DXMATRIX *pOut,FLOAT fovy,FLOAT Aspect,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- fovy
- [in] Field of view in the y direction, in radians.
- Aspect
- [in] Aspect ratio, defined as view space width divided by height.
- zn
- [in] Z-value of the near view-plane.
- zf
- [in] Z-value of the far view-plane.
Return Values
Pointer to a D3DXMATRIX structure that is a right-handed perspective projection matrix.
看结果
接着看几个正投影
先看D3DXMatrixOrthoLH
D3DXMatrixOrthoLH
Builds a left-handed orthographic projection matrix.
D3DXMATRIX * D3DXMatrixOrthoLH(D3DXMATRIX *pOut,FLOAT w,FLOAT h,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the resulting D3DXMATRIX.
- w
- [in] Width of the view volume.
- h
- [in] Height of the view volume.
- zn
- [in] Minimum z-value of the view volume which is referred to as z-near.
- zf
- [in] Maximum z-value of the view volume which is referred to as z-far.
Return Values
Pointer to the resulting D3DXMATRIX.
看结果
接着看D3DXMatrixOrthoRH
D3DXMatrixOrthoRH
Builds a right-handed orthographic projection matrix.
D3DXMATRIX * D3DXMatrixOrthoRH(D3DXMATRIX *pOut,FLOAT w,FLOAT h,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the resulting D3DXMATRIX.
- w
- [in] Width of the view volume.
- h
- [in] Height of the view volume.
- zn
- [in] Minimum z-value of the view volume.
- zf
- [in] Maximum z-value of the view volume.
Return Values
Pointer to the resulting D3DXMATRIX.
看结果
接着看D3DXMatrixOrthoOffCenterLH
D3DXMatrixOrthoOffCenterLH
Builds a customized, left-handed orthographic projection matrix.
D3DXMATRIX * D3DXMatrixOrthoOffCenterLH(D3DXMATRIX *pOut,FLOAT l,FLOAT r,FLOAT b,FLOAT t,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the resulting D3DXMATRIX.
- l
- [in] Minimum x-value of view volume.
- r
- [in] Maximum x-value of view volume.
- b
- [in] Minimum y-value of view volume.
- t
- [in] Maximum y-value of view volume.
- zn
- [in] Minimum z-value of the view volume.
- zf
- [in] Maximum z-value of the view volume.
Return Values
Pointer to the resulting D3DXMATRIX.
看结果
终于到最后一个了D3DXMatrixOrthoOffCenterRH
D3DXMatrixOrthoOffCenterRH
Builds a customized, right-handed orthographic projection matrix.
D3DXMATRIX * D3DXMatrixOrthoOffCenterRH(D3DXMATRIX *pOut,FLOAT l,FLOAT r,FLOAT b,FLOAT t,FLOAT zn,FLOAT zf );
Parameters
- pOut
- [in, out] Pointer to the resulting D3DXMATRIX.
- l
- [in] Minimum x-value of view volume.
- r
- [in] Maximum x-value of view volume.
- b
- [in] Minimum y-value of view volume.
- t
- [in] Maximum y-value of view volume.
- zn
- [in] Minimum z-value of the view volume.
- zf
- [in] Maximum z-value of the view volume.
Return Values
Pointer to the resulting D3DXMATRIX.
看结果
尼玛,终于搞完了,本来还有世界坐标到视图坐标的转换,标准设备坐标到视口的转换..今晚先到这里,伤不起啊,6点了,以后补上
继续补上,先看世界坐标到视图坐标的转换
先看D3DXMatrixLookAtLH
D3DXMatrixLookAtLH
Builds a left-handed, look-at matrix.
D3DXMATRIX * D3DXMatrixLookAtLH(D3DXMATRIX *pOut,CONST D3DXVECTOR3 *pEye,CONST D3DXVECTOR3 *pAt,CONST D3DXVECTOR3 *pUp );
Parameters
- pOut
- [in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
- pEye
- [in] Pointer to the D3DXVECTOR3 that defines the eye point. This value is used in translation.
- pAt
- [in] Pointer to the D3DXVECTOR3 structure that defines the camera look-at target.
- pUp
- [in] Pointer to the D3DXVECTOR3 structure that defines the current world's up, usually [0, 1, 0].
Return Values
Pointer to a D3DXMATRIX structure that is a left-handed, look-at matrix.
看结果
另外D3DXMatrixLookAtRH推导是一样的,只不过把Z''取负即可
接着看标准设备坐标到视口坐标的转换,DX提供了SetViewport方法来设置视口矩阵
IDirect3DDevice9::SetViewport
Sets the viewport parameters for the device.
HRESULT SetViewport(CONST D3DVIEWPORT9 * pViewport );
Parameters
- pViewport
- [in] Pointer to a D3DVIEWPORT9 structure, specifying the viewport parameters to set.
Return Values
If the method succeeds, the return value is D3D_OK. If the method fails, it will return D3DERR_INVALIDCALL. This will happen if pViewport is invalid, or if pViewport describes a region that cannot exist within the render target surface.
D3DVIEWPORT9结构体如下:
typedef struct D3DVIEWPORT9 {DWORD X;DWORD Y;DWORD Width;DWORD Height;float MinZ;float MaxZ; } D3DVIEWPORT9, *LPD3DVIEWPORT9;
所以,视口变换
就是将
x''->x''':(-1,1)->(X,X+Width)
y''->y''':(-1,1)->(Y+Height,Y)//这里注意DX中视口坐标中的y值是从上到下递增的
z''->z''':(0,1)->(MinZ,MaxZ)
由于(x'',y'',z'')满足线性插值,所以设
x'''=A'x''+B'
y'''=A''y''+B''
z'''=A'''z''+B'''
代入变换条件可求得:
A'=Width/2 B'=Width/2+X
A''=-Height/2 B''=Height/2+Y
A'''=MaxZ-MinZ B'''=MinZ
所以视口矩阵为
也就是龙书上所说的
OK,渲染管线里面用到的变换基本上讲完了,当然还有神马旋转变换矩阵,镜像映射矩阵,平面投影矩阵到时候我会再开专题讲敬请期待哦!
各种变换的原理----DX版本相关推荐
- 图像傅立叶变换的原理和物理意义
图像傅立叶变换的原理和物理意义 图像的傅立叶变换,原始图像由N行N列构成,N必须是基2的,把这个N*N个包含图像的点称为实部,另外还需要N*N个点称为虚部,因为FFT是基于复数的,如下图所示: (// ...
- 伽马变换的原理以及python实现
引用:https://blog.csdn.net/yangleo1987/article/details/52912560 伽马(gamma)变换: 原理: 个人理解类似于photoshop中的曲线功 ...
- PRI变换法原理解析及其matlab分析
---------------------------------------------------------------------------------------------------- ...
- python 图像变化检测_Python OpenCV 霍夫(Hough Transform)直线变换检测原理,图像处理第 33 篇博客...
Python OpenCV 365 天学习计划,与橡皮擦一起进入图像领域吧.本篇博客是这个系列的第 33 篇. 基础知识铺垫 霍夫变换(Hough Transform)是图像处理领域中,从图像中识别几 ...
- 【控制】Z变换及其原理讲解
扩展链接: [控制]拉普拉斯拉氏变换原理分解理解 [Matlab 控制] 拉氏变换和Z变换 Z变换及其原理讲解 简介 定义 说明 Z 变换求解方法 1)级数求和法 2)部分分式法 基本定理 1)线性定 ...
- 图形变换核心原理(平移、缩放、旋转,拉伸)
以Android为例,在使用Matrix进行绘图时有如下变换方法 // 缩放 public boolean preScale(float sx, float sy, float px, float p ...
- 傅立叶变换的原理、意义以及如何用Matlab实现快速傅立叶变换
本帖最后由 xiaoliu 于 2011-7-28 21:00 编辑 一.傅立叶变换的由来 关于傅立叶变换,无论是书本还是在网上可以很容易找到关于傅立叶变换的描述,但是大都是些故弄玄虚的文章,太过抽象 ...
- 希尔伯特黄变换(Hilbert-Huang)原理、HHT求时频谱、边际谱,及MATLAB(2018rb)实现
目录 1. 经验模态分解: 2. 希尔伯特变换: 3. 方法缺陷: 4. MATLAB(2018rb版本)实现和探讨 ##边际谱 [若觉文章质量良好且有用,请别忘了点赞收藏加关注,这将是我继续分享的动 ...
- SIFT(尺度不变特征变换)原理与简单应用
目录 1.SIFT(Scale Invariant Feature Transform)简介 1.1.SIFT算法的操作步骤 兴趣点的检测: 特征方向的赋值: 特征点描述: 1.2.SIFT算法的适用 ...
最新文章
- [转载]iphone开发--改变UIPageControl里的小点的颜色
- linux at java,Linux-Tutorial/Java-bin.md at master · linsanityHuang/Linux-Tutorial · GitHub
- php将文件夹压缩成zip文件,将文件夹压缩成zip文件的php代码_php实例
- 为什么不懂技术的人可以做产品经理?
- 计算机网络之传输层:3、TCP协议
- Oracle 项目就是那回事 ----表空间的管理
- 三种主流快平台技术测评,你更青睐谁?
- 1 dhcp服务器的配置文件,Linux1 DHCP服务器配置 主配置文件(dhcpd.conf)
- 新出计算机语言有哪些,2020年最新编程语言排名(十大编程语言的比较)
- Scikit-learn 秘籍 第五章 模型后处理
- Java题 细胞分裂
- java启动后台进程_windows下java -jar 后台运行以及杀死后台进程的操作
- 伊斯坦布尔之旅返程:夜景和免税店
- 【DVB】采用DVB-T或DVB-T2的国家达166个
- 艾美捷RPMI-1640培养基含L-谷氨酰胺的功能和研究
- EXCEL数据处理相关操作
- 输入一个整数,判断是奇数还是偶数?
- 电影院场次管理java_电影放映时间选择_09-JAVASE项目实战-电影管理系统_Java视频-51CTO学院...
- c++ word文档操作
- win7 创建wifi热点。