我正在尝试通过绘制顶点来制作一个 3D 方形平截头体:
int xPts[] = { 1.0, 1.0, -1.0, -1.0, 2.0, 2.0, -2.0, -2.0 };
int yPts[] = { 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, -1.0 };
int zPts[] = { 1.0, -1.0, -1.0, 1.0, 2.0, -2.0, -2.0, 2.0 };
int sideA[] = { 0, 3, 7, 4 };
int sideB[] = { 0, 1, 5, 4 };
int sideC[] = { 2, 3, 7, 6 };
int sideD[] = { 1, 2, 6, 5 };
glPolygonMode(GL_FRONT, GL_FILL);
glPushMatrix();
glTranslatef(xLoc, yLoc, zLoc);
glRotatef(xRotation, 1, 0, 0);
glRotatef(yRotation, 0, 1, 0);
glRotatef(zRotation, 0, 0, 1);
glScalef(xSize, ySize, zSize);
glBegin(GL_POLYGON);
for (int i = 0; i < 4; i++) {
glVertex3f(xPts[i], yPts[i], zPts[i]);
}
for (int i = 4; i < 8; i++) {
glVertex3f(xPts[i], yPts[i], zPts[i]);
}
for (int i = 0; i < 4; i++) {
glVertex3f(xPts[sideA[i]], yPts[sideA[i]], zPts[sideA[i]]);
}
for (int i = 0; i < 4; i++) {
glVertex3f(xPts[sideB[i]], yPts[sideB[i]], zPts[sideB[i]]);
}
for (int i = 0; i < 4; i++) {
glVertex3f(xPts[sideC[i]], yPts[sideC[i]], zPts[sideC[i]]);
}
for (int i = 0; i < 4; i++) {
glVertex3f(xPts[sideD[i]], yPts[sideD[i]], zPts[sideD[i]]);
}
glEnd();
glPopMatrix();
这成功地绘制了一个方形平截头体,我可以毫无问题地旋转、缩放和平移它。但是,阴影已关闭。它应该是亮黄色,但所有侧面看起来都被均匀着色。你可以看到我的阴影一般适用于我所有其他可爱的形状。
我要建造我的方形平截头体是完全错误的吗?如何让阴影正确应用到它?