Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Mat_info.cxx
- *
- * Created on: 4 janv. 2012
- * Author: schflo
- */
- #include <GL/glut.h>
- #include "math.h"
- #include <cmath>
- using namespace std;
- bool signe = 0;
- bool signe2 = 0;
- int vitesse = O.5;
- bool presse = 0;
- namespace
- {
- GLfloat teta1 = 20;
- GLfloat teta2 = 30 ;
- GLfloat Rotation[16]= { cos(teta1), sin(teta1), 0, 0,
- -sin(teta1), cos(teta1), 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1 };
- GLfloat Translation[16] = { 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0.43, 0.25, 0.0, 1 };
- GLfloat Echelle[16] = { 0.4, 0, 0, 0,
- 0, 0.4, 0, 0,
- 0, 0, 0.4, 0,
- 0, 0, 0, 1 };
- GLfloat Q[16] = { 0, 0, 1, 0,
- 0.5, -sqrt(3)/2, 0, 0,
- sqrt(3)/2, 0.5, 0, 0,
- 0, 0, 0, 1 };
- GLfloat Qt[16] = { 0, 0.5, sqrt(3)/2, 0,
- 0, -sqrt(3)/2, 0.5, 0,
- 1, 0, 0, 0,
- 0, 0, 0, 1 };
- GLfloat Rotation2[16]= { cos(teta2), sin(teta2), 0, 0,
- -sin(teta2), cos(teta2), 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1 };
- void Carre ()
- {
- glClearColor(0.0,0.0,0.0,0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadMatrixf(Echelle);
- glMultMatrixf(Translation);
- glMultMatrixf(Rotation);
- glMultMatrixf(Q);
- glMultMatrixf(Rotation2);
- glMultMatrixf(Qt);
- glPointSize(2.0);
- typedef struct
- {
- float x;
- float y;
- float z;
- float r;
- float g;
- float b;
- } point;
- point p[8]= {
- { -0.5, -0.5, 0.5, 1.0, 0.0, 0.0 },
- { -0.5, 0.5, 0.5, 0.0, 1.0, 0.0 },
- { 0.5, 0.5, 0.5, 0.0, 0.0, 1.0 },
- { 0.5, -0.5, 0.5, 1.0, 1.0, 1.0 },
- { -0.5, -0.5, -0.5, 1.0, 0.0, 0.0 },
- { -0.5, 0.5, -0.5, 0.0, 1.0, 0.0 },
- { 0.5, 0.5, -0.5, 0.0, 0.0, 1.0 },
- { 0.5, -0.5, -0.5, 1.0, 1.0, 1.0 }};
- int f[6][4]= {
- { 0, 1, 2, 3 },
- { 3, 2, 6, 7 },
- { 4, 5, 6, 7 },
- { 0, 1, 5, 4 },
- { 1, 5, 6, 2 },
- { 0, 4, 7, 3 }};
- for (int i (0) ; i < 6 ; ++i)
- {
- glBegin(GL_POLYGON);
- for (int j (0) ; j < 4 ; ++j)
- {
- glColor3f(p[f[i][j]].r,p[f[i][j]].g,p[f[i][j]].b);
- glVertex3f(p[f[i][j]].x,p[f[i][j]].y,p[f[i][j]].z);
- }
- glEnd();
- }
- glutSwapBuffers();
- } // Carre ()
- void Clavier (unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 49:
- vitesse=1;
- break;
- case 50:
- vitesse=2;
- break;
- case 51:
- vitesse=3;
- break;
- case 52:
- vitesse=4;
- break;
- case 53:
- vitesse=5;
- break;
- case 54:
- vitesse=6;
- break;
- case 55:
- vitesse=7;
- break;
- case 56:
- vitesse=8;
- break;
- case 57:
- vitesse=9;
- break;
- }
- } // Clavier ()
- void GestionFleches (int key, int x, int y)
- {
- switch (key)
- {
- case GLUT_KEY_LEFT:
- signe=0;
- break;
- case GLUT_KEY_RIGHT:
- signe=1;
- break;
- case GLUT_KEY_UP:
- //signe2=0;
- break;
- case GLUT_KEY_DOWN:
- //signe2=0;
- break;
- }
- } // GestionFleches ()
- void idle ()
- {
- if (!signe)
- teta1 -= 0.001 * vitesse;
- if (signe)
- teta1 += 0.001 * vitesse;
- if (!signe)
- teta2 += 0.001 * vitesse;
- if (signe)
- teta2 -= 0.001 * vitesse;
- Rotation[0] = cos(teta1);
- Rotation[1] = sin(teta1);
- Rotation[4] = -sin(teta1);
- Rotation[5] = cos(teta1);
- glLoadMatrixf(Rotation);
- Rotation2[0] = cos(teta2);
- Rotation2[1] = sin(teta2);
- Rotation2[4] = -sin(teta2);
- Rotation2[5] = cos(teta2);
- glLoadMatrixf(Rotation2);
- glutPostRedisplay();
- } // idle ()
- void reshape (int x, int y)
- {
- if (x < y)
- glViewport(0, (y-x)/2, x, x);
- else
- glViewport((x-y)/2, 0, y, y) ;
- } // reshape ()
- int xold;
- int yold;
- int anglex;
- int angley;
- void souris (int boutton, int state, int x, int y)
- {
- if (boutton == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- {
- presse = true;
- // vitesse1 = 0;
- // vitesse2 = 0;
- anglex = anglex + (x-xold);
- angley = angley + (y-yold);
- }
- else
- presse = false;
- // /* si on appuie sur le bouton gauche */
- // if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
- // {
- // presse = true;
- // xold = x; /* on sauvegarde la position de la souris */
- // yold=y;
- // }
- // /* si on relache le bouton gauche */
- // if (button == GLUT_LEFT_BUTTON && state == GLUT_UP)
- // presse = false; /* le booleen presse passe a 0 (faux) */
- } // souris()
- void mouvement_souris (int x, int y)
- {
- if (presse)
- {
- anglex = anglex + (x-xold);
- angley = angley + (y-yold);
- }
- glutPostRedisplay();
- // if (presse) /* si le bouton gauche est presse */
- // {
- // /* on modifie les angles de rotation de l’objet
- // en fonction de la position actuelle de la souris et de la derniere
- // position sauvegardee */
- // anglex = anglex + (x-xold);
- // angley = angley + (y-yold);
- // glutPostRedisplay(); /* on demande un rafraichissement de l’affichage */
- // }
- // xold=x; /* sauvegarde des valeurs courante de le position de la souris */
- // yold=y;
- } // mouvement_souris()
- } // namespace
- int main (int argc, char * argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
- glutCreateWindow("Carre");
- glClearColor(1.0, 1.0, 1.0, 0.0);
- glutInitWindowPosition(200, 200);
- glutInitWindowSize(250, 250);
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glutDisplayFunc(Carre);
- glutKeyboardFunc(Clavier);
- glutSpecialFunc(GestionFleches);
- glutIdleFunc(idle);
- glutReshapeFunc(reshape);
- glutMouseFunc(souris);
- glutMotionFunc(mouvement_souris);
- glutMainLoop();
- return 0;
- } // main ()
Add Comment
Please, Sign In to add comment