Main Page Namespace List Class Hierarchy Alphabetical List Data Structures File List Namespace Members Data Fields Globals

# ExCLight.cpp

Go to the documentation of this file.

    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         m_AngleX=0;
    00054         m_AngleY=0;
    00055         m_AngleZ=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.SetX(0.0f);
    00061         m_Position.SetY(0.0f);
    00062         m_Position.SetZ(0.0f);
    00063         m_Target.SetX(0.0f);
    00064         m_Target.SetY(0.0f);
    00065         m_Target.SetZ(-1.0f);
    00066         SetSpotExponent(0.0f);
    00067         SetSpotCutOff(180.0f);
    00068         SetConstantAttenuation(1.0f);
    00069         SetLinearAttenuation(0.0f);
    00070         SetQuadraticAttenuation(0.0f);
    00071 UnGuard
    00072 }
    00073
    00074 void ExCLight::SetLightNumber(GLenum light)
    00075 {
    00076 Guard(void ExCLight::SetLightNumber(GLenum light))
    00077         m_LightNumber=light;
    00078 UnGuard
    00079 }
    00080
    00081 void ExCLight::TurnOn(void)
    00082 {
    00083 Guard(void ExCLight::TurnOn(void))
    00084         m_State=true;
    00085         glEnable(m_LightNumber);
    00086 UnGuard
    00087 }
    00088
    00089 void ExCLight::TurnOff(void)
    00090 {
    00091 Guard(void ExCLight::TurnOff(void))
    00092         m_State=false;
    00093         glDisable(m_LightNumber);
    00094 UnGuard
    00095 }
    00096
    00097 void ExCLight::SetAmbiant(float R,float G,float B,float A)
    00098 {
    00099 Guard(void ExCLight::SetAmbiant(float R,float G,float B,float A))
    00100         SetAmbiantR(R);
    00101         SetAmbiantG(G);
    00102         SetAmbiantB(B);
    00103         SetAmbiantA(A);
    00104 UnGuard
    00105 }
    00106
    00107 void ExCLight::SetAmbiantR(float R)
    00108 {
    00109 Guard(void ExCLight::SetAmbiantR(float R))
    00110         if(R>1)R=1.0f;if(R<0.0f)R=0.0f;
    00111         m_ambiant[0]=R;
    00112         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
    00113 UnGuard
    00114 }
    00115
    00116 void ExCLight::SetAmbiantG(float G)
    00117 {
    00118 Guard(void ExCLight::SetAmbiantG(float G))
    00119         if(G>1)G=1.0f;if(G<0.0f)G=0.0f;
    00120         m_ambiant[1]=G;
    00121         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
    00122 UnGuard
    00123 }
    00124
    00125 void ExCLight::SetAmbiantB(float B)
    00126 {
    00127 Guard(void ExCLight::SetAmbiantB(float B))
    00128         if(B>1)B=1.0f;if(B<0.0f)B=0.0f;
    00129         m_ambiant[2]=B;
    00130         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
    00131 UnGuard
    00132 }
    00133
    00134 void ExCLight::SetAmbiantA(float A)
    00135 {
    00136 Guard(void ExCLight::SetAmbiantA(float A))
    00137         if(A>1)A=1.0f;if(A<0.0f)A=0.0f;
    00138         m_ambiant[3]=A;
    00139         glLightfv(m_LightNumber,GL_AMBIENT,m_ambiant);
    00140 UnGuard
    00141 }
    00142
    00143 float ExCLight::GetAmbiantR(void)
    00144 {
    00145 Guard(float ExCLight::GetAmbiantR(void))
    00146         return m_ambiant[0];
    00147 UnGuard
    00148 }
    00149
    00150 float ExCLight::GetAmbiantG(void)
    00151 {
    00152 Guard(float ExCLight::GetAmbiantG(void))
    00153         return m_ambiant[1];
    00154 UnGuard
    00155 }
    00156
    00157 float ExCLight::GetAmbiantB(void)
    00158 {
    00159 Guard(float ExCLight::GetAmbiantB(void))
    00160         return m_ambiant[2];
    00161 UnGuard
    00162 }
    00163
    00164 float ExCLight::GetAmbiantA(void)
    00165 {
    00166 Guard(float ExCLight::GetAmbiantA(void))
    00167         return m_ambiant[3];
    00168 UnGuard
    00169 }
    00170
    00171 void ExCLight::IncAmbiantR(float inc)
    00172 {
    00173 Guard(void ExCLight::IncAmbiantR(float inc))
    00174         SetAmbiantR(GetAmbiantR()+inc);
    00175 UnGuard
    00176 }
    00177
    00178 void ExCLight::IncAmbiantG(float inc)
    00179 {
    00180 Guard(void ExCLight::IncAmbiantG(float inc))
    00181         SetAmbiantG(GetAmbiantG()+inc);
    00182 UnGuard
    00183 }
    00184
    00185 void ExCLight::IncAmbiantB(float inc)
    00186 {
    00187 Guard(void ExCLight::IncAmbiantB(float inc))
    00188         SetAmbiantB(GetAmbiantB()+inc);
    00189 UnGuard
    00190 }
    00191
    00192 void ExCLight::IncAmbiantA(float inc)
    00193 {
    00194 Guard(void ExCLight::IncAmbiantA(float inc))
    00195         SetAmbiantA(GetAmbiantA()+inc);
    00196 UnGuard
    00197 }
    00198
    00199 void ExCLight::SetDiffuse(float R,float G,float B,float A)
    00200 {
    00201 Guard(void ExCLight::SetDiffuse(float R,float G,float B,float A))
    00202         SetDiffuseR(R);
    00203         SetDiffuseG(G);
    00204         SetDiffuseB(B);
    00205         SetDiffuseA(A);
    00206 UnGuard
    00207 }
    00208
    00209 void ExCLight::SetDiffuseR(float R)
    00210 {
    00211 Guard(void ExCLight::SetDiffuseR(float R))
    00212         if(R>1)R=1.0f;if(R<0.0f)R=0.0f;
    00213         m_diffuse[0]=R;
    00214         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
    00215 UnGuard
    00216 }
    00217
    00218 void ExCLight::SetDiffuseG(float G)
    00219 {
    00220 Guard(void ExCLight::SetDiffuseG(float G))
    00221         if(G>1)G=1.0f;if(G<0.0f)G=0.0f;
    00222         m_diffuse[1]=G;
    00223         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
    00224 UnGuard
    00225 }
    00226
    00227 void ExCLight::SetDiffuseB(float B)
    00228 {
    00229 Guard(void ExCLight::SetDiffuseB(float B))
    00230         if(B>1)B=1.0f;if(B<0.0f)B=0.0f;
    00231         m_diffuse[2]=B;
    00232         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
    00233 UnGuard
    00234 }
    00235
    00236 void ExCLight::SetDiffuseA(float A)
    00237 {
    00238 Guard(void ExCLight::SetDiffuseA(float A))
    00239         if(A>1)A=1.0f;if(A<0.0f)A=0.0f;
    00240         m_diffuse[3]=A;
    00241         glLightfv(m_LightNumber,GL_DIFFUSE,m_diffuse);
    00242 UnGuard
    00243 }
    00244
    00245 float ExCLight::GetDiffuseR(void)
    00246 {
    00247 Guard(float ExCLight::GetDiffuseR(void))
    00248         return m_diffuse[0];
    00249 UnGuard
    00250 }
    00251
    00252 float ExCLight::GetDiffuseG(void)
    00253 {
    00254 Guard(float ExCLight::GetDiffuseG(void))
    00255         return m_diffuse[1];
    00256 UnGuard
    00257 }
    00258
    00259 float ExCLight::GetDiffuseB(void)
    00260 {
    00261 Guard(float ExCLight::GetDiffuseB(void))
    00262         return m_diffuse[2];
    00263 UnGuard
    00264 }
    00265
    00266 float ExCLight::GetDiffuseA(void)
    00267 {
    00268 Guard(float ExCLight::GetDiffuseA(void))
    00269         return m_diffuse[3];
    00270 UnGuard
    00271 }
    00272
    00273 void ExCLight::IncDiffuseR(float inc)
    00274 {
    00275 Guard(void ExCLight::IncDiffuseR(float inc))
    00276         SetDiffuseR(GetDiffuseR()+inc);
    00277 UnGuard
    00278 }
    00279
    00280 void ExCLight::IncDiffuseG(float inc)
    00281 {
    00282 Guard(void ExCLight::IncDiffuseG(float inc))
    00283         SetDiffuseG(GetDiffuseG()+inc);
    00284 UnGuard
    00285 }
    00286
    00287 void ExCLight::IncDiffuseB(float inc)
    00288 {
    00289 Guard(void ExCLight::IncDiffuseB(float inc))
    00290         SetDiffuseB(GetDiffuseB()+inc);
    00291 UnGuard
    00292 }
    00293
    00294 void ExCLight::IncDiffuseA(float inc)
    00295 {
    00296 Guard(void ExCLight::IncDiffuseA(float inc))
    00297         SetDiffuseA(GetDiffuseA()+inc);
    00298 UnGuard
    00299 }
    00300
    00301 void ExCLight::SetSpecular(float R,float G,float B,float A)
    00302 {
    00303 Guard(void ExCLight::SetSpecular(float R,float G,float B,float A))
    00304         SetSpecularR(R);
    00305         SetSpecularG(G);
    00306         SetSpecularB(B);
    00307         SetSpecularA(A);
    00308 UnGuard
    00309 }
    00310
    00311 void ExCLight::SetSpecularR(float R)
    00312 {
    00313 Guard(void ExCLight::SetSpecularR(float R))
    00314         if(R>1)R=1.0f;if(R<0.0f)R=0.0f;
    00315         m_specular[0]=R;
    00316         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
    00317 UnGuard
    00318 }
    00319
    00320 void ExCLight::SetSpecularG(float G)
    00321 {
    00322 Guard(void ExCLight::SetSpecularG(float G))
    00323         if(G>1)G=1.0f;if(G<0.0f)G=0.0f;
    00324         m_specular[1]=G;
    00325         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
    00326 UnGuard
    00327 }
    00328
    00329 void ExCLight::SetSpecularB(float B)
    00330 {
    00331 Guard(void ExCLight::SetSpecularB(float B))
    00332         if(B>1)B=1.0f;if(B<0.0f)B=0.0f;
    00333         m_specular[2]=B;
    00334         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
    00335 UnGuard
    00336 }
    00337
    00338 void ExCLight::SetSpecularA(float A)
    00339 {
    00340 Guard(void ExCLight::SetSpecularA(float A))
    00341         if(A>1)A=1.0f;if(A<0.0f)A=0.0f;
    00342         m_specular[3]=A;
    00343         glLightfv(m_LightNumber,GL_SPECULAR,m_specular);
    00344 UnGuard
    00345 }
    00346
    00347 float ExCLight::GetSpecularR(void)
    00348 {
    00349 Guard(float ExCLight::GetSpecularR(void))
    00350         return m_specular[0];
    00351 UnGuard
    00352 }
    00353
    00354 float ExCLight::GetSpecularG(void)
    00355 {
    00356 Guard(float ExCLight::GetSpecularG(void))
    00357         return m_specular[1];
    00358 UnGuard
    00359 }
    00360
    00361 float ExCLight::GetSpecularB(void)
    00362 {
    00363 Guard(float ExCLight::GetSpecularB(void))
    00364         return m_specular[2];
    00365 UnGuard
    00366 }
    00367
    00368 float ExCLight::GetSpecularA(void)
    00369 {
    00370 Guard(float ExCLight::GetSpecularA(void))
    00371         return m_specular[3];
    00372 UnGuard
    00373 }
    00374
    00375 void ExCLight::IncSpecularR(float inc)
    00376 {
    00377 Guard(void ExCLight::IncSpecularR(float inc))
    00378         SetSpecularR(GetSpecularR()+inc);
    00379 UnGuard
    00380 }
    00381
    00382 void ExCLight::IncSpecularG(float inc)
    00383 {
    00384 Guard(void ExCLight::IncSpecularG(float inc))
    00385         SetSpecularG(GetSpecularG()+inc);
    00386 UnGuard
    00387 }
    00388
    00389 void ExCLight::IncSpecularB(float inc)
    00390 {
    00391 Guard(void ExCLight::IncSpecularB(float inc))
    00392         SetSpecularB(GetSpecularB()+inc);
    00393 UnGuard
    00394 }
    00395
    00396 void ExCLight::IncSpecularA(float inc)
    00397 {
    00398 Guard(void ExCLight::IncSpecularA(float inc))
    00399         SetSpecularA(GetSpecularA()+inc);
    00400 UnGuard
    00401 }
    00402
    00403
    00404 void ExCLight::SetPosition(double X,double Y,double Z)
    00405 {
    00406 Guard(void ExCLight::SetPosition(double X,double Y,double Z))
    00407         SetPosition(X,Y,Z);
    00408         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
    00409         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00410 UnGuard
    00411 }
    00412
    00413 void ExCLight::SetPositionX(double X)
    00414 {
    00415 Guard(void ExCLight::SetPositionX(double X))
    00416         m_Position.SetX(X);
    00417         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
    00418         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00419 UnGuard
    00420 }
    00421
    00422 void ExCLight::SetPositionY(double Y)
    00423 {
    00424 Guard(void ExCLight::SetPositionY(double Y))
    00425         m_Position.SetY(Y);
    00426         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
    00427         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00428 UnGuard
    00429 }
    00430
    00431 void ExCLight::SetPositionZ(double Z)
    00432 {
    00433 Guard(void ExCLight::SetPositionZ(double Z))
    00434         m_Position.SetZ(Z);
    00435         GLfloat lightPos[] = { m_Position.GetX(), m_Position.GetY(),m_Position.GetZ()};
    00436         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00437 UnGuard
    00438 }
    00439
    00440
    00441 void ExCLight::SetTargetX(double X)
    00442 {
    00443 Guard(void ExCLight::SetTargetX(double X))
    00444         m_Target.SetX(X);
    00445         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
    00446         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00447 UnGuard
    00448 }
    00449
    00450 void ExCLight::SetTargetY(double Y)
    00451 {
    00452 Guard(void ExCLight::SetTargetY(double Y))
    00453         m_Target.SetY(Y);
    00454         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
    00455         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00456 UnGuard
    00457 }
    00458
    00459 void ExCLight::SetTargetZ(double Z)
    00460 {
    00461 Guard(void ExCLight::SetTargetZ(double Z))
    00462         m_Target.SetZ(Z);
    00463         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
    00464         glLightfv(m_LightNumber, GL_POSITION, lightPos );
    00465 UnGuard
    00466 }
    00467
    00468
    00469
    00470
    00471 void ExCLight::SetTarget(double X,double Y,double Z)
    00472 {
    00473 Guard(void ExCLight::SetTarget(double X,double Y,double Z))
    00474         //SetTarget(X,Y,Z);
    00475         GLfloat lightPos[] = { m_Target.GetX(), m_Target.GetY(),m_Target.GetZ(), 1.0 };
    00476         glLightfv(m_LightNumber,GL_SPOT_DIRECTION,lightPos);
    00477 UnGuard
    00478 }
    00479
    00480 void ExCLight::SetSpotExponent(float Exponent)
    00481 {
    00482 Guard(void ExCLight::SetSpotExponent(float Exponent))
    00483         if(Exponent<0)Exponent=0.0f;if(Exponent>128)Exponent=128.0f;
    00484         m_spotExponent[0]=Exponent;
    00485         glLightfv(m_LightNumber,GL_SPOT_EXPONENT,m_spotExponent);
    00486 UnGuard
    00487 }
    00488
    00489 void ExCLight::IncSpotExponent(float inc)
    00490 {
    00491 Guard(void ExCLight::IncSpotExponent(float inc))
    00492         SetSpotExponent(GetSpotExponent()+inc);
    00493 UnGuard
    00494 }
    00495
    00496 float ExCLight::GetSpotExponent(void)
    00497 {
    00498 Guard(float ExCLight::GetSpotExponent(void))
    00499         return m_spotExponent[0];
    00500 UnGuard
    00501 }
    00502
    00503 void ExCLight::SetSpotCutOff(float cut)
    00504 {
    00505 Guard(void ExCLight::SetSpotCutOff(float cut))
    00506         if(cut>m_spotCutOff[0])
    00507         {
    00508                 if(cut>90)cut=180;
    00509         }else
    00510         {
    00511                 if(cut<0)cut=0;
    00512                 if(cut>90)cut=90;
    00513
    00514         }
    00515
    00516         m_spotCutOff[0]=cut;
    00517         glLightfv(m_LightNumber,GL_SPOT_CUTOFF,m_spotCutOff);
    00518 UnGuard
    00519 }
    00520
    00521 void ExCLight::IncSpotCutOff(float inc)
    00522 {
    00523 Guard(void ExCLight::IncSpotCutOff(float inc))
    00524         SetSpotCutOff(GetSpotCutOff()+inc);
    00525 UnGuard
    00526 }
    00527
    00528 float ExCLight::GetSpotCutOff(void)
    00529 {
    00530 Guard(float ExCLight::GetSpotCutOff(void))
    00531         return m_spotCutOff[0];
    00532 UnGuard
    00533 }
    00534
    00535 void ExCLight::SetConstantAttenuation(float att)
    00536 {
    00537 Guard(void ExCLight::SetConstantAttenuation(float att))
    00538         if(att<0)att=0.0f;if(att>5)att=5.0f;
    00539         m_spotConstentAtt[0]=att;
    00540         glLightfv(m_LightNumber,GL_CONSTANT_ATTENUATION,m_spotConstentAtt);
    00541 UnGuard
    00542 }
    00543
    00544 void ExCLight::IncConstantAttenuation(float inc)
    00545 {
    00546 Guard(void ExCLight::IncConstantAttenuation(float inc))
    00547         SetConstantAttenuation(GetConstantAttenuation()+inc);
    00548 UnGuard
    00549 }
    00550
    00551 float ExCLight::GetConstantAttenuation(void)
    00552 {
    00553 Guard(float ExCLight::GetConstantAttenuation(void))
    00554         return m_spotConstentAtt[0];
    00555 UnGuard
    00556 }
    00557
    00558 void ExCLight::SetLinearAttenuation(float att)
    00559 {
    00560 Guard(void ExCLight::SetLinearAttenuation(float att))
    00561         if(att<0)att=0.0f;if(att>5)att=5.0f;
    00562         m_spotLinearAtt[0]=att;
    00563         glLightfv(m_LightNumber,GL_LINEAR_ATTENUATION,m_spotLinearAtt);
    00564 UnGuard
    00565 }
    00566
    00567 void ExCLight::IncLinearAttenuation(float inc)
    00568 {
    00569 Guard(void ExCLight::IncLinearAttenuation(float inc))
    00570         SetLinearAttenuation(GetLinearAttenuation()+inc);
    00571 UnGuard
    00572 }
    00573
    00574 float ExCLight::GetLinearAttenuation(void)
    00575 {
    00576 Guard(float ExCLight::GetLinearAttenuation(void))
    00577         return m_spotLinearAtt[0];
    00578 UnGuard
    00579 }
    00580
    00581 void ExCLight::SetQuadraticAttenuation(float att)
    00582 {
    00583 Guard(void ExCLight::SetQuadraticAttenuation(float att))
    00584         if(att<0)att=0.0f;if(att>5)att=5.0f;
    00585         m_spotQuadraticAtt[1]=att;
    00586         glLightfv(m_LightNumber,GL_QUADRATIC_ATTENUATION,m_spotQuadraticAtt);
    00587 UnGuard
    00588 }
    00589
    00590 void ExCLight::IncQuadraticAttenuation(float inc)
    00591 {
    00592 Guard(void ExCLight::IncQuadraticAttenuation(float inc))
    00593         SetQuadraticAttenuation(GetQuadraticAttenuation()+inc);
    00594 UnGuard
    00595 }
    00596
    00597 float ExCLight::GetQuadraticAttenuation(void)
    00598 {
    00599 Guard(float ExCLight::GetQuadraticAttenuation(void))
    00600         return m_spotQuadraticAtt[1];
    00601 UnGuard
    00602 }
    00603