Partage
  • Partager sur Facebook
  • Partager sur Twitter

Gros problème d'orientation

    7 juillet 2006 à 21:21:22

    Coucou ;)

    Dans ce code :

    #include <SDL/SDL.h>
    #include <SDL/SDL_image.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include "sdlglutils.h"

    void dessiner(double angle, int x, int y);
    GLuint texture;

    int main(int argv, char *argc[])
    {
     SDL_Init(SDL_INIT_VIDEO);
     
     SDL_Surface *screen=NULL;
     int x=0;
     int y=0;
     
     screen=SDL_SetVideoMode(640,480,32,SDL_OPENGL);
     
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     gluPerspective(70,(double)640/480,1,1000);
     glEnable(GL_DEPTH_TEST);
     glEnable(GL_TEXTURE_2D);
     texture=loadTexture("oiseau.jpg");
     
     bool continuer=1;
     SDL_Event event;
     double angle=0;
     
     while(continuer)
     {
      SDL_PollEvent(&event);
      switch(event.type)
      {
       case SDL_QUIT:
        continuer=0;
        break;
      }
      dessiner(angle, x, y);
     
      angle++;
     
      glFlush();
      SDL_GL_SwapBuffers();
     }
     
     SDL_Quit();
     return EXIT_SUCCESS;
    }

    void dessiner(double angle, int x, int y)
    {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      gluLookAt(3,4,2,x,y,0,0,0,1);
     
      glRotated(angle,1,0,1);
     
      glBindTexture(GL_TEXTURE_2D, texture);
     
     glBegin(GL_QUADS);
       glTexCoord2d(0,1);  glVertex3d(1,1,1);
       glTexCoord2d(0,0);  glVertex3d(1,1,-1);
       glTexCoord2d(1,0);  glVertex3d(-1,1,-1);
       glTexCoord2d(1,1);  glVertex3d(-1,1,1);
     glEnd();
       
     glBegin(GL_QUADS)
       glColor3ub(0,255,0);
       
       glTexCoord2d(0,1);  glVertex3d(1,-1,1);
       glTexCoord2d(0,0);  glVertex3d(1,-1,-1);
       glTexCoord2d(1,0);  glVertex3d(1,1,-1);
       glTexCoord2d(1,1);  glVertex3d(1,1,1);
     glEnd();
     
     glBegin(GL_QUADS);   
       glColor3ub(0,0,255);
       
       glTexCoord2d(0,1);  glVertex3d(1,-1,1);
       glTexCoord2d(0,0);  glVertex3d(-1,-1,1);
       glTexCoord2d(1,0);  glVertex3d(-1,-1,-1);
       glTexCoord2d(1,1);  glVertex3d(1,-1,-1);
     glEnd();
     
     glBegin(GL_QUADS)
       glColor3ub(255,0,0);
       
       glTexCoord2d(0,1);  glVertex3d(-1,1,1);
       glTexCoord2d(0,0);  glVertex3d(-1,-1,1);
       glTexCoord2d(1,0);  glVertex3d(-1,-1,-1);
       glTexCoord2d(1,1);  glVertex3d(-1,1,-1);
     glEnd();
     
     glBegin(GL_QUADS)
       glColor3ub(100,100,0);
       
       glTexCoord2d(0,1);  glVertex3d(1,-1,1);
       glTexCoord2d(0,0);  glVertex3d(1,1,1);
       glTexCoord2d(1,0);  glVertex3d(-1,1,1);
       glTexCoord2d(1,1);  glVertex3d(-1,-1,1);
     glEnd();
     
     glBegin(GL_QUADS)
       glColor3ub(0,100,100);
       
       glTexCoord2d(0,1);glVertex3d(1,-1,-1);
       glTexCoord2d(0,0);glVertex3d(-1,-1,-1);
       glTexCoord2d(1,0);glVertex3d(-1,1,-1);
       glTexCoord2d(1,1);glVertex3d(1,1,-1);
     glEnd();
    }


    Où est le repère en trois dimensions ? J'arrive pas à me repérer :'( Il est au centre de la fenêtre ? Si oui, comment est-il orienté ? Merci :)
    • Partager sur Facebook
    • Partager sur Twitter
      7 juillet 2006 à 21:24:20

      Le cours d'OpenGL disponible sur ce site donne la fonction suivante dans un fichier nommé sdlglutils.cpp :


      void drawAxis(double scale)
      {
          glPushAttrib(GL_ALL_ATTRIB_BITS);
          glPushMatrix();
          glDisable(GL_LIGHTING);
          glDisable(GL_TEXTURE_2D);
          glEnable(GL_BLEND);
          glEnable(GL_LINE_SMOOTH);
          glLineWidth(2);
          glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
          glScaled(scale,scale,scale);
          glBegin(GL_LINES);
          glColor3ub(255,0,0);
          glVertex3i(0,0,0);
          glVertex3i(1,0,0);
          glColor3ub(0,255,0);
          glVertex3i(0,0,0);
          glVertex3i(0,1,0);
          glColor3ub(0,0,255);
          glVertex3i(0,0,0);
          glVertex3i(0,0,1);
          glEnd();
          glPopMatrix();
          glPopAttrib();
      }


      Appelée au bon moment, elle te permettra de voir l'orientation et la position de ton repère actuel.

      Je laisse les autres zéros t'aider plus sur ton problème en particulier (je n'ai pas regardé désolé) car je n'ai pas le temps pour ça.
      • Partager sur Facebook
      • Partager sur Twitter
      Anonyme
        7 juillet 2006 à 22:58:08

        J'ai regardé vite fait, tu ne fait aucune translation donc il devrait être au centre du cube.
        • Partager sur Facebook
        • Partager sur Twitter

        Gros problème d'orientation

        × 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