作业帮 > 综合 > 作业

OpenGL,一个旋转的正方体,为什么红色的面没有显示.

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/06 03:09:23
OpenGL,一个旋转的正方体,为什么红色的面没有显示.
#include
GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},
\x09\x09{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},
\x09\x09{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};
GLfloat colors[][3] = {{1.0,0.0,0.0},{0.0,1.0,1.0},
\x09\x09{1.0,1.0,0.0},{0.0,1.0,0.0},
\x09\x09{0.0,0.0,1.0},{1.0,0.0,1.0}};
int axis;
float theta[3];
void polygon(int a,int b,int c,int d)
{
\x09glBegin(GL_POLYGON);
\x09glVertex3fv(vertices[a]);
\x09glVertex3fv(vertices[b]);
\x09glVertex3fv(vertices[c]);
\x09glVertex3fv(vertices[d]);
\x09glEnd();
}
void colorcube()
{
\x09glColor3fv(colors[0]);
\x09polygon(0,3,2,1);
\x09glColor3fv(colors[1]);
\x09polygon(2,3,7,6);
\x09glColor3fv(colors[2]);
\x09polygon(3,0,4,7);
\x09glColor3fv(colors[3]);
\x09polygon(1,2,6,5);
\x09glColor3fv(colors[4]);
\x09polygon(4,5,6,7);
\x09glColor3fv(colors[5]);
\x09polygon(5,4,0,1);
}
void spinCube()
{
\x09theta[axis] += 1.0;
\x09if (theta[axis] > 360.0) theta[axis] -= 360.0;
\x09glutPostRedisplay();
}
void mouse(int btn,int state,int x,int y)
{
\x09if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)\x09axis = 0;
\x09if (btn == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)axis = 1;
\x09if (btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)\x09axis = 2;
}
void init()
{
\x09//glClearColor(0.0,0.0,0.0,0.0);
\x09//glColor3f(1.0,1.0,1.0);
}
void display(void)
{
\x09glClear(GL_COLOR_BUFFER_BIT);
\x09glMatrixMode(GL_MODELVIEW);
\x09glLoadIdentity();
\x09gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
\x09glLoadIdentity();
\x09glRotatef(theta[0],1.0,0.0,0.0);
\x09glRotatef(theta[1],0.0,1.0,0.0);
\x09glRotatef(theta[2],0.0,0.0,1.0);
\x09colorcube();
\x09glFlush();
\x09glutSwapBuffers();
}
void reshape(int w,int h)
{
\x09glViewport(0,0,w,h);
\x09glMatrixMode(GL_PROJECTION);
\x09glLoadIdentity();
\x09glOrtho(-4.0,4.0,-4.0,4.0,-4.0,4.0);
}
int main(int argc,char **argv)
{
\x09glutInit(&argc,argv);
\x09glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
\x09glutInitWindowSize(400,400);
\x09glutInitWindowPosition(200,200);
\x09glutCreateWindow("OpenGL");
\x09glutDisplayFunc(display);
\x09glutReshapeFunc(reshape);
\x09glutIdleFunc(spinCube);
\x09glutMouseFunc(mouse);
\x09init();
\x09glutMainLoop();
}
OpenGL,一个旋转的正方体,为什么红色的面没有显示.
#include "stdafx.h"
#include
#include
GLfloat vertices[][3] = {{-1.0,-1.0,1.0},{-1.0,1.0,1.0},
\x05\x05{1.0,1.0,1.0},{1.0,-1.0,1.0},{-1.0,-1.0,-1.0},
\x05\x05{-1.0,1.0,-1.0},{1.0,1.0,-1.0},{1.0,-1.0,-1.0}};
GLfloat colors[][3] = {{1.0,0.0,0.0},{0.0,1.0,1.0},
\x05\x05{1.0,1.0,0.0},{0.0,1.0,0.0},
\x05\x05{0.0,0.0,1.0},{1.0,0.0,1.0}};
int axis;
float theta[3];
void polygon(int a,int b,int c,int d)
{
\x05glBegin(GL_POLYGON);
\x05glVertex3fv(vertices[a]);
\x05glVertex3fv(vertices[b]);
\x05glVertex3fv(vertices[c]);
\x05glVertex3fv(vertices[d]);
\x05glEnd();
}
void colorcube()
{
\x05glColor3fv(colors[0]);
\x05polygon(0,3,2,1);
\x05glColor3fv(colors[1]);
\x05polygon(2,3,7,6);
\x05glColor3fv(colors[2]);
\x05polygon(3,0,4,7);
\x05glColor3fv(colors[3]);
\x05polygon(1,2,6,5);
\x05glColor3fv(colors[4]);
\x05polygon(4,5,6,7);
\x05glColor3fv(colors[5]);
\x05polygon(5,4,0,1);
}
void spinCube()
{
\x05theta[axis] += 1.0;
\x05if (theta[axis] > 360.0) theta[axis] -= 360.0;
\x05glutPostRedisplay();
\x05Sleep(90);
}
void mouse(int btn,int state,int x,int y)
{
\x05if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)\x05axis = 0;
\x05if (btn == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)axis = 1;
\x05if (btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)\x05axis = 2;
}
void init()
{
\x05//glClearColor(0.0,0.0,0.0,0.0);
\x05//glColor3f(1.0,1.0,1.0);
}
void display(void)
{
\x05glClear(GL_COLOR_BUFFER_BIT);
\x05glMatrixMode(GL_MODELVIEW);
\x05glLoadIdentity();
\x05gluLookAt(1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0);
\x05glLoadIdentity();
\x05glRotatef(theta[0],1.0,1.0,0.0);
\x05colorcube();
\x05glFlush();
\x05glutSwapBuffers();
}
void reshape(int w,int h)
{
\x05glViewport(0,0,w,h);
\x05glMatrixMode(GL_PROJECTION);
\x05glLoadIdentity();
\x05glOrtho(-4.0,4.0,-4.0,4.0,-4.0,4.0);
}
int main(int argc,char **argv)
{
\x05glutInit(&argc,argv);
\x05glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
\x05glutInitWindowSize(400,400);
\x05glutInitWindowPosition(200,200);
\x05glutCreateWindow("OpenGL");
\x05glutDisplayFunc(display);
\x05glutReshapeFunc(reshape);
\x05glutIdleFunc(spinCube);
\x05glutMouseFunc(mouse);
\x05init();
\x05glutMainLoop();
}
改下旋转轴就 看到啦
再问: 仔细看它的旋转,只有五种颜色,
再答: 眼睛都看花了,数据不好检查啊,你有一个面的坐标错了,和其他面混合在一起了,所以你永远都看不到那个面
将一个表面涂有红色的长方体,分割成若干个棱长1厘米的小正方体,其中1面都没有红色的小正方体只 一个正方体由27个小正方体组成,这是一个6个面都是红色的魔方,问六面都没有颜色的小正方体有几个? 一个大正方体,表面全涂上红色后,被分割成若干个体积都等于1的小正方体,如果在这些小正方体中,六个面都没有涂红色的小正方体 一个大正方体,表面全涂上红色后,被分割成若干个体积都等于1的小正方体 如果在这些小正方体中,六个面都没有涂红色的小正方体 求算法:opengl 绕任意轴旋转后的坐标 一个6面都是红色的魔方,一共有54块正方体,一面是红色的正方体有几块.每面有9个小正方体 一个棱长4厘米的正方体6面都涂上红色,把它分成棱长是1厘米的小正方体,有多少个6面没有涂色的小正方体? 一个正方体的表面积涂满了红色,然后切成大小相同的27个小正方体.1、3个面有红色有( )个,一个面有红色 关于正方体的奥数题把一个正方体的六个面涂上红色,然后把他据成四个同样的小长方体,没有涂色的面积是60平方厘米,求涂上红色 一个表面涂满红色的长方体,恰好能切成若干个棱长为1分米的正方体,其中有8个小正方体每个面都没有红色,那么这个长方体的体积 把一个6面都涂上红色的正方体木块,锯成( )块小正方体时,一面涂红色的小正方体为96块 将一个正方体木块6个面都涂上红色,把它切成大小相等的8块小正方体.3个面涂上红色的小正方体有【】块