00001 #include "Light.h" 00002 #include "State.h" 00003 00004 using namespace Fluxus; 00005 00006 Light::Light() : 00007 m_Index(0), 00008 m_Ambient(0.2,0.2,0.2), 00009 m_Diffuse(1,1,1), 00010 m_Specular(1,1,1), 00011 m_Position(0,0,0), 00012 m_Direction(0,0,0), 00013 m_Type(POINT), 00014 m_CameraLock(false) 00015 { 00016 } 00017 00018 Light::~Light() 00019 { 00020 glDisable(GL_LIGHT0+m_Index); 00021 } 00022 00023 void Light::SetIndex(int s) 00024 { 00025 m_Index=s; 00026 glEnable(GL_LIGHT0+m_Index); 00027 } 00028 00029 void Light::SetAmbient(dColour s) 00030 { 00031 glLightfv(GL_LIGHT0+m_Index, GL_AMBIENT, s.arr()); 00032 } 00033 00034 void Light::SetDiffuse(dColour s) 00035 { 00036 glLightfv(GL_LIGHT0+m_Index, GL_DIFFUSE, s.arr()); 00037 } 00038 00039 void Light::SetSpecular(dColour s) 00040 { 00041 glLightfv(GL_LIGHT0+m_Index, GL_SPECULAR, s.arr()); 00042 } 00043 00044 void Light::SetSpotAngle(float s) 00045 { 00046 if (m_Type==SPOT) glLightf(GL_LIGHT0+m_Index, GL_SPOT_CUTOFF, s); 00047 } 00048 00049 void Light::SetSpotExponent(float s) 00050 { 00051 if (m_Type==SPOT) glLightf(GL_LIGHT0+m_Index, GL_SPOT_EXPONENT, s); 00052 } 00053 00054 void Light::SetPosition(dVector s) 00055 { 00056 m_Position=s; 00057 } 00058 00059 void Light::SetAttenuation(int type, float s) 00060 { 00061 switch (type) 00062 { 00063 case 0: glLightf(GL_LIGHT0+m_Index, GL_CONSTANT_ATTENUATION, s); break; 00064 case 1: glLightf(GL_LIGHT0+m_Index, GL_LINEAR_ATTENUATION, s); break; 00065 case 2: glLightf(GL_LIGHT0+m_Index, GL_QUADRATIC_ATTENUATION, s); break; 00066 } 00067 } 00068 00069 void Light::SetDirection(dVector s) 00070 { 00071 m_Direction=s; 00072 } 00073 00074 00075 void Light::Render() 00076 { 00077 glPushMatrix(); 00078 glTranslatef(m_Position.x,m_Position.y,m_Position.z); 00079 00080 if (m_Type==DIRECTIONAL) 00081 { 00082 float pos[4] = { m_Direction.x,m_Direction.y,m_Direction.z,0 }; 00083 glLightfv(GL_LIGHT0+m_Index, GL_POSITION, pos); 00084 } 00085 else 00086 { 00087 if (m_Type==SPOT) 00088 { 00089 float pos[4] = { m_Direction.x,m_Direction.y,m_Direction.z,1 }; 00090 glLightfv(GL_LIGHT0+m_Index, GL_SPOT_DIRECTION, pos); 00091 } 00092 00093 float pos[4] = { 0,0,0,1 }; 00094 glLightfv(GL_LIGHT0+m_Index, GL_POSITION, pos); 00095 } 00096 00097 glPopMatrix(); 00098 } 00099