关于窗口大小变化后,裁剪区域的问题
一般来说,"将就小的"原则,即挡板效应
举例来说:
OrigWidth OrigHeight 二者最初具有一定的比例关系 OrigRatio = OrigWidth*1.0/OrigHeight;
窗口大小改变后:
AftWidth AftHeight AftRatio = AftWidth*1.0/AftHeight;
应当这样裁剪:
if(AftRatio < OrigRatio) //width decreases or height increases
then ClipWidth = AfterWidth; ClipHeight = AftWidth*1.0/OrigRatio;
else
then ClipWidth = AfterHeight*1.0*OrigRatio; ClipHeight = AftHeight;
特殊地,在OpenGL中,如果裁剪一个矩形,却应该这样写:
... glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat fRatio = (GLfloat)w / (GLfloat)h; if(w <= h) glOrtho(-100.0, 100.0, -100.0/fRatio, 100.0/fRatio, 1.0, -1.0);//注意裁剪h方向的区域反而变大了 else glOrtho(-100.0*fRatio, 100.0*fRatio, -100.0, 100.0, 1.0, -1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity();
...
原因在于OpenGL有个Volume(视景体)的概念,如果W变大了,你得多裁剪,才能弥补上最后投影到屏幕窗口上时的“缺口”。

浙公网安备 33010602011771号