OpenGL处理​​重新调整窗口大小

时间:2016-01-17 16:58:02

标签: c opengl matrix viewport orthographic

编写一个小型opengl应用程序,使用相机在0,0,0处朝向-1创建正交投影。我在围绕调整窗口大小的同时保持一些看起来不错的东西时遇到了一些困难。

vmathP3MakeFromElems(&eye, 0, 0, 0);
vmathP3MakeFromElems(&center, 0, 0, -1);
vmathV3MakeFromElems(&up, 0, 1, 0);

vmathM4MakeLookAt(&v_mat, &center, &eye, &up);

vmathV3MakeFromElems(&t_trans, (width * 0.5), (height * 0.5), -20.0);
vmathM4MakeTranslation(&v_mat, &t_trans);

vmathM4MakeOrthographic(&p_mat, 0, width, 0, height, 1.0, 100.0);
float aspect = width / height;

创建视图矩阵后,查看0,0,-1然后我翻译它,以便0,0是屏幕的中心。这很好用。当我在0,0画出一些东西时,它会被认为是。

当我重新调整窗口尺寸时,如果我使用新尺寸更新投影矩阵并使用上面的代码重新定位视图,就像这样:

resize(int width, int height) {
    vmathP3MakeFromElems(&eye, 0, 0, 0);
    vmathP3MakeFromElems(&center, 0, 0, -1);
    vmathV3MakeFromElems(&up, 0, 1, 0);

    vmathM4MakeLookAt(&v_mat, &center, &eye, &up);

    vmathV3MakeFromElems(&t_trans, (width * 0.5), (height * 0.5), -20.0);
    vmathM4MakeTranslation(&v_mat, &t_trans);

    vmathM4MakeOrthographic(&p_mat, 0, width, 0, height, 1.0, 100.0);
    float aspect = width / height;
}
然后会发生什么,如果我拉伸宽度,图像的宽度会被压扁。如果我伸展高度,图像高度会被压扁。

如果缩小宽度,则图像的宽度会变宽,如果缩小高度,图像会缩短。

如何调整此行为以说明在特定高度上限高度并显示更多宽度或限制宽度并使高度变高?

0 个答案:

没有答案
相关问题