我的導師說他們可以互換使用來影響投影矩陣。他認爲最好使用gluLookAt()
,因爲它「由於其定義視角的能力而相對簡單」。這是真的?我見過使用gluLookAt()
和glFrustum()
的代碼示例,我想知道爲什麼程序員將它們混合使用。gluLookAt()和glFrustum()有區別嗎?
就像在紅皮書的cube.c例子顯示:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
**//why isn't this a call to glFrustum?**
glScalef(1.0, 2.0, 1.0);
glutWireCube(1.0);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
//why isn't this a call a call to gluLookAt()?
glMatrixMode(GL_MODELVIEW);
}
哼。 gluLookAt和glFrustum設置了非常不同的矩陣(gluLookAt通常不適用於投影矩陣)。你確定你的老師不是在說gluPerspective而不是gluLookAt嗎? – Bahbar 2010-11-22 09:51:34
主要區別在於glFrustum是核心OpenGL庫的一部分,gluLookAt是一個幫助程序庫的一部分,它使用一組不同的參數並調用glFrustum。 OpenGL使用哪一個並沒有什麼不同,選擇是編碼偏好之一。 – AndrewS 2013-09-20 18:13:48