代码改变世界

gluPerspective

2013-02-21 13:56  三戒1993  阅读(145)  评论(0编辑  收藏  举报

gluPerspective
NAME(函数名称)
gluPerspective -- set up a perspective projection matrix (设置透视投影矩阵)
C SPECIFICATION(C语言实现示例)
void gluPerspective(
GLdouble fovy, //角度
GLdouble aspect,//视景体的宽高比
GLdouble zNear,//沿z轴方向的两裁面之间的距离的近处
GLdouble zFar //沿z轴方向的两裁面之间的距离的远处
)
PARAMETERS(参数含义)
fovy
Specifies the field of view angle, in degrees, in the y direction.
指定视景体的视野的角度,以度数为单位,y轴的上下方向
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).
指定你的视景体的宽高比(x 平面上)
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).
与上面的参数相反,这个指定观察者到视景体的最远的裁剪面的距离(必须为正数)
DESCRIPTION(说明)
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.
gluPerspective这个函数指定了观察的视景体(frustum为锥台的意思,通常译为视景体)在世界坐标系中的具体大小,一般而言,其中的参数aspect应该与窗口的宽高比大小相同。比如说,aspect=2.0表示在观察者的角度中物体的宽度是高度的两倍,在视口中宽度也是高度的两倍,这样显示出的物体才不会被扭曲。
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.
由gluPerspective产生的矩阵是与当前矩阵与指定的矩阵相乘得到的,就好像是调用glMatrix()产生的矩阵一样。为了使透视矩阵替代当前矩阵,在调用gluPerspective之前要先调用glLoadidentity()这个函数(就是把当前矩阵s设置为单位矩阵)。
补充,这段话的意思就是说(个人理解),这个gluPerspective的实现是通过将当前矩阵与你通过这个函数指定的参数而建立的矩阵相乘来实现的,而在OpenGL中,矩阵的相乘都是连乘的,也就是说,你调用这个函数会与其他的变化矩阵的函数效果相叠加从而影响原矩阵(当然有时候确实需要这样做),所以,在调用这个函数之前,通常需要先调用glLoadidentity来把当前矩阵单位化,从而使各种变换效果不会叠加,比如旋转就只旋转,透视就只透视,通过调用glLoadidentity就不会既旋转有透视了。
请参考《OpenGL编程指南》一书。

版权声明:本文为博主原创文章,未经博主允许不得转载。