Bonjour,
Je ne sait pas où se positionne mes lampes. J'aimerais qu'on m'explique.
J'ai un terrain plat et carré de 100 x 100 le long des axes X et Y (le ciel vers l'axe Z). Je veux positionner 4 lampes à chacune des extrémités de ce terrain carré et dessiner un arbre au milieu (X=50;Y=50).
Pour que ça fonctionne selon mes attentes, je fais comme ceci :
Code C : 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 float specular[] = {0.25, 0.25, 0.25, 1.0}; float diffuse[] = {0.25, 0.25, 0.25, 1.0}; float ambiante[] = {0.05, 0.05, 0.05, 1.0}; float position[] = { 0.0, 0.0, 0.0, 0.0f }; float positionZero[3] = {0.0,0.0,0.0}; position[0] = 0.0; position[1] = 0.0; position[2] = 0.0; glPushMatrix(); glTranslatef(position[0], position[1], position[2]); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT0, GL_POSITION, positionZero); glPopMatrix(); position[0] = 100.0; position[1] = 0.0; position[2] = 0.0; glPushMatrix(); glTranslatef(position[0], position[1], position[2]); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_SPECULAR, specular); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT1, GL_POSITION, positionZero); glPopMatrix(); position[0] = 100.0; position[1] = 100.0; position[2] = 0.0; glPushMatrix(); glTranslatef(position[0], position[1], position[2]); glEnable(GL_LIGHT2); glLightfv(GL_LIGHT2, GL_SPECULAR, specular); glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT2, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT2, GL_POSITION, positionZero); glPopMatrix(); position[0] = 0.0; position[1] = 100.0; position[2] = 0.0; glPushMatrix(); glTranslatef(position[0], position[1], position[2]); glEnable(GL_LIGHT3); glLightfv(GL_LIGHT3, GL_SPECULAR, specular); glLightfv(GL_LIGHT3, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT3, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT3, GL_POSITION, positionZero); glPopMatrix(); glPushMatrix(); glTranslatef(50.0, 50.0, 0.0); glRotatef(90, 1, 0, 0); glEnable(GL_LIGHTING); this->arbre->afficher(); glDisable(GL_LIGHTING); glPopMatrix();
En faisant comme ça, mon arbre est éclairé comme il faut, un peu de chaque côtés.
Mais avant de faire comme ceci, je faisais autrement, pensant que ça fonctionnerait. Voici le code :
Code C : 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 float specular[] = {0.25, 0.25, 0.25, 1.0}; float diffuse[] = {0.25, 0.25, 0.25, 1.0}; float ambiante[] = {0.05, 0.05, 0.05, 1.0}; float position[] = { 0.0, 0.0, 0.0, 0.0f }; position[0] = 0.0; position[1] = 0.0; position[2] = 0.0; glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT0, GL_POSITION, position); position[0] = 100.0; position[1] = 0.0; position[2] = 0.0; glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_SPECULAR, specular); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT1, GL_POSITION, position); position[0] = 100.0; position[1] = 100.0; position[2] = 0.0; glEnable(GL_LIGHT2); glLightfv(GL_LIGHT2, GL_SPECULAR, specular); glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT2, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT2, GL_POSITION, position); position[0] = 0.0; position[1] = 100.0; position[2] = 0.0; glEnable(GL_LIGHT3); glLightfv(GL_LIGHT3, GL_SPECULAR, specular); glLightfv(GL_LIGHT3, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT3, GL_AMBIENT, ambiante); glLightfv(GL_LIGHT3, GL_POSITION, position); glPushMatrix(); glTranslatef(50.0, 50.0, 0.0); glRotatef(90, 1, 0, 0); glEnable(GL_LIGHTING); this->arbre->afficher(); glDisable(GL_LIGHTING); glPopMatrix();
Avec ce code, l'arbre n'est éclairé que d'un côté. Pourtant, j'ai l'impression que dans les deux cas je positionne les sources de lumière aux mêmes endroits.
Pouvez-vous m'expliquer ce qui m'échappe ?
Merci.
Partager