我用GL_TRIANGLE_FAN
// draw the upper part of the cone
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0, 0, height);
for (int angle = 0; angle < 360; angle++) {
glVertex3f(sin(angle) * radius, cos(angle) * radius, 0);
}
glEnd();
// draw the base of the cone
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0, 0, 0);
for (int angle = 0; angle < 360; angle++) {
// normal is just pointing down
glNormal3f(0, -1, 0);
glVertex3f(sin(angle) * radius, cos(angle) * radius, 0);
}
glEnd();
如何获得表面法线?对于底部,我是否正确地说正常只是指向下方?
更新
我尝试使用
for (int angle = 0; angle < 360; angle++) {
glNormal3f(sin(angle), cos(angle), 0);
glVertex3f(sin(angle) * radius, cos(angle) * radius, 0);
}
但是在某些角度看起来很奇怪......
第二张图片看起来只有一种纯色?