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
|
GLfloat matrix[16];
Point position(0.,1.,0.25); // position de l'arbre
Vector look,right,up; // vecteurs d'orientation du billboard
look = cam.GetPosition() - position;
look.Normalize();
right.CrossProduct(cam.GetUp(),look); // right = camUp ^ look
right.Normalize();
up.CrossProduct(look,right); // up = look ^ right
up.Normalize();
matrix[0] = right.GetX(); // remplissage de la matrice de rotation/translation
matrix[1] = right.GetY();
matrix[2] = right.GetZ();
matrix[3] = 0;
matrix[4] = up.GetX();
matrix[5] = up.GetY();
matrix[6] = up.GetZ();
matrix[7] = 0;
matrix[8] = look.GetX();
matrix[9] = look.GetY();
matrix[10] = look.GetZ();
matrix[11] = 0;
matrix[12] = position.GetX();
matrix[13] = position.GetY();
matrix[14] = position.GetZ();
matrix[15] = 1;
glMatrixMode(GL_MODELVIEW); // utile ?
glPushMatrix(); // il y a d'autres arbres => sauvegarde de la matrice courante
glMultMatrixf(matrix); // problème ???
glDisable(GL_CULL_FACE); // affichage de l'arbre
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glColor4f(1.,1.,1.,1.);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_arbre.GetId());
glBegin(GL_QUADS);
glTexCoord2f(0.,0.);glVertex3f(-0.15,0,0.);
glTexCoord2f(0.,1.);glVertex3f(-0.15,0,0.3);
glTexCoord2f(1.,1.);glVertex3f(0.15,0,0.3);
glTexCoord2f(1.,0.);glVertex3f(0.15,0,0.);
glEnd();
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glPopMatrix(); |
Partager