J'aie ssayé d'intégrer une camera à mon application utilisant GLUT, mais j'ai toujours ce problème avec la fonction gluLookAt(). Le problème c'est que la fonction ne fonctionne tout simplement pas. Peut importe les valeurs que j'envoi, la vue reste toujours la même. Pourtant, j'ai bien cherché dans plein d'exemples qui fonctionnent, et je trouve toujours pas ce qui cloche!
Le main:
La fonction qui gère l'affichage:
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 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1024, 768); //Envoyer les données physiques aux trois cubes test test.setPhysic(globalPhysic); test2.setPhysic(globalPhysic); test3.setPhysic(globalPhysic); //Envoyer les données physique au terrain plat terrainTest.setPhysic(globalPhysic); //camera: camera.SetCamera(0.0f, 0.2f, -2.0f, 0.0f, 0.2f, 0.0f, 0.0f, 1.0f, 0.0f); glutCreateWindow("Test"); initRendering(); glutDisplayFunc(drawScene); glutKeyboardFunc(handleKeypress); glutReshapeFunc(handleResize); glutPassiveMotionFunc(mousePassive); glutTimerFunc(25, update, 0); glutMainLoop(); return 0; }
//La fonction d'initialisation:
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 void drawScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Les deux fonctions donnent une même vue //même avec des valeurs différentes gluLookAt(camera.xPos, camera.yPos, camera.zPos, camera.xView, camera.yView, camera.zView, camera.xUp, camera.yUp, camera.zUp); /*gluLookAt(0, 0.0, 0.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0);*/ glTranslatef(0.0f, 0.0f, -20.0f); GLfloat ambientLight[] = {0.3f, 0.3f, 0.3f, 1.0f}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); GLfloat lightColor[] = {0.7f, 0.7f, 0.7f, 1.0f}; GLfloat lightPos[] = {-2 * 10, 10, 4 * 10, 1.0f}; glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLoadIdentity(); test.show();//Afficher l'objet test2.show(); test3.show(); terrainTest.render(); glutSwapBuffers(); glutWarpPointer( glutGet( GLUT_WINDOW_WIDTH )/2, glutGet( GLUT_WINDOW_HEIGHT )/2 ); }
La fonction qui gère la redimension de la fenêtre:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 void initRendering() { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); }
Merci d'avance pour tout aide :-)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 void handleResize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (float)w / (float)h, 1.0, 500.0); glMatrixMode(GL_MODELVIEW); }
Partager