Bonjour,

J'ai un problème sur l'utilisation du picking d'OpenGL :

Voici les fonctions essentielles de mon objet gérant OpenGL pour le picking :

Fonction appelée lorsque la souris bouge sur la scène :

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
31
32
33
34
35
36
37
38
 
void VolumeViewer::picking(int x, int y)
{
       GLuint selectBuf[BUFSIZE];
       GLint hits;
       GLint viewport[4];
 
       glGetIntegerv(GL_VIEWPORT, viewport);
 
       glSelectBuffer(BUFSIZE, selectBuf);
       (void) glRenderMode(GL_SELECT);
 
       glInitNames();
 
       glMatrixMode(GL_PROJECTION);
       glPushMatrix();
       glLoadIdentity();
 
       /*  create 5x5 pixel picking region near cursor location */
       gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y),
                     5.0, 5.0, viewport);
 
       glTranslatef(_xTrans, _yTrans, -10.0f);
       glRotatef(_xRot / 16.0, 1.0, 0.0, 0.0);
       glRotatef(_yRot / 16.0, 0.0, 1.0, 0.0);
       glRotatef(_zRot / 16.0, 0.0, 0.0, 1.0);
       glScaled(_scale, _scale, _scale);
 
       drawSkeleton(GL_SELECT);
 
       glPopMatrix();
       glMatrixMode(GL_MODELVIEW);
       glFlush();
 
       hits = glRenderMode(GL_RENDER);
       if (hits != 0)
              processHits(hits, selectBuf);
}
Méthode appelée par le picking :
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
 
void VolumeViewer::processHits(GLint hits, GLuint buffer[])
{
       unsigned int i, j;
       GLuint names, *ptr;
 
       cout << "hits = " << hits << endl;
       ptr = (GLuint *) buffer;
       /* for each hit  */
       for (i = 0 ; i < hits ; i++)
       {
              names = *ptr;
              cout << " number of names for hit = "<< names << endl;
              ptr++;
              cout << "  z1 is " << (float)( *ptr/0x7fffffff) << endl;
              ptr++;
              cout << "  z2 is " << (float)( *ptr/0x7fffffff) << endl;
              ptr++;
              cout << "   the name is ";
              /* for each name */
              for (j = 0; j < names; j++)
              {
                     cout << *ptr << " ";
                     ptr++;
              }
              cout << endl;
       }
       cout << "end process hits" << endl;
}
Méthode appelée dans la fonction qui dessine la scène (GL_RENDER) et pour le picking (GL_SELECT) :

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
void VolumeViewer::drawSkeleton(GLenum mode)
{
       if (_skeleton != NULL)
       {
              int branchesSize = _skeleton->size();
 
              // SELECT mode : FOR picking
              if (mode == GL_SELECT)
              {
                     // branches
                     for (int i=0 ; i < branchesSize ; i++)
                     {
                            glPushName(i);
                            drawLines(_skeleton->get(i)); // dessine une suite de GL_LINE
                            glPopName();
                     }
              }
              // RENDER mode : NO picking
              else
              {
                     // first node
                     Segment_t s = _skeleton->get(0).get(0);
                     glColor3ub(s.color.Red(), s.color.Green(), s.color.Blue());
                     drawSphere(s.src);
 
                     // others nodes
                     for (int i=0 ; i < branchesSize ; i++)
                     {
                            for (int j=0 ; j < _skeleton->get(i).size() ; j++)
                            {
                                   s = _skeleton->get(i).get(j);
                                   glColor3ub(s.color.Red(), s.color.Green(), s.color.Blue());
                                   drawSphere(s.trg); // dessine une sphère avec glutDrawSphere
                            }
                     }
 
                     // branches
                     for (int i=0 ; i < branchesSize ; i++)
                     {
                            drawLines(_skeleton->get(i));
                     }
              }
       }
}
Mon problème est simple : je n'arrive pas a récupéré les "names" du "skeleton" que je créé. Quelqu'un verrait il un problème?

Merci