1 /*****************************************************************************
2 *
3 * Copyright (C) 2003 C�dric Br�gardis <cedric.bregardis@free.fr>
4 *
5 * This file is part of BRIQUOLO
6 *
7 * BRIQUOLO is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * BRIQUOLO is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with BRIQUOLO; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 *****************************************************************************/
22 #include "MOGL_Direct.h"
23 #include "MOGL_LensFlareSoleil.h"
24
MOGL_Direct()25 MOGL_Direct::MOGL_Direct(): MOGL_Lumiere()
26 {
27 _Direction.x=1;
28 _Direction.y=1;
29 _Direction.z=1;
30 _Direction.h=0;
31 }
32
33
TnL(MOGL_Afficheur * p_Afficheur)34 void MOGL_Direct::TnL(MOGL_Afficheur * p_Afficheur)
35 {
36 // **** R�glage de la lumi�re ****
37 glPushMatrix();
38 _Matrice.MultiplierDansOpenGL();
39 _MatriceFinale.PrendreDeOpenGL();
40
41 glLightfv(_NumLight,GL_DIFFUSE,(float*)&_Diffuse);
42 glLightfv(_NumLight,GL_SPECULAR,(float*)&_Specular);
43 glLightfv(_NumLight,GL_AMBIENT,(float*)&_Ambient);
44 glLightfv(_NumLight,GL_POSITION,(GLfloat *)&_Direction);
45 glEnable(_NumLight);
46
47 MOGL_ItSet_ElementArbre it;
48 for(it=_SetElement.begin();it!=_SetElement.end();it++)
49 {
50 (*it)->TnL(p_Afficheur);
51 }
52 glPopMatrix();
53
54 if (_ProjeterOmbre)
55 {
56 MOGL_Struct_Vecteur vec;
57 vec.x=-_Direction.x;
58 vec.y=-_Direction.y;
59 vec.z=-_Direction.z;
60 vec=_MatriceFinale.EffectuerRotationVecteur(vec);
61
62 p_Afficheur->AjouterLumiereOmbre(vec, true);
63 }
64 }
65
SetDirection(const MOGL_Struct_Vecteur & p_Direction)66 void MOGL_Direct::SetDirection(const MOGL_Struct_Vecteur & p_Direction)
67 {
68 float norm=sqrt(p_Direction.x*p_Direction.x+p_Direction.y*p_Direction.y+p_Direction.z*p_Direction.z);
69 _Direction.x=-p_Direction.x/norm;
70 _Direction.y=-p_Direction.y/norm;
71 _Direction.z=-p_Direction.z/norm;
72 _Direction.h=0;
73 }
74
GetDirection() const75 const MOGL_Struct_VecteurHomogene & MOGL_Direct::GetDirection() const
76 {
77 return _Direction;
78 }
79