bonjour à tous,

j'ai (encore) un petit soucis avec mon picking. Je découvre SDL, et j'utilise la freeFlyCamera. J'avais déjà réussi a faire fonctionner le picking auparavant, mais la... aucune idée de ce qui cloche.

Tout part de la!
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
int main( int narg, char **argv)
{ 	
	width = LARGEUR_FENETRE;
	height = HAUTEUR_FENETRE;
 
	// Init SDL video subsystem
	if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) 
	{
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		exit(1);
	}
 
    // Set GL context attributes
    initAttributes ();
 
    // Create GL context
    createSurface (0);
 
    // Init GL state
    initGL ();
 
    // Draw, get events...
    mainLoop ();
 
    // Cleanup
	SDL_Quit();
 
 
	return 0;
}
les principales fonctions
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
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void initGL ()
{
    initTerrain(); 
    redim (gScreen->w, gScreen->h);
 
	glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    gluPerspective(60,(double)width/height,0.001,200000);
 
	camera = new FreeFlyCamera(Vector3D(0,0,2));
}
//``````````````````````````````````````````````````
 
 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static void mainLoop ()
{
    SDL_Event event;
    int done = 0;
    const Uint32 time_per_frame = 1000/FPS;
    Uint32 last_time,current_time,elapsed_time; //for time animation
    Uint32 start_time,stop_time; //for frame limit
 
	last_time = SDL_GetTicks();
 
    while ( !done ) 
	{
		start_time = SDL_GetTicks();
 
		/* Check for events */
		while ( SDL_PollEvent (&event) ) 
		{
			switch (event.type)
			{
				case SDL_QUIT:	done = 1;	break;
				case SDL_MOUSEMOTION:	if (!modeSelect) camera->OnMouseMotion(event.motion);	
                                                          else   camera->OnMouseMotion2(event.motion);	break;
				case SDL_MOUSEBUTTONUP:
				case SDL_MOUSEBUTTONDOWN: if (!modeSelect)	camera->OnMouseButton(event.button);	
                                                          else  camera->OnMouseButton2(event.button);	break;
				case SDL_KEYUP:	 camera->OnKeyboard(event.key); break;
				case SDL_KEYDOWN:	
						switch (event.key.keysym.sym)
						{
							case SDLK_p:		takeScreenshot("test.bmp");		break;
							case SDLK_m:		modeSelect = !modeSelect;	
									if (!modeSelect)	SDL_ShowCursor(SDL_DISABLE);
									else				SDL_ShowCursor(SDL_ENABLE);
												break;
							case SDLK_ESCAPE:	exit(0);						break;
							default :			camera->OnKeyboard(event.key);
						}
						break;
				default:	break;
			}
		}
 
	current_time = SDL_GetTicks();
        elapsed_time = current_time - last_time;
        last_time = current_time;
 
	camera->animate(elapsed_time);
 
	// Affichage de la scène
        affichage ();
 
	stop_time = SDL_GetTicks();
        if ((stop_time - last_time) < time_per_frame)
        {
            SDL_Delay(time_per_frame - (stop_time - last_time));
        }
	}
}
//``````````````````````````````````````````````````
 
 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void affichage (void)
{
	static double th[4] = {0.0, 0.0, 0.0, 0.0};
	static double t1 = 0.0, t2 = 0.0, t;
	char num_str[128];
	t1 = t2;
 
	glClearColor(0,0,0,0);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	// mise en place du Z-BUFFER
    glEnable (GL_DEPTH_TEST);
 
	glPushMatrix();
	glMatrixMode (GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, width, 0, height, -10.0, 10.0);
		glRasterPos2f(5.0, 5.0);
		t2 = mtime();
		t = t2 - t1;
		if(t > 0.0001) t = 1.0 / t;
		glColor3f( 0.0, 0.0, 1.0 );
		sprintf(num_str, "%0.2f FPS ", filter(t, th));
		DrawStr(num_str);
	glPopMatrix();
 
	glPushMatrix();
	camera->look();
	dessineTerrain();	
	if (modeSelect)	dessinePoint();
	glPopMatrix();
 
	glFlush();
    SDL_GL_SwapBuffers();
 
}
//``````````````````````````````````````````````````
 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void redim (int x , int y)
{
	if (y == 0 || x == 0) return;
	//Set a new projection matrix
	glMatrixMode(GL_PROJECTION);  
	glLoadIdentity();
	gluPerspective(60,(double)width/height,0.001,200000);
 
	glMatrixMode(GL_MODELVIEW);
	glViewport(0,0,x,y);  //Use the whole window for rendering
}
//``````````````````````````````````````````````````
et les fonctions de 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
30
31
32
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void select (int x, int y)
{
    GLuint selectBuf[1024];
    GLint hits=0;
    GLint viewport[4];
 
    glGetIntegerv (GL_VIEWPORT, viewport);
    glSelectBuffer (1024, selectBuf);
    (void) glRenderMode (GL_SELECT);
 
    glInitNames();
    glPushName(0);
 
    glMatrixMode (GL_PROJECTION);
	glPushMatrix ();                 // push projection 
	glLoadIdentity ();
	gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport);
	gluPerspective(60,(double)width/height,0.001,200000);
 
	picking = true;
	dessineTerrain();
	picking = false;
 
    glPopMatrix ();        // pop projection 
    glFlush();
 
    hits = glRenderMode (GL_RENDER);
    processHits (hits, selectBuf);
    glutPostRedisplay();
}
//``````````````````````````````````````````````````