我正在关注 Sumanta Guha 第二版的Computer Graphics Through OpenGL,第二版,在第 35 页,它说
Raising the first vertex of (the original) square.cpp from
glVertex3f(20.0, 20.0, 0.0)
toglVertex3f(20.0, 20.0, 1.5)
causes the square – actually, the new figure which is not a square any more – to be clipped. If, instead, the second vertex is raised fromglVertex3f(80.0, 20.0, 0.0)
toglVertex3f(80.0, 20.0, 1.5)
, then the figure is clipped too, but very differently from when the first vertex is raised. Why? Should not the results be similar by symmetry?Hint: OpenGL draws polygons after triangulating them as so-called triangle fans with the first vertex of the polygon the center of the fan. For example, the fan in Figure 2.16 consists of three triangles around vertex v0.
相应的代码如下
glVertex3f(20.0, 20.0, 0.0);
glVertex3f(80.0, 20.0, 0.0);
glVertex3f(80.0, 80.0, 0.0);
glVertex3f(20.0, 80.0, 0.0);
如果我只将第一个顶点的 z 轴设置为 1.5f,我会得到这样的输出,
如果我仅将第二个顶点的 z 轴设置为 1.5f,则会得到以下输出
在后一种情况下,我可以理解为什么我会因为剪辑而得到该输出,但我不明白为什么我会在前一种情况下得到该输出。
最佳答案
您正在绘制两个三角形:A、B、C 和 A、C、D。
如果更改其中一个顶点的一个 z
,两个三角形将不再位于同一平面内。
在第一种情况下,您更改 A 会影响两个三角形。在第二种情况下,您要更改 B,这只会影响第二个三角形。
请注意,您使用的代码已经严重过时,并且无法在 OpenGL 的现代核心配置文件中工作,其中“现代”的意思是:自十年 .
关于c++ - OpenGL:绘制多边形时,如果第一个顶点位于屏幕空间之外怎么办(三角扇),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46013073/