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_Spot.h"
23 
24 #ifndef M_PI
25 #define M_PI 3.14159265359
26 #endif
27 
SetDirection(const MOGL_Struct_Vecteur & p_Direction)28 void MOGL_Spot::SetDirection(const MOGL_Struct_Vecteur & p_Direction)
29 {
30   float norm=p_Direction.x*p_Direction.x+p_Direction.y*p_Direction.y+p_Direction.z*p_Direction.z;
31   _Direction.x=p_Direction.x/norm;
32   _Direction.y=p_Direction.y/norm;
33   _Direction.z=p_Direction.z/norm;
34 }
35 
SetCutOff(GLfloat p_CutOff)36 void MOGL_Spot::SetCutOff(GLfloat p_CutOff)
37 {
38   if (p_CutOff<0)
39     p_CutOff=0;
40   else if (p_CutOff>90)
41     p_CutOff=90;
42   _CutOff=p_CutOff;
43 }
44 
SetExposant(GLfloat p_Exposant)45 void MOGL_Spot::SetExposant(GLfloat p_Exposant)
46 {
47   if (p_Exposant<0)
48     p_Exposant=0;
49   else if (p_Exposant>128)
50     p_Exposant=128;
51   _Exposant=p_Exposant;
52 }
53 
TnL(MOGL_Afficheur * p_Afficheur)54 void MOGL_Spot::TnL(MOGL_Afficheur * p_Afficheur)
55 {
56   glPushMatrix();
57   _Matrice.MultiplierDansOpenGL();
58   _MatriceFinale.PrendreDeOpenGL();
59 
60   glLightfv(_NumLight,GL_DIFFUSE,(float*)&_Diffuse);
61   glLightfv(_NumLight,GL_SPECULAR,(float*)&_Specular);
62   glLightfv(_NumLight,GL_AMBIENT,(float*)&_Ambient);
63   glEnable(_NumLight);
64 
65   int Pos[4]={0,0,0,1};
66   glLightiv(_NumLight,GL_POSITION,Pos);
67   glLightfv(_NumLight,GL_SPOT_DIRECTION,(GLfloat*)&_Direction);
68   glLightf(_NumLight,GL_SPOT_CUTOFF,_CutOff);
69   glLightf(_NumLight,GL_SPOT_EXPONENT,_Exposant);
70 
71   MOGL_ItSet_ElementArbre it;
72   for(it=_SetElement.begin();it!=_SetElement.end();it++)
73   {
74     (*it)->TnL(p_Afficheur);
75   }
76   glPopMatrix();
77 }
78 
~MOGL_Spot()79 MOGL_Spot::~MOGL_Spot()
80 {
81 }
82