openGL的project matrix 和 model matrix


最近和juanL两个人调openGL,现在才把一些东西搞清楚

project matrix 相当于是内参,自己设置的一些东西,可以通过gluperspective之类的函数设置

model matrix 相当于外参, 就是R和T。

一般情况下,程序都至少会调用设置project matrix一次,如我们通常在reshape回调函数里设置gluperspective函数(因为不管怎么样所有的回调函数都得至少跑一次,如下面的resizeGL函数,就是通过调用这个函数让我们设置内参数。)

就是因为如果窗口发生变化的话,我们的project matrix得重新设置,一般都是

void GLWidget::resizeGL(int width, int height)
{
    if ( height == 0 )
    {
        height = 1;
    }
    glViewport( 0, 0, (GLint)width, (GLint)height ); 
    glMatrixMode( GL_PROJECTION ); // 开始设置project matrix
    glLoadIdentity(); // 清楚影响
    gluPerspective( 45.0, (GLfloat)width/(GLfloat)height, 0.1, 100.0 ); // 设置project matrix
    glMatrixMode( GL_MODELVIEW ); // 开始设置model matrix
    glLoadIdentity();
}


可以多看看红宝书。

整个openGL就是一个起到一个摄像机的作用。

相关内容