Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

ExCLight.cpp

Aller à la documentation de ce fichier.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExCLight.cpp,v 1.8 2002/08/14 15:40:05 data Exp $
00021  *
00022  */
00023 
00024 #include "ExCLight.h"
00025 
00026 ExCLight::ExCLight()
00027 {
00028 Guard(ExCLight::ExCLight())
00029         Reset();
00030         m_LightNumber=0;
00031         SetName("ExCLight");
00032         SetType(typeid(this).name());
00033 UnGuard
00034 }
00035 
00036 ExCLight::ExCLight(GLenum Number)
00037 {
00038 Guard(ExCLight::ExCLight(GLenum Number))
00039         Reset();
00040         m_LightNumber=Number;
00041 UnGuard
00042 }
00043 
00044 ExCLight::~ExCLight(void)
00045 {
00046 Guard(ExCLight::~ExCLight(void))
00047 UnGuard
00048 }
00049 
00050 void ExCLight::Reset(void)
00051 {
00052 Guard(ExCLight::Reset(void))
00053         TurnOn();
00054         glEnable(GL_LIGHT0);    
00055         m_Angle.SetValue(0,0,0);
00056         m_State=false;
00057         SetAmbiant(0.0f,0.0f,0.0f,1.0f);
00058         SetDiffuse(1.0f,1.0f,1.0f,1.0f);
00059         SetSpecular(1.0f,1.0f,1.0f,1.0f);
00060         m_Position.SetValue(10,10,0);
00061         m_Target.SetValue(0,0,0);
00062         SetSpotExponent(0.0f);
00063         SetSpotCutOff(180.0f);
00064         SetConstantAttenuation(1.0f);
00065         SetLinearAttenuation(0.0f);
00066         SetQuadraticAttenuation(0.0f);
00067         
00068 UnGuard
00069 }
00070 
00071 void ExCLight::SetLightNumber(GLenum light)
00072 {
00073 Guard(void ExCLight::SetLightNumber(GLenum light))
00074         m_LightNumber=light;    
00075 UnGuard
00076 }
00077 
00078 void ExCLight::TurnOn(void)
00079 {
00080 Guard(void ExCLight::TurnOn(void))
00081         m_State=true;
00082         glEnable(m_LightNumber);
00083 UnGuard
00084 }
00085 
00086 void ExCLight::TurnOff(void)
00087 {
00088 Guard(void ExCLight::TurnOff(void))
00089         m_State=false;
00090         glDisable(m_LightNumber);
00091 UnGuard
00092 }
00093 
00094 void ExCLight::SetAmbiant(float R,float G,float B,float A)
00095 {
00096 Guard(void ExCLight::SetAmbiant(float R,float G,float B,float A))
00097         SetAmbiantR(R);
00098         SetAmbiantG(G);
00099         SetAmbiantB(B);
00100         SetAmbiantA(A);
00101 UnGuard
00102 }
00103 
00104 void ExCLight::SetAmbiantR(float R)
00105 {
00106 Guard(void ExCLight::SetAmbiantR(float R))
00107         if(R>1)R=1.0f;if(R<0.0f)R=0.0f;
00108         m_ambiant[0]=R;
00109         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
00110 UnGuard
00111 }
00112 
00113 void ExCLight::SetAmbiantG(float G)
00114 {
00115 Guard(void ExCLight::SetAmbiantG(float G))
00116         if(G>1)G=1.0f;if(G<0.0f)G=0.0f; 
00117         m_ambiant[1]=G;
00118         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
00119 UnGuard
00120 }
00121 
00122 void ExCLight::SetAmbiantB(float B)
00123 {
00124 Guard(void ExCLight::SetAmbiantB(float B))
00125         if(B>1)B=1.0f;if(B<0.0f)B=0.0f;
00126         m_ambiant[2]=B;
00127         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
00128 UnGuard
00129 }
00130 
00131 void ExCLight::SetAmbiantA(float A)
00132 {
00133 Guard(void ExCLight::SetAmbiantA(float A))
00134         if(A>1)A=1.0f;if(A<0.0f)A=0.0f;
00135         m_ambiant[3]=A;
00136         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
00137 UnGuard
00138 }
00139 
00140 float ExCLight::GetAmbiantR(void)
00141 {
00142 Guard(float ExCLight::GetAmbiantR(void))
00143         return m_ambiant[0];
00144 UnGuard
00145 }
00146 
00147 float ExCLight::GetAmbiantG(void)
00148 {
00149 Guard(float ExCLight::GetAmbiantG(void))
00150         return m_ambiant[1];
00151 UnGuard
00152 }
00153 
00154 float ExCLight::GetAmbiantB(void)
00155 {
00156 Guard(float ExCLight::GetAmbiantB(void))
00157         return m_ambiant[2];
00158 UnGuard
00159 }
00160 
00161 float ExCLight::GetAmbiantA(void)
00162 {
00163 Guard(float ExCLight::GetAmbiantA(void))
00164         return m_ambiant[3];
00165 UnGuard
00166 }
00167 
00168 void ExCLight::IncAmbiantR(float inc)
00169 {
00170 Guard(void ExCLight::IncAmbiantR(float inc))
00171         SetAmbiantR(GetAmbiantR()+inc);
00172 UnGuard
00173 }
00174 
00175 void ExCLight::IncAmbiantG(float inc)
00176 {
00177 Guard(void ExCLight::IncAmbiantG(float inc))
00178         SetAmbiantG(GetAmbiantG()+inc);
00179 UnGuard
00180 }
00181 
00182 void ExCLight::IncAmbiantB(float inc)
00183 {
00184 Guard(void ExCLight::IncAmbiantB(float inc))
00185         SetAmbiantB(GetAmbiantB()+inc);
00186 UnGuard
00187 }
00188 
00189 void ExCLight::IncAmbiantA(float inc)
00190 {
00191 Guard(void ExCLight::IncAmbiantA(float inc))
00192         SetAmbiantA(GetAmbiantA()+inc);
00193 UnGuard
00194 }
00195 
00196 void ExCLight::SetDiffuse(float R,float G,float B,float A)
00197 {
00198 Guard(void ExCLight::SetDiffuse(float R,float G,float B,float A))
00199         SetDiffuseR(R);
00200         SetDiffuseG(G);
00201         SetDiffuseB(B);
00202         SetDiffuseA(A);
00203 UnGuard
00204 }
00205 
00206 void ExCLight::SetDiffuseR(float R)
00207 {
00208 Guard(void ExCLight::SetDiffuseR(float R))
00209         if(R>1)R=1.0f;if(R<0.0f)R=0.0f;
00210         m_diffuse[0]=R;
00211         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
00212 UnGuard
00213 }
00214 
00215 void ExCLight::SetDiffuseG(float G)
00216 {
00217 Guard(void ExCLight::SetDiffuseG(float G))
00218         if(G>1)G=1.0f;if(G<0.0f)G=0.0f; 
00219         m_diffuse[1]=G;
00220         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
00221 UnGuard
00222 }
00223 
00224 void ExCLight::SetDiffuseB(float B)
00225 {
00226 Guard(void ExCLight::SetDiffuseB(float B))
00227         if(B>1)B=1.0f;if(B<0.0f)B=0.0f;
00228         m_diffuse[2]=B;
00229         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
00230 UnGuard
00231 }
00232 
00233 void ExCLight::SetDiffuseA(float A)
00234 {
00235 Guard(void ExCLight::SetDiffuseA(float A))
00236         if(A>1)A=1.0f;if(A<0.0f)A=0.0f;
00237         m_diffuse[3]=A;
00238         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
00239 UnGuard
00240 }
00241 
00242 float ExCLight::GetDiffuseR(void)
00243 {
00244 Guard(float ExCLight::GetDiffuseR(void))
00245         return m_diffuse[0];
00246 UnGuard
00247 }
00248 
00249 float ExCLight::GetDiffuseG(void)
00250 {
00251 Guard(float ExCLight::GetDiffuseG(void))
00252         return m_diffuse[1];
00253 UnGuard
00254 }
00255 
00256 float ExCLight::GetDiffuseB(void)
00257 {
00258 Guard(float ExCLight::GetDiffuseB(void))
00259         return m_diffuse[2];
00260 UnGuard
00261 }
00262 
00263 float ExCLight::GetDiffuseA(void)
00264 {
00265 Guard(float ExCLight::GetDiffuseA(void))
00266         return m_diffuse[3];
00267 UnGuard
00268 }
00269 
00270 void ExCLight::IncDiffuseR(float inc)
00271 {
00272 Guard(void ExCLight::IncDiffuseR(float inc))
00273         SetDiffuseR(GetDiffuseR()+inc);
00274 UnGuard
00275 }
00276 
00277 void ExCLight::IncDiffuseG(float inc)
00278 {
00279 Guard(void ExCLight::IncDiffuseG(float inc))
00280         SetDiffuseG(GetDiffuseG()+inc);
00281 UnGuard
00282 }
00283 
00284 void ExCLight::IncDiffuseB(float inc)
00285 {
00286 Guard(void ExCLight::IncDiffuseB(float inc))
00287         SetDiffuseB(GetDiffuseB()+inc);
00288 UnGuard
00289 }
00290 
00291 void ExCLight::IncDiffuseA(float inc)
00292 {
00293 Guard(void ExCLight::IncDiffuseA(float inc))
00294         SetDiffuseA(GetDiffuseA()+inc);
00295 UnGuard
00296 }
00297 
00298 void ExCLight::SetSpecular(float R,float G,float B,float A)
00299 {
00300 Guard(void ExCLight::SetSpecular(float R,float G,float B,float A))
00301         SetSpecularR(R);
00302         SetSpecularG(G);
00303         SetSpecularB(B);
00304         SetSpecularA(A);
00305 UnGuard
00306 }
00307 
00308 void ExCLight::SetSpecularR(float R)
00309 {
00310 Guard(void ExCLight::SetSpecularR(float R))
00311         if(R>1)R=1.0f;if(R<0.0f)R=0.0f;
00312         m_specular[0]=R;
00313         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
00314 UnGuard
00315 }
00316 
00317 void ExCLight::SetSpecularG(float G)
00318 {
00319 Guard(void ExCLight::SetSpecularG(float G))
00320         if(G>1)G=1.0f;if(G<0.0f)G=0.0f; 
00321         m_specular[1]=G;
00322         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
00323 UnGuard
00324 }
00325 
00326 void ExCLight::SetSpecularB(float B)
00327 {
00328 Guard(void ExCLight::SetSpecularB(float B))
00329         if(B>1)B=1.0f;if(B<0.0f)B=0.0f;
00330         m_specular[2]=B;
00331         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
00332 UnGuard
00333 }
00334 
00335 void ExCLight::SetSpecularA(float A)
00336 {
00337 Guard(void ExCLight::SetSpecularA(float A))
00338         if(A>1)A=1.0f;if(A<0.0f)A=0.0f;
00339         m_specular[3]=A;
00340         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
00341 UnGuard
00342 }
00343 
00344 float ExCLight::GetSpecularR(void)
00345 {
00346 Guard(float ExCLight::GetSpecularR(void))
00347         return m_specular[0];
00348 UnGuard
00349 }
00350 
00351 float ExCLight::GetSpecularG(void)
00352 {
00353 Guard(float ExCLight::GetSpecularG(void))
00354         return m_specular[1];
00355 UnGuard
00356 }
00357 
00358 float ExCLight::GetSpecularB(void)
00359 {
00360 Guard(float ExCLight::GetSpecularB(void))
00361         return m_specular[2];
00362 UnGuard
00363 }
00364 
00365 float ExCLight::GetSpecularA(void)
00366 {
00367 Guard(float ExCLight::GetSpecularA(void))
00368         return m_specular[3];
00369 UnGuard
00370 }
00371 
00372 void ExCLight::IncSpecularR(float inc)
00373 {
00374 Guard(void ExCLight::IncSpecularR(float inc))
00375         SetSpecularR(GetSpecularR()+inc);
00376 UnGuard
00377 }
00378 
00379 void ExCLight::IncSpecularG(float inc)
00380 {
00381 Guard(void ExCLight::IncSpecularG(float inc))
00382         SetSpecularG(GetSpecularG()+inc);
00383 UnGuard
00384 }
00385 
00386 void ExCLight::IncSpecularB(float inc)
00387 {
00388 Guard(void ExCLight::IncSpecularB(float inc))
00389         SetSpecularB(GetSpecularB()+inc);
00390 UnGuard
00391 }
00392 
00393 void ExCLight::IncSpecularA(float inc)
00394 {
00395 Guard(void ExCLight::IncSpecularA(float inc))
00396         SetSpecularA(GetSpecularA()+inc);
00397 UnGuard
00398 }
00399 
00400 
00401 void ExCLight::SetPosition(double X,double Y,double Z)
00402 {
00403 Guard(void ExCLight::SetPosition(double X,double Y,double Z))
00404         SetPosition(X,Y,Z);
00405         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
00406         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00407 UnGuard
00408 }
00409 
00410 void ExCLight::SetPositionX(double X)
00411 {
00412 Guard(void ExCLight::SetPositionX(double X))
00413         m_Position.SetX(X);
00414         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
00415         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00416 UnGuard
00417 }
00418 
00419 void ExCLight::SetPositionY(double Y)
00420 {
00421 Guard(void ExCLight::SetPositionY(double Y))
00422         m_Position.SetY(Y);
00423         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
00424         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00425 UnGuard
00426 }
00427 
00428 void ExCLight::SetPositionZ(double Z)
00429 {
00430 Guard(void ExCLight::SetPositionZ(double Z))
00431         m_Position.SetZ(Z);
00432         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
00433         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00434 UnGuard
00435 }
00436 
00437 
00438 void ExCLight::SetTargetX(double X)
00439 {
00440 Guard(void ExCLight::SetTargetX(double X))
00441         m_Target.SetX(X);
00442         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
00443         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00444 UnGuard
00445 }
00446 
00447 void ExCLight::SetTargetY(double Y)
00448 {
00449 Guard(void ExCLight::SetTargetY(double Y))
00450         m_Target.SetY(Y);
00451         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
00452         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00453 UnGuard
00454 }
00455 
00456 void ExCLight::SetTargetZ(double Z)
00457 {
00458 Guard(void ExCLight::SetTargetZ(double Z))
00459         m_Target.SetZ(Z);
00460         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
00461         glLightfv(m_LightNumber, GL_POSITION, lightPos );
00462 UnGuard
00463 }
00464 
00465 
00466 
00467 
00468 void ExCLight::SetTarget(double X,double Y,double Z)
00469 {
00470 Guard(void ExCLight::SetTarget(double X,double Y,double Z))
00471         //SetTarget(X,Y,Z);
00472         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
00473         glLightfv(m_LightNumber,GL_SPOT_DIRECTION,lightPos);
00474 UnGuard
00475 }
00476 
00477 void ExCLight::SetSpotExponent(float Exponent)
00478 {
00479 Guard(void ExCLight::SetSpotExponent(float Exponent))
00480         if(Exponent<0)Exponent=0.0f;if(Exponent>128)Exponent=128.0f;
00481         m_spotExponent[0]=Exponent;
00482         glLightfv(m_LightNumber,GL_SPOT_EXPONENT,m_spotExponent);
00483 UnGuard
00484 }
00485 
00486 void ExCLight::IncSpotExponent(float inc)
00487 {
00488 Guard(void ExCLight::IncSpotExponent(float inc))
00489         SetSpotExponent(GetSpotExponent()+inc);
00490 UnGuard
00491 }
00492 
00493 float ExCLight::GetSpotExponent(void)
00494 {
00495 Guard(float ExCLight::GetSpotExponent(void))
00496         return m_spotExponent[0];
00497 UnGuard
00498 }
00499 
00500 void ExCLight::SetSpotCutOff(float cut)
00501 {
00502 Guard(void ExCLight::SetSpotCutOff(float cut))
00503         if(cut>m_spotCutOff[0])
00504         {
00505                 if(cut>90)cut=180;
00506         }else
00507         {
00508                 if(cut<0)cut=0;
00509                 if(cut>90)cut=90;
00510                 
00511         }
00512 
00513         m_spotCutOff[0]=cut;
00514         glLightfv(m_LightNumber,GL_SPOT_CUTOFF,m_spotCutOff);
00515 UnGuard
00516 }
00517 
00518 void ExCLight::IncSpotCutOff(float inc)
00519 {
00520 Guard(void ExCLight::IncSpotCutOff(float inc))
00521         SetSpotCutOff(GetSpotCutOff()+inc);
00522 UnGuard
00523 }
00524 
00525 float ExCLight::GetSpotCutOff(void)
00526 {
00527 Guard(float ExCLight::GetSpotCutOff(void))
00528         return m_spotCutOff[0];
00529 UnGuard
00530 }
00531 
00532 void ExCLight::SetConstantAttenuation(float att)
00533 {
00534 Guard(void ExCLight::SetConstantAttenuation(float att))
00535         if(att<0)att=0.0f;if(att>5)att=5.0f;
00536         m_spotConstentAtt[0]=att;
00537         glLightfv(m_LightNumber,GL_CONSTANT_ATTENUATION,m_spotConstentAtt);
00538 UnGuard
00539 }
00540 
00541 void ExCLight::IncConstantAttenuation(float inc)
00542 {
00543 Guard(void ExCLight::IncConstantAttenuation(float inc))
00544         SetConstantAttenuation(GetConstantAttenuation()+inc);
00545 UnGuard
00546 }
00547 
00548 float ExCLight::GetConstantAttenuation(void)
00549 {
00550 Guard(float ExCLight::GetConstantAttenuation(void))
00551         return m_spotConstentAtt[0];
00552 UnGuard
00553 }
00554 
00555 void ExCLight::SetLinearAttenuation(float att)
00556 {
00557 Guard(void ExCLight::SetLinearAttenuation(float att))
00558         if(att<0)att=0.0f;if(att>5)att=5.0f;
00559         m_spotLinearAtt[0]=att;
00560         glLightfv(m_LightNumber,GL_LINEAR_ATTENUATION,m_spotLinearAtt);
00561 UnGuard
00562 }
00563 
00564 void ExCLight::IncLinearAttenuation(float inc)
00565 {
00566 Guard(void ExCLight::IncLinearAttenuation(float inc))
00567         SetLinearAttenuation(GetLinearAttenuation()+inc);
00568 UnGuard
00569 }
00570 
00571 float ExCLight::GetLinearAttenuation(void)
00572 {
00573 Guard(float ExCLight::GetLinearAttenuation(void))
00574         return m_spotLinearAtt[0];
00575 UnGuard
00576 }
00577 
00578 void ExCLight::SetQuadraticAttenuation(float att)
00579 {
00580 Guard(void ExCLight::SetQuadraticAttenuation(float att))
00581         if(att<0)att=0.0f;if(att>5)att=5.0f;
00582         m_spotQuadraticAtt[1]=att;
00583         glLightfv(m_LightNumber,GL_QUADRATIC_ATTENUATION,m_spotQuadraticAtt);
00584 UnGuard
00585 }
00586 
00587 void ExCLight::IncQuadraticAttenuation(float inc)
00588 {
00589 Guard(void ExCLight::IncQuadraticAttenuation(float inc))
00590         SetQuadraticAttenuation(GetQuadraticAttenuation()+inc);
00591 UnGuard
00592 }
00593 
00594 float ExCLight::GetQuadraticAttenuation(void)
00595 {
00596 Guard(float ExCLight::GetQuadraticAttenuation(void))
00597         return m_spotQuadraticAtt[1];
00598 UnGuard
00599 }
00600 
00601 void ExCLight::Draw(void)
00602 {
00603 Guard(void ExCLight::Draw(void))
00604         glPushMatrix();
00605         glDisable(GL_LIGHTING);
00606                 glColor3f(1,1,1);
00607                 glTranslatef(m_Position.GetX(),m_Position.GetY(),m_Position.GetZ());
00608                 glutWireSphere(0.5,10,10);
00609         glPopMatrix();
00610 UnGuard
00611 }
00612 

Généré le Tue Oct 28 12:43:31 2003 pour ExNihilo par doxygen 1.3.4