Bonjour,
Je suis en train d'implanter le picking dans un petit programme 3d que je développe a mes heures perdus ....

Bref je suis confronter a un petit problème le picking marche mais que pour certain de mes objets mais si je déplace la camera il arrive que sa marche sur les objets qui ne marchaient pas auparavant....
Je poste le code il n'est pas très commenter désoler (sauf les partis que j'ai trouver sur des tuto .. :-° ).
Si quelqu'un pouvait m'aider je lui serais très reconnaissant !!

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 
int gl_select(int x, int y,freecamera *camera,newtworld* world)
 {
     std::vector<CPhysique*> *objets = world->get_array_body();
 	GLuint buff[512] = {0};
 	GLint hits, view[4];
 	int id;
   int ptr=0;
 
 
 
 
 	/*
 		This retrieves info about the viewport
 	*/
 	glGetIntegerv(GL_VIEWPORT, view);
 
    /*
 		This choose the buffer where store the values for the selection data
 	*/
 	glSelectBuffer(512, buff);
 
 	/*
 		Switching in selecton mode
 	*/
 	glRenderMode(GL_SELECT);
 
 	/*
 		Clearing the names' stack
 		This stack contains all the info about the objects
 	*/
 	glInitNames();
 
 	/*
 		Now fill the stack with one element (or glLoadName will generate an error)
 	*/
 	glPushName(0);
 
 	/*
 		Now modify the viewing volume, restricting selection area around the cursor
 	*/
 	glMatrixMode(GL_PROJECTION);
 	glPushMatrix();
 		glLoadIdentity();
 
 		/*
 			restrict the draw to an area around the cursor
 		*/
 		gluPickMatrix(x, y, 1, 1, view);
 		gluPerspective(70, (float)view[2]/(float)view[3], 1, 10000);
 
 
 
 
 		/*
 			Draw the objects onto the screen
 		*/
 		glMatrixMode(GL_MODELVIEW);
 
        /*
 			draw only the names in the stack, and fill the array
 		*/
 
 		///Fonction de draw pour le picking
 
            glLoadIdentity ();
 
    camera->look();
 
    int j = objets->size()-1;
 
    if(j<0)
    {
        j=0;
    }
 
   for (unsigned int i = 0 ; i < j; i++)
   {
       if((*objets)[i]->m_visible)
       {
           glLoadName(((*objets)[i]->getnameid())); /*objets est un tableau qui contient tout les objet de la scène*/
         (*objets)[i]->Render_pickink();
       }
   }
 
         ///fin de la fonction
 
 		/*
 			Do you remeber? We do pushMatrix in PROJECTION mode
 		*/
 		glMatrixMode(GL_PROJECTION);
 	glPopMatrix();
 
 	/*
 		get number of objects drawed in that area
 		and return to render mode
 	*/
 	hits = glRenderMode(GL_RENDER);
 
 	ptr=buff[3];
 
 
 	int select;
 
 
 
    if(hits>0)
    {
        select = 0;
 
        for(unsigned int j=0;j<objets->size()-1;j++)
        {
 
         if(((*objets)[j]->getnameid()) == ptr)
         {
             select = j;
             j = objets->size();
 
         }
 
        }
    }
    else
    {
        select = 0;
    }
 
 
 	glMatrixMode(GL_MODELVIEW);
    glPopName();                                                       //On supprime le nom de la pile
    glFlush();
 
  return select;
 }