-2
我想创建一个基本上为2个长方体的“L”形状,我可以做很长的路,但希望能够使用我试图实现的顶点方法创建它。在openGL中创建一个L形
任何人都可以帮忙吗?
float vertices[8][3] = {
{ 0, 2, 0.5 },
{ 0.5, 2, 0.5 },
{ 0.5, 0, 0.5 },
{ 0, 0, 0.5 },
{ 0, 2, -0.5 },
{ 0.5, 2, -0.5 },
{ 0.5, 0, -0.5 },
{ 0, 0, -0.5 }
};
//set up the array of colours
float colours[6][3] = {
{ 1.0, 0.0, 1.0 },
{ 0.5, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 },
{ 0.0, 0.5, 0.0 },
{ 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.5 }
};
void polygon(int a, int b, int c, int d, int colour) {
glColor3fv(colours[colour]);
glBegin(GL_POLYGON);
glVertex3fv(vertices[a]);
glVertex3fv(vertices[b]);
glVertex3fv(vertices[c]);
glVertex3fv(vertices[d]);
glEnd();
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex3fv(vertices[a]);
glVertex3fv(vertices[b]);
glVertex3fv(vertices[c]);
glVertex3fv(vertices[d]);
glEnd();
}
void cube() {
polygon(0, 3, 7, 4, 0); // left
polygon(1, 5, 6, 2, 1);// right
polygon(0, 4, 5, 1, 2);// bottom
polygon(3, 2, 6, 7, 3);// top
polygon(0, 1, 2, 3, 4); // near
polygon(4, 7, 6, 5, 5);// far
}