Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

light.cpp

Go to the documentation of this file.
00001 /* ***********************************************************************************
00002         Writer:         Sebastien Bloc
00003         Copyright:      2003-2004
00004         eMail:          sebastien.bloc@free.fr
00005         URL:            http://mignonsoft.free.fr
00006 
00007         This program is free software; you can redistribute it and/or
00008         modify it under the terms of the GNU General Public License
00009         as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016         http://www.gnu.org/copyleft/gpl.html    
00017 *********************************************************************************** */
00018 
00019 #include "light.h"
00020 
00021 BOOL Light::useLighting;
00022 
00023 void Light::SetLighting(BOOL set)
00024 {
00025         useLighting = set;
00026         if (set) glEnable(GL_LIGHTING);
00027         else glDisable(GL_LIGHTING);
00028 }
00029 
00030 BOOL Light::IsLighting() 
00031 { 
00032         return useLighting; 
00033 }
00034 
00035 Light::Light()
00036 {
00037         Zero();
00038         id = 0;
00039 }
00040 
00041 Light::Light(int _id)
00042 {
00043         Zero();
00044         id = _id;
00045 }
00046 
00047 void Light::Zero()
00048 {
00049         id = GL_LIGHT0;
00050         isEnable = TRUE;
00051         material.Zero();
00052         direction.Zero();
00053         position.Zero();
00054         cutoff.isEnable=FALSE;
00055         exponent.isEnable=FALSE;
00056         attenuationCst.isEnable=FALSE;
00057         attenuationLin.isEnable=FALSE;
00058         attenuationQuad.isEnable=FALSE;
00059 }
00060 
00061 void Light::operator=(Light &source)
00062 {
00063         isEnable = source.isEnable;
00064         material = source.material;
00065 
00066         direction = source.direction;
00067         position = source.position;
00068 
00069         cutoff = source.cutoff;
00070         exponent = source.exponent;
00071 
00072         attenuationCst = source.attenuationCst;
00073         attenuationLin = source.attenuationLin;
00074         attenuationQuad = source.attenuationQuad;
00075 }
00076 
00077 void Light::Enable(BOOL active) // -1 affiche ou pas suivant le mode precedent , 0 desactive et 1 active
00078 {
00079         if (active!=-1) isEnable = active;
00080         if (isEnable) glEnable (id);
00081         else glDisable (id);
00082 }
00083 
00084 BOOL Light::IsEnabled() 
00085 { 
00086         return isEnable; 
00087 } 
00088 
00089 void Light::Toggle () 
00090 { 
00091         Enable(!IsEnabled()); 
00092 }
00093 
00094 void Light::Use()
00095 {
00096         Enable();
00097         if (!isEnable) return;
00098         if (material.ambient.isEnable)  glLightfv(id,GL_AMBIENT,material.ambient);
00099         if (material.diffuse.isEnable)  glLightfv(id,GL_DIFFUSE,material.diffuse);
00100         if (material.specular.isEnable) glLightfv(id,GL_SPECULAR,material.specular);
00101         if (cutoff.isEnable)                    glLightf(id,GL_SPOT_CUTOFF,cutoff.elem);
00102         if (exponent.isEnable)                  glLightf(id,GL_SPOT_EXPONENT,exponent.elem);
00103         if (attenuationCst.isEnable)    glLightf(id,GL_CONSTANT_ATTENUATION,attenuationCst.elem);
00104         if (attenuationLin.isEnable)    glLightf(id,GL_CONSTANT_ATTENUATION,attenuationLin.elem);
00105         if (attenuationQuad.isEnable)   glLightf(id,GL_CONSTANT_ATTENUATION,attenuationQuad.elem);
00106         if (direction.isEnable)                 glLightfv(id,GL_SPOT_DIRECTION,direction);
00107         if (position.isEnable)                  glLightfv(id,GL_POSITION,position);
00108 }

Generated on Fri Aug 20 19:19:46 2004 for 3d Controls by doxygen 1.3.6