Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

Light.cpp

Go to the documentation of this file.
00001 #include "Light.h"
00002 
00003 Light::Light(int id)
00004 {
00005         light_id = GL_LIGHT0 + id;
00006         
00007         ambient[0] = ambient[1] = ambient[2] = ambient[3] = 0;
00008         diffuse[0] = diffuse[1] = diffuse[2] = diffuse[3] = 0;
00009         specular[0] = specular[1] = specular[2] = specular[3] = 0;
00010         position[0] = position[1] = position[2] = 0;
00011         position[3] = is_positional = true;
00012         spot_dir[0] = spot_dir[1] = spot_dir[2] = 0;
00013         spot_exp = 1;
00014         spot_cutoff = 0;
00015         const_atten = 1;
00016         lin_atten = 0;
00017         quad_atten = 0;
00018         
00019         SetAll();
00020 }
00021 
00022 void Light::SetAll()
00023 {
00024     glLightfv(light_id, GL_AMBIENT, ambient);
00025     glLightfv(light_id, GL_DIFFUSE, diffuse);
00026     glLightfv(light_id, GL_SPECULAR, specular);
00027     glLightfv(light_id, GL_POSITION, position);
00028     glLightfv(light_id, GL_SPOT_DIRECTION, spot_dir);
00029 //    glLightfv(light_id, GL_SPOT_EXPONENT, const float(spot_exp));
00030 //    glLightfv(light_id, GL_SPOT_CUTOFF, const(spot_cutoff));
00031 //    glLightfv(light_id, GL_CONSTANT_ATTENUATION, const(const_atten));
00032 //    glLightfv(light_id, GL_LINEAR_ATTENUATION, const(lin_atten));
00033 //    glLightfv(light_id, GL_QUADRATIC_ATTENUATION, const(quad_atten));
00034 }
00035 
00036 void Light::SetPos(glVector new_pos)
00037 {
00038     position[0] = new_pos.data[0];
00039     position[1] = new_pos.data[1];
00040     position[2] = new_pos.data[2];
00041     position[3] = is_positional;
00042 
00043     glLightfv(light_id, GL_POSITION, position);
00044 }
00045 
00046 void Light::SetColor(Color new_color, light_type type)
00047 {
00048     switch (type)
00049     {
00050         case AMBIENT:
00051             glLightfv(light_id, GL_AMBIENT, new_color.color);
00052             break;
00053         case DIFFUSE:
00054             glLightfv(light_id, GL_DIFFUSE, new_color.color);
00055             break;
00056         case SPECULAR:
00057             glLightfv(light_id, GL_SPECULAR, new_color.color);
00058             break;
00059     }
00060 }
00061 
00062 void Light::Update()
00063 {
00064     glLightfv(light_id, GL_POSITION, position);
00065 }
00066 
00067 void Light::On()
00068 {
00069     glEnable(light_id);
00070 }

Generated on Thu Apr 21 18:06:30 2005 for Basic Rendering Engine by  doxygen 1.4.1