Partage
  • Partager sur Facebook
  • Partager sur Twitter

Rotation Opengl

    19 juillet 2007 à 8:42:51

    Bonjour,

    Je cherche à faire une rotation en opengl.

    J'ai comprit comment faire les rotations, mais le problème c'est que toutes les autres figures tourne aussi autour des axes...

    Pour cela j'ai lu qu'il fallait faire une translation. Mais si je fais une translation, toutes mes figures sont translatés et se mettes encore à tourner autour de l'axe...

    Merci d'avance :)
    • Partager sur Facebook
    • Partager sur Twitter
      19 juillet 2007 à 9:17:37

      Hello,

      Le mieux je crois est que tu relises le cours de Kayl sur OpenGL. http://www.siteduzero.com/tuto-3-1346-0-creez-des-programmes-en-3d-avec-opengl.html
      • Partager sur Facebook
      • Partager sur Twitter
      Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
        19 juillet 2007 à 9:31:57

        Ca fait 2 fois ce matin ^^.

        Je fais comme l'exercice sur la grue mais moi c'est tou qui se déplace...
        • Partager sur Facebook
        • Partager sur Twitter
          19 juillet 2007 à 10:14:38

          Bon je vais essayer d'expliquer.

          Quand tu utilises "glRotated(..,..,..)" TOUT ce qui suit cette ligne sera tourné.
          si tu veux annuler la rotation, il y a 3 possibilités simples:

          1) Annuler la rotation en appelant la meme fonction avec l'angle négatif.
          2) Utiliser glLoadIdentity(); qui te ramènes en (0,0,0)
          3) Mettre un glPushMatrix(); avant ta rotation, faire ta roattion, dessiner ce qui est tourné puis appeler glPopMatrix();
          • Partager sur Facebook
          • Partager sur Twitter
          Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
            19 juillet 2007 à 10:25:29

            En faite, je me suis amusé à créé un Rubik's Cube grâce à ce tutoriel, mais je n'arrive toujours pas à faire tourner...

            J'ai essayer ta méthode mais mon problème c'est que tout se déplace sauf ce qui n'a pas été modifier avant...

            Je me suis peut être mal parti dans la création de mon algorithme ?

            J'ai fais une fonction dessiner comme si dessous.
            Et je n'arrive pas à faire tourner la face supérieur...

            Tu pourais juste me montrer pour cette face ?
            Car la je crois avoir comprit la méthode mais je ne sais pas comment faire dans mon algorithme...


            void Dessiner()
            {
                glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

                glMatrixMode( GL_MODELVIEW );
                glLoadIdentity( );
                gluLookAt(6,0,0,0,0,0,0,0,2);

                //glRotated(angleZ,0,0,1.5);
                //glRotated(angleX,0,1,0);
               
                ////////////////////////////////////////////
                ///                Ligne                 ///
                ////////////////////////////////////////////
               
                glBegin(GL_LINES);
               
                ////////////////////////////////////////////
                ///            Face bleu                 ///
                ////////////////////////////////////////////
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,1.5,0.5);
                glVertex3d(1.5,1.5,0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,1.5,-0.5);
                glVertex3d(1.5,1.5,-0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-0.5,1.5,1.5);
                glVertex3d(-0.5,1.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(0.5,1.5,1.5);
                glVertex3d(0.5,1.5,-1.5);
               
                ////////////////////////////////////////////
                ///            Face orange               ///
                ////////////////////////////////////////////
               
                glColor3ub(0,0,0);
                glVertex3d(1.5,1.5,0.5);
                glVertex3d(1.5,-1.5,0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(1.5,1.5,-0.5);
                glVertex3d(1.5,-1.5,-0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(1.5,0.5,1.5);
                glVertex3d(1.5,0.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(1.5,-0.5,1.5);
                glVertex3d(1.5,-0.5,-1.5);
               
                ////////////////////////////////////////////
                ///            Face jaune                ///
                ////////////////////////////////////////////
               
                glColor3ub(0,0,0);
                glVertex3d(-0.5,1.5,1.5);
                glVertex3d(-0.5,-1.5,1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(0.5,1.5,1.5);
                glVertex3d(0.5,-1.5,1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,0.5,1.5);
                glVertex3d(1.5,0.5,1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,-0.5,1.5);
                glVertex3d(1.5,-0.5,1.5);
               
                ////////////////////////////////////////////
                ///            Face vert                 ///
                ////////////////////////////////////////////
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,-1.5,0.5);
                glVertex3d(1.5,-1.5,0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,-1.5,-0.5);
                glVertex3d(1.5,-1.5,-0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-0.5,-1.5,1.5);
                glVertex3d(-0.5,-1.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(0.5,-1.5,1.5);
                glVertex3d(0.5,-1.5,-1.5);
               
                ////////////////////////////////////////////
                ///            Face marron               ///
                ////////////////////////////////////////////
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,1.5,0.5);
                glVertex3d(-1.5,-1.5,0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,1.5,-0.5);
                glVertex3d(-1.5,-1.5,-0.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,0.5,1.5);
                glVertex3d(-1.5,0.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,-0.5,1.5);
                glVertex3d(-1.5,-0.5,-1.5);
               
                ////////////////////////////////////////////
                ///            Face blanc                ///
                ////////////////////////////////////////////
               
                glColor3ub(0,0,0);
                glVertex3d(-0.5,1.5,-1.5);
                glVertex3d(-0.5,-1.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(0.5,1.5,-1.5);
                glVertex3d(0.5,-1.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,0.5,-1.5);
                glVertex3d(1.5,0.5,-1.5);
               
                glColor3ub(0,0,0);
                glVertex3d(-1.5,-0.5,-1.5);
                glVertex3d(1.5,-0.5,-1.5);
               
                glEnd();
               
                ////////////////////////////////////////////
                ////////////////////////////////////////////
               
                ////////////////////////////////////////////
                ///                 Face                 ///
                ////////////////////////////////////////////
               
               

                ////////////////////////////////////////////
                ///            Face bleu                 ///
                ////////////////////////////////////////////
               
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Haut/Gauche
                glVertex3d(-1.5,1.5,1.5);
                glVertex3d(-0.5,1.5,1.5);
                glVertex3d(-0.5,1.5,0.5);
                glVertex3d(-1.5,1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Haut/Milieu
                glVertex3d(-1.5,1.5,0.5);
                glVertex3d(-0.5,1.5,0.5);
                glVertex3d(-0.5,1.5,-0.5);
                glVertex3d(-1.5,1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Haut/Droite
                glVertex3d(-1.5,1.5,-0.5);
                glVertex3d(-0.5,1.5,-0.5);
                glVertex3d(-0.5,1.5,-1.5);
                glVertex3d(-1.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Milieu/Gauche
                glVertex3d(-0.5,1.5,1.5);
                glVertex3d(0.5,1.5,1.5);
                glVertex3d(0.5,1.5,0.5);
                glVertex3d(-0.5,1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Milieu/Milieu
                glVertex3d(-0.5,1.5,0.5);
                glVertex3d(0.5,1.5,0.5);
                glVertex3d(0.5,1.5,-0.5);
                glVertex3d(-1.5,1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Milieu/Droite
                glVertex3d(-0.5,1.5,-0.5);
                glVertex3d(0.5,1.5,-0.5);
                glVertex3d(0.5,1.5,-1.5);
                glVertex3d(-0.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Bas/Gauche
                glVertex3d(0.5,1.5,1.5);
                glVertex3d(1.5,1.5,1.5);
                glVertex3d(1.5,1.5,0.5);
                glVertex3d(0.5,1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Bas/Milieu
                glVertex3d(0.5,1.5,0.5);
                glVertex3d(1.5,1.5,0.5);
                glVertex3d(1.5,1.5,-0.5);
                glVertex3d(0.5,1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,0,255); // Bas/Droite
                glVertex3d(0.5,1.5,-0.5);
                glVertex3d(1.5,1.5,-0.5);
                glVertex3d(1.5,1.5,-1.5);
                glVertex3d(0.5,1.5,-1.5);
                glEnd();
               
                ////////////////////////////////////////////
                ///            Face orange               ///
                ////////////////////////////////////////////
                 
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Haut/Gauche
                glVertex3d(1.5,1.5,1.5);
                glVertex3d(1.5,0.5,1.5);
                glVertex3d(1.5,0.5,0.5);
                glVertex3d(1.5,1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Haut/Milieu
                glVertex3d(1.5,1.5,0.5);
                glVertex3d(1.5,0.5,0.5);   
                glVertex3d(1.5,0.5,-0.5);
                glVertex3d(1.5,1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Haut/Droite
                glVertex3d(1.5,1.5,-0.5);
                glVertex3d(1.5,0.5,-0.5);
                glVertex3d(1.5,0.5,-1.5);
                glVertex3d(1.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Milieu/Gauche
                glVertex3d(1.5,0.5,1.5);
                glVertex3d(1.5,-0.5,1.5);
                glVertex3d(1.5,-0.5,0.5);
                glVertex3d(1.5,0.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Milieu/Milieu
                glVertex3d(1.5,0.5,0.5);
                glVertex3d(1.5,-0.5,0.5);
                glVertex3d(1.5,-0.5,-0.5);
                glVertex3d(1.5,0.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Milieu/Droite
                glVertex3d(1.5,0.5,-0.5);
                glVertex3d(1.5,-0.5,-0.5);
                glVertex3d(1.5,-0.5,-1.5);
                glVertex3d(1.5,0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Bas/Gauche
                glVertex3d(1.5,-0.5,1.5);
                glVertex3d(1.5,-1.5,1.5);
                glVertex3d(1.5,-1.5,0.5);
                glVertex3d(1.5,-0.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Bas/Milieu
                glVertex3d(1.5,-0.5,0.5);
                glVertex3d(1.5,-1.5,0.5);
                glVertex3d(1.5,-1.5,-0.5);
                glVertex3d(1.5,-0.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,128,0); // Bas/Droite
                glVertex3d(1.5,-0.5,-0.5);
                glVertex3d(1.5,-1.5,-0.5);
                glVertex3d(1.5,-1.5,-1.5);
                glVertex3d(1.5,-0.5,-1.5);
                glEnd();
               
                ////////////////////////////////////////////
                ///            Face jaune                ///
                ////////////////////////////////////////////
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Haut/Gauche
                glVertex3d(-1.5,1.5,1.5);
                glVertex3d(-1.5,0.5,1.5);
                glVertex3d(-0.5,0.5,1.5);
                glVertex3d(-0.5,1.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Haut/Milieu
                glVertex3d(-0.5,1.5,1.5);
                glVertex3d(-0.5,0.5,1.5);   
                glVertex3d(0.5,0.5,1.5);
                glVertex3d(0.5,1.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Haut/Droite
                glVertex3d(0.5,1.5,1.5);
                glVertex3d(0.5,0.5,1.5);
                glVertex3d(1.5,0.5,1.5);
                glVertex3d(1.5,1.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Milieu/Gauche
                glVertex3d(-1.5,0.5,1.5);
                glVertex3d(-1.5,-0.5,1.5);
                glVertex3d(-0.5,-0.5,1.5);
                glVertex3d(-0.5,0.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Milieu/Milieu
                glVertex3d(-0.5,0.5,1.5);
                glVertex3d(-0.5,-0.5,1.5);
                glVertex3d(0.5,-0.5,1.5);
                glVertex3d(0.5,0.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Milieu/Droite
                glVertex3d(0.5,0.5,1.5);
                glVertex3d(0.5,-0.5,1.5);
                glVertex3d(1.5,-0.5,1.5);
                glVertex3d(1.5,0.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Bas/Gauche
                glVertex3d(-1.5,-0.5,1.5);
                glVertex3d(-1.5,-1.5,1.5);
                glVertex3d(-0.5,-1.5,1.5);
                glVertex3d(-0.5,-0.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Bas/Milieu
                glVertex3d(-0.5,-0.5,1.5);
                glVertex3d(-0.5,-1.5,1.5);
                glVertex3d(0.5,-1.5,1.5);
                glVertex3d(0.5,-0.5,1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,0); // Bas/Droite
                glVertex3d(0.5,-0.5,1.5);
                glVertex3d(0.5,-1.5,1.5);
                glVertex3d(1.5,-1.5,1.5);
                glVertex3d(1.5,-0.5,1.5);
                glEnd();
               
                ////////////////////////////////////////////
                ///            Face marron               ///
                ////////////////////////////////////////////
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Haut/Gauche
                glVertex3d(-1.5,1.5,1.5);
                glVertex3d(-1.5,0.5,1.5);
                glVertex3d(-1.5,0.5,0.5);
                glVertex3d(-1.5,1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Haut/Milieu
                glVertex3d(-1.5,1.5,0.5);
                glVertex3d(-1.5,0.5,0.5);   
                glVertex3d(-1.5,0.5,-0.5);
                glVertex3d(-1.5,1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Haut/Droite
                glVertex3d(-1.5,1.5,-0.5);
                glVertex3d(-1.5,0.5,-0.5);
                glVertex3d(-1.5,0.5,-1.5);
                glVertex3d(-1.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Milieu/Gauche
                glVertex3d(-1.5,0.5,1.5);
                glVertex3d(-1.5,-0.5,1.5);
                glVertex3d(-1.5,-0.5,0.5);
                glVertex3d(-1.5,0.5,0.5);
                glEnd();
                 
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Milieu/Milieu
                glVertex3d(-1.5,0.5,0.5);
                glVertex3d(-1.5,-0.5,0.5);
                glVertex3d(-1.5,-0.5,-0.5);
                glVertex3d(-1.5,0.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Milieu/Droite
                glVertex3d(-1.5,0.5,-0.5);
                glVertex3d(-1.5,-0.5,-0.5);
                glVertex3d(-1.5,-0.5,-1.5);
                glVertex3d(-1.5,0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Bas/Gauche
                glVertex3d(-1.5,-0.5,1.5);
                glVertex3d(-1.5,-1.5,1.5);
                glVertex3d(-1.5,-1.5,0.5);
                glVertex3d(-1.5,-0.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Bas/Milieu
                glVertex3d(-1.5,-0.5,0.5);
                glVertex3d(-1.5,-1.5,0.5);
                glVertex3d(-1.5,-1.5,-0.5);
                glVertex3d(-1.5,-0.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(128,0,0); // Bas/Droite
                glVertex3d(-1.5,-0.5,-0.5);
                glVertex3d(-1.5,-1.5,-0.5);
                glVertex3d(-1.5,-1.5,-1.5);
                glVertex3d(-1.5,-0.5,-1.5);
                glEnd();
               
                ////////////////////////////////////////////
                ///            Face blanc                ///
                ////////////////////////////////////////////
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Haut/Gauche
                glVertex3d(-1.5,1.5,-1.5);
                glVertex3d(-1.5,0.5,-1.5);
                glVertex3d(-0.5,0.5,-1.5);
                glVertex3d(-0.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Haut/Milieu
                glVertex3d(-0.5,1.5,-1.5);
                glVertex3d(-0.5,0.5,-1.5);   
                glVertex3d(0.5,0.5,-1.5);
                glVertex3d(0.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Haut/Droite
                glVertex3d(0.5,1.5,-1.5);
                glVertex3d(0.5,0.5,-1.5);
                glVertex3d(1.5,0.5,-1.5);
                glVertex3d(1.5,1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Milieu/Gauche
                glVertex3d(-1.5,0.5,-1.5);
                glVertex3d(-1.5,-0.5,-1.5);
                glVertex3d(-0.5,-0.5,-1.5);
                glVertex3d(-0.5,0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Milieu/Milieu
                glVertex3d(-0.5,0.5,-1.5);
                glVertex3d(-0.5,-0.5,-1.5);
                glVertex3d(0.5,-0.5,-1.5);
                glVertex3d(0.5,0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Milieu/Droite
                glVertex3d(0.5,0.5,-1.5);
                glVertex3d(0.5,-0.5,-1.5);
                glVertex3d(1.5,-0.5,-1.5);
                glVertex3d(1.5,0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Bas/Gauche
                glVertex3d(-1.5,-0.5,-1.5);
                glVertex3d(-1.5,-1.5,-1.5);
                glVertex3d(-0.5,-1.5,-1.5);
                glVertex3d(-0.5,-0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Bas/Milieu
                glVertex3d(-0.5,-0.5,-1.5);
                glVertex3d(-0.5,-1.5,-1.5);
                glVertex3d(0.5,-1.5,-1.5);
                glVertex3d(0.5,-0.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(255,255,255); // Bas/Droite
                glVertex3d(0.5,-0.5,-1.5);
                glVertex3d(0.5,-1.5,-1.5);
                glVertex3d(1.5,-1.5,-1.5);
                glVertex3d(1.5,-0.5,-1.5);
                glEnd();
               
                ////////////////////////////////////////////
                ///            Face vert                 ///
                ////////////////////////////////////////////
               
                glBegin(GL_QUADS);   
                glColor3ub(0,128,0); // Haut/Gauche
                glVertex3d(-1.5,-1.5,1.5);
                glVertex3d(-0.5,-1.5,1.5);
                glVertex3d(-0.5,-1.5,0.5);
                glVertex3d(-1.5,-1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Haut/Milieu
                glVertex3d(-1.5,-1.5,0.5);
                glVertex3d(-0.5,-1.5,0.5);
                glVertex3d(-0.5,-1.5,-0.5);
                glVertex3d(-1.5,-1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Haut/Droite
                glVertex3d(-1.5,-1.5,-0.5);
                glVertex3d(-0.5,-1.5,-0.5);
                glVertex3d(-0.5,-1.5,-1.5);
                glVertex3d(-1.5,-1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Milieu/Gauche
                glVertex3d(-0.5,-1.5,1.5);
                glVertex3d(0.5,-1.5,1.5);
                glVertex3d(0.5,-1.5,0.5);
                glVertex3d(-0.5,-1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Milieu/Milieu
                glVertex3d(-0.5,-1.5,0.5);
                glVertex3d(0.5,-1.5,0.5);
                glVertex3d(0.5,-1.5,-0.5);
                glVertex3d(-1.5,-1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Milieu/Droite
                glVertex3d(-0.5,-1.5,-0.5);
                glVertex3d(0.5,-1.5,-0.5);
                glVertex3d(0.5,-1.5,-1.5);
                glVertex3d(-0.5,-1.5,-1.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Bas/Gauche
                glVertex3d(0.5,-1.5,1.5);
                glVertex3d(1.5,-1.5,1.5);
                glVertex3d(1.5,-1.5,0.5);
                glVertex3d(0.5,-1.5,0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Bas/Milieu
                glVertex3d(0.5,-1.5,0.5);
                glVertex3d(1.5,-1.5,0.5);
                glVertex3d(1.5,-1.5,-0.5);
                glVertex3d(0.5,-1.5,-0.5);
                glEnd();
               
                glBegin(GL_QUADS);
                glColor3ub(0,128,0); // Bas/Droite
                glVertex3d(0.5,-1.5,-0.5);
                glVertex3d(1.5,-1.5,-0.5);
                glVertex3d(1.5,-1.5,-1.5);
                glVertex3d(0.5,-1.5,-1.5);
                glEnd();
                   
                glFlush();
                SDL_GL_SwapBuffers();
            }
            • Partager sur Facebook
            • Partager sur Twitter
              19 juillet 2007 à 10:39:55

              Sincèrement, je pense pas que essayer durant 10 minutes ne soit suffisant pour comprendre l'informatique....
              • Partager sur Facebook
              • Partager sur Twitter
              Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
                19 juillet 2007 à 10:56:19

                Le truc, c'est que je fait des rotation aux débuts des faces, mais mon cube est déformer même si je met le repère par defaut à la fin...

                (Je suis sur ce cube depuis plus de temps que 10 min ;) )
                • Partager sur Facebook
                • Partager sur Twitter
                  19 juillet 2007 à 11:13:18

                  Je pense bien que tu es dessus depuis 10min. Mais c'est le temps entre mon explication, et ta réponse pour me dire que ça marche pas.

                  Il faudrait que tu expliques ce que tu veux faire tourner et je pense que simplifier ton code ne serait pas un luxe. Tu fais au moins 10 dessins de faces carrées, ne serait-il pas mieux de mettre tout ça dans une fonction et l'appeler à chaque fois. Ca rendrait le code plus lisible et digeste.

                  Le plus simple pour tourner qu'une face est la chose suivante:


                  //Dessin des choses pas tournees qui viennent avant
                  glRotatef(angle, 0,0,1);
                  //Dessin de la face
                  glRotatef(-angle, 0,0,1);
                  //Suite du dessin avec des choses pas tournees
                   


                  C'est pas optimal (et de loin...) mais c'est simple à comprendre.
                  • Partager sur Facebook
                  • Partager sur Twitter
                  Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
                    19 juillet 2007 à 11:21:49

                    Pour appeller la fonction j'y avait penser, mais je n'avais pas encore envis de mit attarder...

                    Je vais donc créé une rotation spécifique pour chaques mouvements pour le moment.

                    Merci à toi :)

                    EDIT: J'ai réussit encore merci !!!!
                    • Partager sur Facebook
                    • Partager sur Twitter
                      21 juillet 2007 à 18:44:26

                      Re,

                      Bon, j'ai créé une fonction point(); avec tout les sommet des cubes, et une fonction face qui cree toutes les faces du cubes.

                      J'arrive à la fin, je fait une rotation des face que je veux sur l'axe x (par exemple).

                      Tout marche correctement.

                      Mais mon problème c'est que je n'arrive pas à enchainer deux rotations...

                      La première s'effectue, puis se stop. La deuxième commence mais par dessu la première.

                      J'ai penser, faire un appelle (c'est a dire mettre à jours les couleurs des carrés après rotation) des couleurs.
                      Mais ca fait trois foix que je recommence l'algo au complet et je voudrais savoir si c'est une bonne solution ?

                      Merci
                      • Partager sur Facebook
                      • Partager sur Twitter
                        22 juillet 2007 à 20:26:46

                        Personne pourrait m'aider dans le consepte pour faire deux rotations ?
                        • Partager sur Facebook
                        • Partager sur Twitter
                          23 juillet 2007 à 9:43:08

                          Bon..

                          Tout ça c'est expliqué dans le cours de Kayl et dans n'importe quel bouquin/tuto traitant de l'Ogl..

                          Quand tu fais une rotation (ou n'importe quelle transformation), l'ordre est très important.

                          Tu as plusieurs solution (tout t'as été expliqué plus haut..)

                          glPushMatrix() Qui va te mettre une matrice sur la pile.
                          Tu fait ta rotation
                          glPopMatrix() pour dégager la premiere matrice de la pile et pouvoir recommencer tranquile

                          glPushMatrix()
                          Deuxieme rotation
                          glPopMatrix()

                          Plus simple:
                          Pour effectuer une rotation, ogl multilplie la matrice de transformation active (en haut de la pile en fait) par la matrice colonne de la position d'un point (glVertex3f(x, y, z) par ex) (en fait c'est plutôt l'inverse en ce qui conserve la multiplication, vu que la multiplication de matrice n'est pas commutative).

                          Or, apres chaque transformation, la matrice de transformation active est modifiée (logique, pour coller à la nouvelle position/orientation des axes, d'où d'ailleurs l'importance de l'ordre des transformations...).
                          Donc, entre chaque transformation, une solution simple si tu n'arrives pas à enchainer deux rotations serait de charger la matrice identité de transformation:

                          1,0,0
                          0,1,0
                          0,0,1

                          Ce qui se fait tout naturellement par un appel à glLoadIdetity().

                          Sinon, honnêtement, même passer par une fonction pour dessiner un rubik cube comme tu le fais, ce serait bôf..

                          Renseigne toi sur les listes d'affichage déjà, ensuite si vraiment tu ne les comprends pas, tu peux dessiner tout ton cube en quelques tours de boucles..
                          • Partager sur Facebook
                          • Partager sur Twitter
                            23 juillet 2007 à 12:10:17

                            Dans un premier temps, j'ai créé mon cube et lui est affecté deux rotations...
                            Je me suis appercu que le cube tournait sur deux axes...(Ca parait évident pourtant :euh: ).

                            Ensuite j'ai suivit la solution que l'on ma donner plus haut:

                            glPushMatrix()
                            Rotation

                            Dessin des faces du cube qui doivent être en rotation.
                            glPopMatrix()

                            La ma face tournait correctement.

                            Mais ensuite, j'ai voulus faire une deuxième rotation.
                            Là, j'ai vus que mes deux faces tournaient en même temps, donc j'ai fait une boucle pour attendre que la première rotation soit fini.

                            Là c'est parfait j'ai mais deux rotations, mais il y a un problème...
                            Lorsque la première rotation est fini, elle revient à zero et l'autre commence. Une fois que la deuxième fini, elle revient aussi à zero...

                            Je ne veux pas faire le gros débutant qui ne comprend rien... :-°
                            Je connet d'autre l'angage, et je sais ce que ca fait de répondre à des sujets comme celui là.
                            Et la je sèche complètement (pourtant je lit et relit le cours de Kayl).

                            Tu dis que passer par une fonction pour dessiner le rubik's cube est bof.

                            Si tu as une autre solution je suis preneur...

                            Car je n'arrive pas à établire ce qu'il faut faire pour pouvoir enchainer une suite de rotation qui n'auront pas toujours le même ordre.

                            (Je vais y passer un moi je sens bien sur ce truc qui semble évident :colere2: ).

                            Merci

                            • Partager sur Facebook
                            • Partager sur Twitter
                              23 juillet 2007 à 12:14:16

                              C'est un probleme de maths.

                              Les rotations et transformations matricielles se cumulent.
                              Si tu lances un glRotate, puis un autre, alors la résultat est la multiplication matricielle des 2 matrices de rotations.

                              Si tu veux "remettre a zero", tu une instruction pour mettre la matrice a l'identité.
                              • Partager sur Facebook
                              • Partager sur Twitter

                              Recueil de code C et C++  http://fvirtman.free.fr/recueil/index.html

                                23 juillet 2007 à 12:19:55

                                Entre les deux je met un glPopMatrix() à la fin de la première rotation il n'y a donc pas de cumulation.
                                • Partager sur Facebook
                                • Partager sur Twitter
                                  23 juillet 2007 à 12:33:07

                                  Chose qu'il ne faut pas faire si tu veux avoir 2 rotations.

                                  Pour ce qui est de faire mieux au niveau du dessin. Il y a les listes d'initialisation. Ce sera plus optimisé, mais je te conseille de faire un truc à la fois. Quand tu maîtriseras les rotations, passe au point suivant.
                                  • Partager sur Facebook
                                  • Partager sur Twitter
                                  Co-auteur du cours de C++. ||| Posez vos questions sur le forum ||| Me contacter.
                                    23 juillet 2007 à 12:50:19

                                    J'ai comprit les rotations.

                                    Pour résumé, quand je fait une rotation sur l'axe des abscisses (x), ce sont les deux autres axes qui tourne autour. (Transformation = Changement de repère) J'ai retenu :).

                                    Sinon, j'ai fait quelques que recherche à listes d'initialisations. Et je n'est pas trouver de Rubik's Cube...

                                    Si vous en avez un je suis preneur !

                                    Je vous met l'exe pour que vous vouyez ce que j'ai fait:

                                    http://maniaque.jexiste.fr/dls/Graphique.rar

                                    Si vous pouvez me dire les erreurs...
                                    • Partager sur Facebook
                                    • Partager sur Twitter

                                    Rotation Opengl

                                    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                                    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                                    • Editeur
                                    • Markdown