4. glutSwapBuffers();
}
void spinDisplay()
{
spin += 1; if (spin>360.)spin = 0.;
glutPostRedisplay();
}
void keyboard(unsigned char key, int xx, int yy)
{
switch (key)
{
case '?': cout << "nUse:n '?' 'x' 'y' 'z' 'a' 'b' 'c' 'w' 's' 'S' ' ' keys
for animationn" << endl; break;
case 'x': X = 1; Y = Z = 0; break;
case 'y': Y = 1; X = Z = 0; break;
case 'z': Z = 1; X = Y = 0; break;
case 'a': a += .01; break;
case 'b': b += .01; break;
case 'c': c += .01; break;
case 'A': a -= .01; break;
case 'B': b -= .01; break;
case 'C': c -= .01; break;
case 'h': x1 += .1; break;
case 'v': yy1 += .1; break;
case 'd': z1 += .1; break;
case 'H': x1 -= .1; break;
case 'V': yy1 -= .1; break;
case 'D': z1 -= .1; break;
case ' ': spin = x = y = z = .0; break;
case 'w': wire = ++wire % 2; break;
case 's': glShadeModel(GL_SMOOTH); break;
case 'S': glShadeModel(GL_FLAT); break;
}
glutPostRedisplay();
}
int ObjectSpin(int x, int y)
{
if (x >= 70 && x <= 230 && y >= 54 && y <= 140){
ObjectLbl = 1; }
if (x >= 273 && x <= 491 && y >= 67 && y <= 140){
ObjectLbl = 2; }
if (x >= 520 && x <= 680 && y >= 54 && y <= 140){
ObjectLbl = 3; }
if (x >= 723 && x <= 941 && y >= 67 && y <= 140){
ObjectLbl = 4; }
if (x >= 970 && x <= 1120 && y >= 54 && y <= 140){
ObjectLbl = 5; }
if (x >= 37 && x <= 260 && y >= 242 && y <= 360){
ObjectLbl = 6; }
if (x >= 296 && x <= 453 && y >= 256 && y <= 344){
5. ObjectLbl = 7; }
if (x >= 487 && x <= 711 && y >= 242 && y <= 360){
ObjectLbl = 8; }
if (x >= 746 && x <= 903 && y >= 256 && y <= 344){
ObjectLbl = 9; }
if (x >= 937 && x <= 1162 && y >= 242 && y <= 360){
ObjectLbl = 10; }
return ObjectLbl;
}
void mouse(int button, int state, int xx, int yy)
{
glutIdleFunc(spinDisplay);
switch (button)
{
case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { choice = ObjectSpin(xx,yy); X =
1; Y =1, Z = -1; } break;
case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN){ choice = 0; }break;
//glutIdleFunc(NULL);
}
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport(0., 0., 1500., 800.);
glLoadIdentity();
gluPerspective(80., (GLfloat)w / (GLfloat)h, .1, 190.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //important: last line must be glLoadIdentity() for coloring
with openGL
// glTranslatef (.0, .0, -4.); //do not translate at all if glLoadIdentity() is
used
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1200, 700); glutInitWindowPosition(0, 0);
glutCreateWindow("Brian's GLUT Window");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutMainLoop();
}
//////////////////////////////////////////// END OF PROGRAM
///////////////////////////////////