gluPerspective

gluPerspective這個函式指定了觀察的視景體(frustum為錐台的意思,通常譯為視景體)在世界坐標系中的具體大小,一般而言,其中的參數aspect應該與視窗的寬高比大小相同。比如說,aspect=2.0表示在觀察者的角度中物體的寬度是高度的兩倍,在視口中寬度也是高度的兩倍,這樣顯示出的物體才不會被扭曲。

基本介紹

  • 外文名:gluPerspective
  • 類型:函式
  • 優點:顯示出的物體不會被扭曲
  • 函式名稱:NAME
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.
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編程指南》一書。
gluPerspective

相關詞條

熱門詞條

聯絡我們