Documentos de Académico
Documentos de Profesional
Documentos de Cultura
h>
glEnd();
glEnd();
glTranslated(l1,0,0); glRotated(phi2*180/PI,0,0,1);
GLfloat x2 = 0.0,y2 = 0.0,R2 = 1.5; glColor3f(0.2,0.8,0.6); glBegin(GL_LINE_LOOP); for(int k = 0; k < 360;k++) glVertex3f(R2*cos(2*PI*k/360) + x2,R*sin(2*PI*k/360) +y2 ,0.0); glEnd();
glPopMatrix();
glPushMatrix();
GLfloat x1 = 0.0,y1 = 0.0,R1 = 1.5; glColor3f(0.2,0.4,0.6); glBegin(GL_LINE_LOOP); for(int j = 0; j < 360;j++) glVertex3f(R1*cos(2*PI*j/360) + x1,R*sin(2*PI*j/360) +y1 ,0.0); glEnd();
glPopMatrix();
void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glColor3f(1.0, 1.0, 1.0); Draw(); glPopMatrix(); glutSwapBuffers(); }
void spinDisplay(void) { phi1 = phi1 + 0.001; if (phi1 > 2*PI) phi1 = phi1 - 2*PI; glutPostRedisplay(); glPopMatrix(); }
glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void mouse(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) glutIdleFunc(spinDisplay); break; case GLUT_MIDDLE_BUTTON: if (state == GLUT_DOWN) glutIdleFunc(NULL); break; default: break; } }
void keyboard (unsigned char key, int x, int y) { switch (key) { case 'R': case 'r': glutIdleFunc(spinDisplay); break; case 'S': case 's': glutIdleFunc(NULL); break; case 27: exit(0); break; default: break; } }
glutCreateMenu(menu_option); glutAddMenuEntry("Rotate Rectangle", 1); glutAddMenuEntry("Stop Rotate Rectangle", 2); glutAddMenuEntry("---------------------", 0);
glutAddSubMenu("Enable Rotate And Stop", menu_title[0]); glutAddSubMenu("Disable Rotate And Stop", menu_title[1]);
glutAttachMenu(GLUT_RIGHT_BUTTON); }
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); create_menu(); glutMainLoop(); return 0; }