Voila mon problème.
C'est que l'appel a la fonction callback que je donne dans SDL_AddTimer et bien faite mais le refresh de l'image non. j'ai tester la fonction en l'appellant séparérement et la ca marche. Je comprend pas trop...
[edit] J'ai aussi essayer avec les threads et puis ca change pas grand chose qu'est ce que j'ai raté !?! [/edit]
le code du global
le main
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 #include <ode/ode.h> #include <SDL/SDL.h> #include <GL/gl.h> #include <GL/glu.h> #include <stdlib.h> #include <vector> #include <math.h> //Variable pour la fenêtre int L = 640; int H = 480; /// static dWorldID world; // notre monde static dSpaceID space; // l'espace //groupe de contact temporaire pour les collisions static dJointGroupID contactgroup = dJointGroupCreate (0); /// int nombre_de_cube = 0; //fonction callback pour les collisions void nearCallback (void *data, dGeomID o1, dGeomID o2); /// //Fonction pour mettre la matrice au point d'origine du solide à déssiner void LDEsetM(const dReal *pos,const dReal *R); /// //Fonction pour dessiner les différantes structure graphique Uint32 dessine(Uint32 intervalle, void *parametre); void dessineCube (dBodyID); void dessinePlan (); ///
le code qui dessinent les petit cube + les plans.
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 int main (int argc,char *argv[]) { bool continuer = true; SDL_Event evenement;//pour la gestion des evenements //initialisation de ODE world = dWorldCreate(); space = dHashSpaceCreate(0); dWorldSetGravity (world,0,0,-9.81); dWorldSetERP(world,(dReal)0.8); dWorldSetCFM(world,(dReal)1E-5); /// //initialisation des objets ODE dMass matricePoid; dMassSetBoxTotal(&matricePoid, (dReal)10 , (dReal)2 ,(dReal)2,(dReal)2);//initialisation de la matrice dCreatePlane ( space , 0 , 0 , 1 , 0); dCreatePlane ( space , 1 , 0 , 1 , -50); dCreatePlane ( space , -1 , 0 , 1 , -50); dCreatePlane ( space , 0 , 1 , 1 , -50); dCreatePlane ( space , 0 , -1 , 1 , -50); std::vector<dBodyID> cubes;//Cube à dessiner std::vector<dGeomID> cubesGeom;//Cube à dessiner /// //initialisation de la SDL SDL_Init(SDL_INIT_VIDEO| SDL_INIT_TIMER); SDL_WM_SetCaption("OpenGL with ODE",NULL); SDL_SetVideoMode(L, H, 32, SDL_OPENGL); SDL_ShowCursor(0); // on cache le cursor /// //inistialisation de OpenGL glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); gluPerspective(70,(double)L/H,1,1000); glEnable(GL_DEPTH_TEST); /// //Gestion du temps Uint32 last_time = SDL_GetTicks(); Uint32 current_time,ellapsed_time; Uint32 start_time; /// SDL_TimerID timer; timer = SDL_AddTimer((Uint32)30, dessine, &cubes);//marche pas while (continuer) { start_time = SDL_GetTicks(); SDL_PollEvent(&evenement); if(evenement.type == SDL_KEYDOWN && evenement.key.keysym.sym == SDLK_F9) continuer = false; if(nombre_de_cube < 800 && evenement.type == SDL_MOUSEBUTTONDOWN && evenement.button.button == SDL_BUTTON_LEFT) { //ajoute un cube cubes.push_back( dBodyCreate(world));//création de l'objet dBodySetMass(cubes[nombre_de_cube] ,&matricePoid);//application de la matrice poid dBodySetPosition(cubes[nombre_de_cube],0,nombre_de_cube%6 * 2,((int)nombre_de_cube/6)*2 + 1); cubesGeom.push_back(dCreateBox (space,(dReal)2,(dReal)2,(dReal)2)); dGeomSetBody (cubesGeom[nombre_de_cube],cubes[nombre_de_cube]);//liaison de l'objet physique et de collision ++nombre_de_cube; } if(nombre_de_cube > 0 && evenement.type == SDL_MOUSEBUTTONDOWN && evenement.button.button == SDL_BUTTON_RIGHT) { //suprime le dernier cube --nombre_de_cube; dGeomDestroy(cubesGeom[nombre_de_cube]); dBodyDestroy(cubes[nombre_de_cube]); cubesGeom.pop_back(); cubes.pop_back(); } if( evenement.type == SDL_KEYDOWN && evenement.key.keysym.sym == SDLK_F1) { //Explosion int i = 0; while ( i < nombre_de_cube) { dReal d = sqrt(dBodyGetPosition(cubes[i])[0] * dBodyGetPosition(cubes[i])[0] + dBodyGetPosition(cubes[i])[1] * dBodyGetPosition(cubes[i])[1] + dBodyGetPosition(cubes[i])[2] * dBodyGetPosition(cubes[i])[2]); dReal a = 40000*(1.0-0.2*d*d); if (a<0) a=0; dBodySetForce(cubes[i], dBodyGetPosition(cubes[i])[0]*a , dBodyGetPosition(cubes[i])[1]*a , dBodyGetPosition(cubes[i])[2]*a ); ++i; } } if( evenement.type == SDL_KEYDOWN && evenement.key.keysym.sym == SDLK_F2) { //implosion int i = 0; while ( i < nombre_de_cube) { dReal x,y,z; x = dBodyGetPosition(cubes[i])[0]*-100; y = dBodyGetPosition(cubes[i])[1]*-100; z =dBodyGetPosition(cubes[i])[2]*-100; dBodySetForce(cubes[i],x,y,z ); ++i; } } //dessine (20,&cubes); // ici ca marche !!!! dSpaceCollide(space,contactgroup,&nearCallback); // teste les collisions entre les objets dWorldQuickStep(world, 0.02f);//lancement de la simulation dJointGroupEmpty (contactgroup); ellapsed_time = SDL_GetTicks() - start_time; //if (ellapsed_time < 1) // SDL_Delay(1 - ellapsed_time); } //on détruit les éléments de ODE dSpaceDestroy (space); dWorldDestroy (world); dCloseODE(); // on ferme ODE /// return EXIT_SUCCESS; }
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 Uint32 dessine(Uint32 intervalle, void *parametre) { std::vector<dBodyID> * cubes = (std::vector<dBodyID> *) parametre; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // mise à jour d'opengl glMatrixMode( GL_MODELVIEW ); glLoadIdentity( ); //caméra gluLookAt( 0,30,30,//position 0,0,0,//cible 0,0,1);//vecteur vertical dessinePlan(); int i = 0; while ( i < nombre_de_cube) dessineCube((*cubes)[i++]); glFlush(); SDL_GL_SwapBuffers(); return intervalle; } void dessineCube(dBodyID cube) { glPushMatrix(); LDEsetM(dBodyGetPosition(cube),dBodyGetRotation(cube)); glBegin(GL_QUADS); glColor3ub(255,0,0); //face rouge glVertex3d(1,1,1); glVertex3d(1,1,-1); glVertex3d(-1,1,-1); glVertex3d(-1,1,1); glColor3ub(0,255,0); //face verte glVertex3d(1,-1,1); glVertex3d(1,-1,-1); glVertex3d(1,1,-1); glVertex3d(1,1,1); glColor3ub(0,0,255); //face bleue glVertex3d(-1,-1,1); glVertex3d(-1,-1,-1); glVertex3d(1,-1,-1); glVertex3d(1,-1,1); glColor3ub(255,255,0); //face jaune glVertex3d(-1,1,1); glVertex3d(-1,1,-1); glVertex3d(-1,-1,-1); glVertex3d(-1,-1,1); glColor3ub(0,255,255); //face cyan glVertex3d(1,1,-1); glVertex3d(1,-1,-1); glVertex3d(-1,-1,-1); glVertex3d(-1,1,-1); glColor3ub(255,0,255); //face magenta glVertex3d(1,-1,1); glVertex3d(1,1,1); glVertex3d(-1,1,1); glVertex3d(-1,-1,1); glEnd(); glPopMatrix(); } void dessinePlan() { glBegin(GL_QUADS); //sol glColor3ub(255,255,255); //blanc glVertex3d(50,50,0); glVertex3d(50,-50,0); glVertex3d(-50,-50,0); glVertex3d(-50,50,0); //murs glColor3ub(200,200,200); //gris glVertex3d(-100,100,50); glVertex3d(0,0,-50); glVertex3d(0,0,-50); glVertex3d(-100,-100,50); glColor3ub(200,200,200); //gris glVertex3d(100,100,50); glVertex3d(0,100,-50); glVertex3d(0,-100,-50); glVertex3d(100,-100,50); glColor3ub(100,100,100); //gris glVertex3d(100,100,50); glVertex3d(50,50,0); glVertex3d(-50,50,0); glVertex3d(-100,100,50); glColor3ub(100,100,100); //gris glVertex3d(100,-100,50); glVertex3d(50,-50,0); glVertex3d(-50,-50,0); glVertex3d(-100,-100,50); glEnd(); }
Partager