Bonjour,

Je commence avec le picking en OpenGL. j'ai suivis un tutoriel mais j'ai toujours hits = 0 ??

j'espère que qq pourra m'aider

voila mon code

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
 
void myDisplayFunc()
{
	// Nettoyage du "Tampon Chromatique" et du "Z buffer" 
  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();	
  gluLookAt(xPos ,yPos, zPos, xPos+cos(camAngle), yPos-0.2f, zPos+sin(camAngle), 0, 1, 0);
  glPushMatrix();
  renderScene(); 
  glPopMatrix();
  glFlush();
  glutSwapBuffers();
}//myDisplayFunc()
 
 
void renderScene() {
 
if (mode == GL_SELECT) {
		startPicking(mouse_x, mouse_y);
		 }
 
gluLookAt(xPos ,yPos, zPos, xPos+cos(camAngle), yPos-0.2f, zPos+sin(camAngle), 0, 1, 0);
 
	glLoadIdentity(); 
		Draw2();
	if (mode == GL_SELECT) 
		stopPicking();
 
 
}
void startPicking(int x, int y) {
 
	GLint viewport[4];
	float ratio;
 
	glGetIntegerv(GL_VIEWPORT,viewport);
 
	glSelectBuffer(BUFSIZE,selectBuf);
 
 
	glRenderMode(GL_SELECT);
	glInitNames();
 
// creation de la matrice de selection
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
    gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
	gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,1000.0f);
	glMatrixMode(GL_MODELVIEW);
}
void stopPicking() {
 
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
 
	hits = glRenderMode(GL_RENDER);
	if (hits != 0){
 
		processHits2(hits,selectBuf,0);
	}
 
 
	mode = GL_RENDER;
}
 
void Draw2(){
 
 
 
	glLoadName(1); 		
	glPushMatrix();	
	glTranslatef(-0.5,0,0);
	DrawObjet(1)		;
	glPopMatrix();
	glPopName();
 
 
	glLoadName(2); 	
	glPushMatrix();
	glTranslatef(0.5,0,0);
	DrawObjet(2)		;
 
	glPopName();
	glPopMatrix();
}