Salut tout le monde.

Je suis en train de faire un projet en OpenGL et j'ai un petit probleme avec la fonction glulookat.

Je ne sais pas trop ou la placer !!

voici 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
 
/* Function to draw a quadrilatere */
void draw_quad( GLfloat point1[], GLfloat point2[], GLfloat point3[], GLfloat point4[] )
{
	indiceColor ++;
	glColor3fv(colors[indiceColor%2]);
	glBegin(GL_POLYGON);
		glVertex3fv(point1);
		glVertex3fv(point2);
		glVertex3fv(point3);
		glVertex3fv(point4);
	glEnd();
}
 
void display(void)
{
	glLoadIdentity();
	gluLookAt(viewer[0],viewer[1],viewer[2], 0.0,0.0,0.0, 0.0,1.0,0.0);
 
	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();
		glRotatef(theta[0], 1.0, 0.0, 0.0);
		glRotatef(theta[1], 0.0, 1.0, 0.0);
		glRotatef(theta[2], 0.0, 0.0, 1.0);
 
	draw_quad(vertices[3], vertices[2], vertices[1], vertices[0]);
	draw_quad (vertices[2], vertices[6], vertices[5], vertices[1]);
	draw_quad (vertices[6], vertices[7], vertices[4], vertices[5]);
	draw_quad (vertices[7], vertices[3], vertices[0], vertices[4]);
 
	 glFlush();
	 //I swap the buffers
	 glutSwapBuffers();
}
 
void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
	if (h == 0) h = 1;
	if (w == 0) w = 1;
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
        glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
            2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
    else
        glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
            2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(viewer[0],viewer[1],viewer[2], 0.0,0.0,0.0, 0.0,1.0,0.0);
}
 
int main(int argc, char **argv)
{
	indiceColor = -1;
	recursionLevel = 0;
	viewer[0] = 0.0;
	viewer[1] = 0.0;
        viewer[2] = 150.0;
    glutInit(&argc, argv);
 
    glutInitWindowSize(500, 500);
    window1 = glutCreateWindow("Spinning box");
 
	// need both double buffering and z buffer 
 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
 
	glutReshapeFunc(myReshape);
        glutDisplayFunc(display);
	glutMouseFunc(mouse);
	glutKeyboardFunc(keyPressed);
	glEnable(GL_DEPTH_TEST); //Enable hidden--surface--removal 
    glutMainLoop();
    return 1;
}
Pour le moment, j'ai mis le code dans la fonctio display.
Mais j'avoue qu'avec le GL_MODELVIEW et GL_PROJECTION je suis un peu perdu.

Je veux regarder toujours à l'origine, et au début je me trouve à 150 sur l'axe des z.
Cette valeur peut changer si l'utilisateur presse des touches ...

J'ai essayé plusieurs possibilités mais je n'arrive à rien, j'obtiens toujours la meme chose :/

Est-ce que quelqu'un peut m'aider svp !!

Merci beaucoup