IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

Problème avec gluUnproject


Sujet :

OpenGL

  1. #1
    Membre expérimenté
    Avatar de GLDavid
    Homme Profil pro
    Head of Service Delivery
    Inscrit en
    Janvier 2003
    Messages
    2 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Head of Service Delivery
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 895
    Par défaut Problème avec gluUnproject
    Bonjour

    J'éprouve quelques problèmes avec gluUnproject. Dans ma méthode de gestion à la souris, je veux retourner les coordonnées de la souris sur l'écran et dans mon "monde", d'où l'utilisation de gluUnproject:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    public void mousePressed(MouseEvent arg0) {
            this.point = arg0.getPoint();
            this.mouse_state = this.PICKED;
     
            int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            int realy = 0;// GL y coord pos
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            GLU glu = new GLU();
            int x = this.point.x, y = this.point.y;
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            /* note viewport[3] is height of window in pixels */
            realy = (int) y - 1;
     
            System.out.println("Coordinates at cursor are (" + x + ", " + realy);
     
            glu.gluUnProject((double) x, (double) realy, 0.0, //
                    mvmatrix, 0,//
                    projmatrix, 0, //
                    viewport, 0, //
                    wcoord, 0);
            System.out.println("World coords at z=0.0 are ( " //
                    + wcoord[0] + ", " + wcoord[1] + ", " + wcoord[2] + ")");
     
            this.mw.refresh();
        }
    Le code compile correctement mais lorsque j'utilise ma souris, les coordonnées sont de 0,0
    Voici mes méthodes init et reshape:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    public void init(GLAutoDrawable arg0) {
            this.gl = arg0.getGL();
            gl.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading
            gl.glClearColor(1f, 1f, 1f, 1f);
            gl.glClearDepth(1.0f);
            arg0.addMouseListener(this);
            arg0.addMouseMotionListener(this);
        }
     
    public void reshape(GLAutoDrawable arg0, int x, int y, int w, int h) {
            this.gl = arg0.getGL();
            GLU glu = new GLU();
            gl.glViewport(0, 0, w, h);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();
            glu.gluOrtho2D(-2f, 2f, -2f, 2f);
            gl.glMatrixMode(GL.GL_MODELVIEW);
            gl.glLoadIdentity();
        }
    Merci d'avance de vos lumières.

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code :tagcode: ni le tag :resolu:

    Je ne répond à aucune question technique par MP.

  2. #2
    Membre expérimenté
    Avatar de GLDavid
    Homme Profil pro
    Head of Service Delivery
    Inscrit en
    Janvier 2003
    Messages
    2 895
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Head of Service Delivery
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Janvier 2003
    Messages : 2 895
    Par défaut
    C'est bon, j'ai trouvé une solution. J'ai dpélacé ce code dans ma routine d'affichage:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    int viewport[] = new int[4];
            double mvmatrix[] = new double[16];
            double projmatrix[] = new double[16];
            int realy = 0;// GL y coord pos
            double wcoord[] = new double[4];// wx, wy, wz;// returned xyz coords
            GLU glu = new GLU();
            int x = this.point.x, y = this.point.y;
            gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix, 0);
            gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projmatrix, 0);
            /* note viewport[3] is height of window in pixels */
            realy = (int) y - 1;
     
            System.out.println("Coordinates at cursor are (" + x + ", " + realy);
     
            glu.gluUnProject((double) x, (double) realy, 0.0, //
                    mvmatrix, 0,//
                    projmatrix, 0, //
                    viewport, 0, //
                    wcoord, 0);
            System.out.println("World coords at z=0.0 are ( " //
                    + wcoord[0] + ", " + wcoord[1] + ", " + wcoord[2] + ")");
    Depuis, c'est bon !

    @++
    GLDavid
    Consultez la FAQ Perl ainsi que mes cours de Perl.
    N'oubliez pas les balises code :tagcode: ni le tag :resolu:

    Je ne répond à aucune question technique par MP.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. VC++ Direct3D8, problème avec LPD3DXFONT et LPD3DTEXTURE8
    Par Magus (Dave) dans le forum DirectX
    Réponses: 3
    Dernier message: 03/08/2002, 11h10
  2. Problème avec [b]struct[/b]
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 2
    Dernier message: 17/07/2002, 10h25
  3. Problème avec le type 'Corba::Any_out'
    Par Steven dans le forum CORBA
    Réponses: 2
    Dernier message: 14/07/2002, 18h48
  4. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo