nimo New.Internet.Master.Operator | Salut,
J'ai mis en place les transformation, mais je voudrai que quequ'un me dise comment je peu faire pour que ma function sequence() fonctionne correctement ? SVP, merci
Code :
- #include <stdlib.h>
- #include <GL/glut.h>
- void init(void);
- void display(void);
- void keyboard(unsigned char, int, int);
- void resize(int, int);
- int is_depth; /* depth testing flag */
- int frame=0;
- // Double array of undefined first and defined second
- GLfloat vertices[][3] =
- {
- /********************************************************* A LETTER **************************************************/
- /* first face
- /*0*/ {-1.0,-0.60,/**/-1.0},
- /*1*/ {-0.80,-0.60,/**/-1.0},
- /*2*/ {-0.80,0.60,/**/-1.0},
- /*3*/ {-1.0,0.60,/**/-1.0},
-
- /*4*/ {-0.80,-0.20,/**/-1.0},
- /*5*/ {-0.40,-0.20,/**/-1.0},
- /*6*/ {-0.40,0.00,/**/-1.0},
- /*7*/ {-0.80,0.00,/**/-1.0},
-
- /*8*/ {-0.80,0.40,/**/-1.0},
- /*9*/ {-0.40,0.40,/**/-1.0},
- /*10*/ {-0.40,0.60,/**/-1.0},
- /*11*/ {-0.80,0.60,/**/-1.0},
-
- /*12*/ {-0.40,-0.60,/**/-1.0},
- /*13*/ {-0.20,-0.60,/**/-1.0},
- /*14*/ {-0.20,0.60,/**/-1.0},
- /*15*/ {-0.40,0.60,/**/-1.0},
-
- /* second face
- /*16*/ {-1.0,-0.60,/**/-0.50},
- /*17*/ {-0.80,-0.60,/**/-0.50},
- /*18*/ {-0.80,0.60,/**/-0.50},
- /*19*/ {-1.0,0.60,/**/-0.50},
-
- /*20*/ {-0.80,-0.20,/**/-0.50},
- /*21*/ {-0.40,-0.20,/**/-0.50},
- /*22*/ {-0.40,0.00,/**/-0.50},
- /*23*/ {-0.80,0.00,/**/-0.50},
-
- /*24*/ {-0.80,0.40,/**/-0.50},
- /*25*/ {-0.40,0.40,/**/-0.50},
- /*26*/ {-0.40,0.60,/**/-0.50},
- /*27*/ {-0.80,0.60,/**/-0.50},
-
- /*28*/ {-0.40,-0.60,/**/-0.50},
- /*29*/ {-0.20,-0.60,/**/-0.50},
- /*30*/ {-0.20,0.60,/**/-0.50},
- /*31*/ {-0.40,0.60,/**/-0.50},
-
- /********************************************************* N LETTER **************************************************/
-
- /* first face
- /*32*/ {0.20,-0.60,/**/-1.0},
- /*33*/ {0.40,-0.60,/**/-1.0},
- /*34*/ {0.40,0.60,/**/-1.0},
- /*35*/ {0.20,0.60,/**/-1.0},
-
- /*36*/ {0.40,0.20,/**/-1.0},
- /*37*/ {0.80,-0.60,/**/-1.0},
- /*38*/ {0.80,-0.20,/**/-1.0},
- /*39*/ {0.40,0.60,/**/-1.0},
-
- /*40*/ {0.80,-0.60,/**/-1.0},
- /*41*/ {1.0,-0.60,/**/-1.0},
- /*42*/ {1.0,0.60,/**/-1.0},
- /*43*/ {0.80,0.60,/**/-1.0},
-
- /* second face
- /*44*/ {0.20,-0.60,/**/-0.50},
- /*45*/ {0.40,-0.60,/**/-0.50},
- /*46*/ {0.40,0.60,/**/-0.50},
- /*47*/ {0.20,0.60,/**/-0.50},
-
- /*48*/ {0.40,0.20,/**/-0.50},
- /*49*/ {0.80,-0.60,/**/-0.50},
- /*50*/ {0.80,-0.20,/**/-0.50},
- /*51*/ {0.40,0.60,/**/-0.50},
-
- /*52*/ {0.80,-0.60,/**/-0.50},
- /*53*/ {1.0,-0.60,/**/-0.50},
- /*54*/ {1.0,0.60,/**/-0.50},
- /*55*/ {0.80,0.60,/**/-0.50}
-
- };
-
- /************************************************* Color settings *****************************************************/
- GLfloat colors[][3] =
- {
-
- // Color for A
- /*0*/ {0.0, 0.0, 1.0}, // Blue
- /*1*/ {0.0, 0.0, 1.0},
- /*2*/ {0.0, 0.0, 1.0},
- /*3*/ {0.0, 0.0, 1.0},
- /*4*/ {0.0, 0.0, 1.0},
- /*5*/ {0.0, 0.0, 1.0},
- /*6*/ {0.0, 0.0, 1.0},
- /*7*/ {0.0, 0.0, 1.0},
-
- /*8*/ {0.0, 0.0, 1.0},
- /*9*/ {0.0, 0.0, 1.0},
- /*10*/ {0.0, 0.0, 1.0},
- /*11*/ {0.0, 0.0, 1.0},
- /*12*/ {0.0, 0.0, 1.0},
- /*13*/ {0.0, 0.0, 1.0},
- /*14*/ {0.0, 0.0, 1.0},
- /*15*/ {0.0, 0.0, 1.0},
-
- /*16*/ {0.0, 1.0, 0.0}, // Green
- /*17*/ {0.0, 1.0, 0.0},
- /*18*/ {0.0, 1.0, 0.0},
- /*19*/ {0.0, 1.0, 0.0},
- /*20*/ {0.0, 1.0, 0.0},
- /*21*/ {0.0, 1.0, 0.0},
- /*22*/ {0.0, 1.0, 0.0},
- /*23*/ {0.0, 1.0, 0.0},
-
- /*24*/ {0.0, 1.0, 0.0},
- /*25*/ {0.0, 1.0, 0.0},
- /*26*/ {0.0, 1.0, 0.0},
- /*27*/ {0.0, 1.0, 0.0},
- /*28*/ {0.0, 1.0, 0.0},
- /*29*/ {0.0, 1.0, 0.0},
- /*30*/ {0.0, 1.0, 0.0},
- /*31*/ {0.0, 1.0, 0.0},
-
-
- // Color for N
- /*32*/ {1.0, 1.0, 0.0}, // Yellow
- /*33*/ {1.0, 1.0, 0.0},
- /*34*/ {1.0, 1.0, 0.0},
- /*35*/ {1.0, 1.0, 0.0},
- /*36*/ {1.0, 1.0, 0.0},
- /*37*/ {1.0, 1.0, 0.0},
- /*38*/ {1.0, 1.0, 0.0},
- /*39*/ {1.0, 1.0, 0.0},
-
- /*40*/ {1.0, 1.0, 0.0},
- /*41*/ {1.0, 1.0, 0.0},
- /*42*/ {1.0, 1.0, 0.0},
- /*43*/ {1.0, 1.0, 0.0},
- /*44*/ {1.0, 0.0, 0.0}, // Red
- /*45*/ {1.0, 0.0, 0.0},
- /*46*/ {1.0, 0.0, 0.0},
- /*47*/ {1.0, 0.0, 0.0},
-
- /*48*/ {1.0, 0.0, 0.0},
- /*49*/ {1.0, 0.0, 0.0},
- /*50*/ {1.0, 0.0, 0.0},
- /*51*/ {1.0, 0.0, 0.0},
- /*52*/ {1.0, 0.0, 0.0},
- /*53*/ {1.0, 0.0, 0.0},
- /*54*/ {1.0, 0.0, 0.0},
- /*55*/ {1.0, 0.0, 0.0}
- };
-
- void polygon(int a, int b, int c , int d)
- {
- /* draw a polygon via list of vertices */
- glShadeModel(GL_SMOOTH);
- glBegin(GL_POLYGON);
- glColor3fv(colors[a]);
- glVertex3fv(vertices[a]);
- glColor3fv(colors[b]);
- glVertex3fv(vertices[b]);
- glColor3fv(colors[c]);
- glVertex3fv(vertices[c]);
- glColor3fv(colors[d]);
- glVertex3fv(vertices[d]);
- glEnd();
- }
-
-
- void nimo(void)
- {
-
- /* map vertices to faces */
-
- /************************************************* POLYGONES FOR A ********************************************************/
- /*1*/ polygon(0,1,2,3);
- polygon(1,17,18,2);
- polygon(3,19,16,0);
- polygon(16,17,18,19);
- polygon(0,1,17,16);
- polygon(3,2,18,19);
-
- /*2*/ polygon(4,5,6,7);
- polygon(7,6,22,23);
- polygon(5,21,22,6);
- polygon(4,20,23,7);
- polygon(20,21,22,23);
- polygon(4,5,21,20);
-
- /*3*/ polygon(8,9,10,11);
- polygon(24,25,26,27);
- polygon(8,24,27,11);
- polygon(9,25,26,10);
- polygon(8,9,25,24);
- polygon(11,10,26,27);
-
- /*4*/ polygon(12,13,14,15);
- polygon(28,29,30,31);
- polygon(12,13,29,28);
- polygon(15,14,30,31);
- polygon(12,28,31,15);
- polygon(13,29,30,14);
-
- /************************************************* POLYGONES FOR N ********************************************************/
- /*1*/ polygon(32,33,34,35);
- polygon(44,45,46,47);
- polygon(32,33,45,44);
- polygon(35,34,46,47);
- polygon(34,46,45,33);
- polygon(44,32,35,47);
-
- /*2*/ polygon(36,37,38,39);
- polygon(48,49,50,51);
- polygon(36,37,49,48);
- polygon(51,50,38,39);
- polygon(36,39,51,48);
- polygon(37,49,50,38);
-
- /*3*/ polygon(40,41,42,43);
- polygon(52,53,54,55);
- polygon(40,41,53,52);
- polygon(43,42,54,55);
- polygon(41,53,54,42);
- polygon(52,40,43,55);
-
- }
-
- // Keyboard input from user for transformation
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key)
- {
- /******************************************** Translate ***************************************************/
- case 'd': //"d": move right
- case 'D':
- glTranslatef(0.10, 0.0, 0.0);
- break;
- case 'a': //"a": move left
- case 'A':
- glTranslatef(-0.10, 0.0, 0.0);
- break;
- case 'w': //"w": move up
- case 'W':
- glTranslatef(0.0, 0.10, 0.0);
- break;
- case 's': //"s": move down
- case 'S':
- glTranslatef(0.0, -0.10, 0.0);
- break;
-
- /************************************************** Rotate ********************************************************/
- case 'u':
- case 'U':
- glRotatef(3.0, 1.0, 0.0, 0.0); /* rotate up */
- break;
- case 'j':
- case 'J':
- glRotatef(-3.0, 1.0, 0.0, 0.0); /* rotate down */
- break;
- case 'i':
- case 'I':
- glRotatef(3.0, 0.0, 1.0, 0.0); /* rotate left */
- break;
- case 'k':
- case 'K':
- glRotatef(-3.0, 0.0, 1.0, 0.0); /* rotate right */
- break;
- case 'o':
- case 'O':
- glRotatef(3.0, 0.0, 0.0, 1.0); /* rotate left */
- break;
- case 'l':
- case 'L':
- glRotatef(-3.0, 0.0, 0.0, 1.0); /* rotate right */
- break;
-
- /********************************************** Scale *************************************************/
- case 'g':
- case 'G':
- glScalef(1.10, 1.10, 1.10);
- break;
- case 'b':
- case 'B':
- glScalef(0.90, 0.90, 0.90);
- break;
-
- /***************************************** Depth on or off **********************************************/
- case 't':
- case 'T':
- if (is_depth)
- {
- is_depth = 0;
- glDisable(GL_DEPTH_TEST);
- }
- else
- {
- is_depth = 1;
- glEnable(GL_DEPTH_TEST);
- }
- }
- display();
- }
-
- void sequence(void)
- {
- if ((frame >=0 ) && (frame <10))
- {
- glTranslatef(0.10, 0.0, 0.0);
- }
- else if ((frame >=10 ) && (frame <20))
- {
- glRotatef(-3.0, 0.0, 0.0, 1.0);
- }
- // glRotatef(-3.5, 0.0, 0.0, 1.0);
- // glTranslatef(0.50, 0.0, 0.0);
-
- frame ++;
- display();
- }
-
- void resize(int width, int height)
- {
- if (height == 0) height = 1;
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- /* note we divide our width by our height to get the aspect ratio */
- gluPerspective(45.0, width / height, 1.0, 400.0);
-
- /* set initial position */
- glTranslatef(0.0, 1.0, -10.0);
- glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
-
- glMatrixMode(GL_MODELVIEW);
- }
-
-
- void display(void)
- {
- /* display callback, clear frame buffer and z buffer,
- rotate cube and draw, swap buffers */
- if (is_depth)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- else
- glClear(GL_COLOR_BUFFER_BIT);
- nimo();
- glFlush();
- glutSwapBuffers();
- }
- int main (int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(800, 600);
- glutInitWindowPosition(40, 40);
- glutCreateWindow("2219191: ALEXANDRE NALIN" );
- init();
- sequence();
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- /* this time we're going to keep the aspect ratio
- constant by trapping the window resizes */
- glutReshapeFunc(resize);
- glutMainLoop();
- return 0;
- }
- void init(void)
- {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glEnable(GL_DEPTH_TEST);
- is_depth = 1;
- glMatrixMode(GL_MODELVIEW);
- }
- // END OF PROGRAM
|
---------------
NEC 3500 | YAMADA 6600 | NIMO_CORP
|