1.结果是没有除以w之前的值 yScale = cot(fovY/2),fovY越小,yScale缩放比例差距越大, 一般fovY取90度,fovY/2为45度, 视图坐标系到透视4D空间中yScale = 1。2.w/h比例越大说明xScale缩放比例越小,yScale由fovY指定,而且要正好反比例:w/h = yScale/xScale 。
xScale = yScale / aspect,aspect = w/h.aspect 一般取屏幕的宽高,这样是等比缩放,没有拉伸效果,如果yScale = 1, w/h等于4:3,那么视图坐标系到透视4D空间中xScale = 3/4。
视锥体的上下夹角(6面体),z轴平分该夹角。
当fovy变小时候,因为也要在屏幕90度中用,所以高度方向被放大了,反之fovy变大,高度方向变小。
aspect:aspect = w / h,fovy = 90度,由投影矩阵的计算过程,投影yScale = cot(fovy/2); xScale = yScale /aspect.
当屏幕w:h = 100:20时,当aspect = 5:1,那么视锥内的[5,1]正方形截面世界将被变换映射到(1,1)的平面内,
xScale压缩了1/5,当透视投影映射到屏幕坐标时候[5,1],xScale方向需要根据屏幕放大5倍,这样视锥体里面的世界等比缩放到屏幕。
当aspect = 1变小;那么yScale = 1, xScale = 1,视锥体内的xy正方形截面[1,1]世界被放置到(1,1); 映射到屏幕为[5,1]xScale映射到屏幕被放大了5倍,yScale不变。
当aspect = 10变大,那么yScale = 1,xScale = 1/10,视锥体内的xy正方形截面[10,1]世界->(1,1)->[5,1],xScale被缩小了2倍,yScale不变。
D3DXMATRIX* D3DXMatrixPerspectiveFovRH( _Inout_ D3DXMATRIX *pOut, _In_ FLOAT fovy, _In_ FLOAT Aspect, _In_ FLOAT zn, _In_ FLOAT zf );
xScale 0 0 0 0 yScale 0 0 0 0 zf/(zn-zf) -1 0 0 zn*zf/(zn-zf) 0 where:
// 结果是没有除以w之前的值
yScale = cot(fovY/2)
// 通过yScale和缩放比例aspect = w/h,求取xScale
xScale = yScale / aspect ratio
D3DXMatrixPerspectiveFovLH变换矩阵:
D3DXMATRIX* D3DXMatrixPerspectiveFovLH( _Inout_ D3DXMATRIX *pOut, _In_ FLOAT fovy, _In_ FLOAT Aspect, _In_ FLOAT zn, _In_ FLOAT zf );
xScale 0 0 0 0 yScale 0 0 0 0 zf/(zf-zn) 1 0 0 -zn*zf/(zf-zn) 0 where: yScale = cot(fovY/2) xScale = yScale / aspect ratio
变换公式:
gluPerspective — set up a perspective projection matrix
void gluPerspective( |
GLdouble fovy, |
|
GLdouble aspect, |
|
GLdouble zNear, |
|
GLdouble zFar) ; |
fovy
Specifies the field of view angle, in degrees, in the y direction.
aspect
Specifies the aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of x (width) to y (height).
zNear
Specifies the distance from the viewer to the near clipping plane (always positive).
zFar
Specifies the distance from the viewer to the far clipping plane (always positive).
gluPerspective
specifies a viewing frustum into the world coordinate system. In general, the aspect ratio in gluPerspective
should match the aspect ratio of the associated viewport. For example, aspect = 2.0 means the viewer's angle of view is twice as wide in x as it is in y. If the viewport is twice as wide as it is tall, it displays the image without distortion.
The matrix generated by gluPerspective
is multipled by the current matrix, just as if glMultMatrix were called with the generated matrix. To load the perspective matrix onto the current matrix stack instead, precede the call to gluPerspective
with a call to glLoadIdentity.
Given f defined as follows:
The generated matrix is
Depth buffer precision is affected by the values specified for zNear
and zFar
. The greater the ratio of zFar
to zNear
is, the less effective the depth buffer will be at distinguishing between surfaces that are near each other. If
r = zFar zNear
roughly log 2 r bits of depth buffer precision are lost. Because r approaches infinity as zNear
approaches 0, zNear
must never be set to 0.