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点了,以后补上