IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

Lumière et transformation


Sujet :

OpenGL

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    74
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 74
    Points : 80
    Points
    80
    Par défaut Lumière et transformation
    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.

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    Le quatrième paramètre de la position des lampes est important et de mémoire, il faut le mettre à 1.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

Discussions similaires

  1. Transformations sur une lumière
    Par betsprite dans le forum OpenGL
    Réponses: 1
    Dernier message: 12/02/2011, 17h00
  2. position lumière et transformation
    Par gooze dans le forum OpenGL
    Réponses: 3
    Dernier message: 10/06/2008, 04h27
  3. transformer un jour en JJ/MM/AA
    Par gemini_010 dans le forum Algorithmes et structures de données
    Réponses: 8
    Dernier message: 08/11/2002, 22h55
  4. Transformer un caractère en type énuméré
    Par HT dans le forum Langage
    Réponses: 3
    Dernier message: 22/10/2002, 20h46
  5. FFT(Fast Fourier Transform)
    Par IngBen dans le forum Traitement du signal
    Réponses: 6
    Dernier message: 23/05/2002, 16h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo