00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "K3dLight.h"
00035 #include <SDL/SDL_opengl.h>
00036
00037 K3dLight::K3dLight()
00038 {
00039 Reset();
00040 }
00041
00042 K3dLight::~K3dLight()
00043 {
00044 Destroy();
00045 }
00046
00047 void K3dLight::InitLight()
00048 {
00049 cout << "void K3dLight::InitLight()" << endl;
00050 m_afAmbient[0] = 0.1f;
00051 m_afAmbient[1] = 0.1f;
00052 m_afAmbient[2] = 0.1f;
00053 m_afAmbient[3] = 1.0f;
00054 m_afDiffuse[0] = 1.0f;
00055 m_afDiffuse[1] = 1.0f;
00056 m_afDiffuse[2] = 1.0f;
00057 m_afDiffuse[3] = 1.0f;
00058 m_afSpecular[0] = 0.5f;
00059 m_afSpecular[1] = 0.5f;
00060 m_afSpecular[2] = 0.5f;
00061 m_afSpecular[3] = 0.0f;
00062 m_fShininess = 5.0f;
00063 m_afPosition[0] = 60000.0f;
00064 m_afPosition[1] = 60000.0f;
00065 m_afPosition[2] = 60000.0f;
00066 m_afPosition[3] = 0.0f;
00067 m_afDirection[0] = -60000.0f;
00068 m_afDirection[1] = -60000.0f;
00069 m_afDirection[2] = -60000.0f;
00070 m_afEmission[0] = 0.5f;
00071 m_afEmission[1] = 0.5f;
00072 m_afEmission[2] = 0.5f;
00073 m_afEmission[3] = 1.0f;
00074 m_fLinearAttenuation = 0.2f;
00075 m_iSpotExponent = 1;
00076 m_iSpotCutoff = 180;
00077 }
00078
00079
00080 void K3dLight::Reset()
00081 {
00082 for ( int i=0; i<4; i++ )
00083 {
00084 m_afAmbient[i] = ( float ) 0;
00085 m_afDiffuse[i] = ( float ) 0;
00086 m_afEmission[i] = ( float ) 0;
00087 m_afPosition[i] = ( float ) 0;
00088 m_afSpecular[i] = ( float ) 0;
00089 if ( i<3 )
00090 {
00091 m_afDirection[i] = ( float ) 0;
00092 }
00093 }
00094 m_fLinearAttenuation = ( float ) 0;
00095 m_fShininess = ( float ) 0;
00096 m_iSpotCutoff = 0;
00097 m_iSpotExponent = 0;
00098
00099 }
00100
00101 void K3dLight::Destroy()
00102 {
00103 Reset();
00104 }
00105
00106 void K3dLight::DrawLight()
00107 {
00108 glLightfv ( GL_LIGHT0, GL_AMBIENT, m_afAmbient );
00109 glLightfv ( GL_LIGHT0, GL_DIFFUSE, m_afDiffuse );
00110 glLightfv ( GL_LIGHT0, GL_SPECULAR, m_afSpecular );
00111 glLightfv ( GL_LIGHT0, GL_POSITION, m_afPosition );
00112 glLightfv ( GL_LIGHT0, GL_SPOT_DIRECTION, m_afDirection );
00113 glLightf ( GL_LIGHT0, GL_LINEAR_ATTENUATION, m_fLinearAttenuation );
00114 glLighti ( GL_LIGHT0, GL_SPOT_EXPONENT, m_iSpotExponent );
00115 glLighti ( GL_LIGHT0, GL_SPOT_CUTOFF, m_iSpotCutoff );
00116 glEnable ( GL_LIGHTING );
00117 glEnable ( GL_LIGHT0 );
00118 glEnable ( GL_COLOR_MATERIAL );
00119
00120 }
00121
00122
00123