K3dLight.cpp

Go to the documentation of this file.
00001 
00013 /***************************************************************************
00014  *   Copyright (C) 2007 by Jan Koci   *
00015  *   honza.koci@email.cz   *
00016  *   http://kengine.sourceforge.net/tutorial/
00017  *                                                                         *
00018  *   This program is free software; you can redistribute it and/or modify  *
00019  *   it under the terms of the GNU General Public License as published by  *
00020  *   the Free Software Foundation; either version 2 of the License, or     *
00021  *   (at your option) any later version.                                   *
00022  *                                                                         *
00023  *   This program is distributed in the hope that it will be useful,       *
00024  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00025  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00026  *   GNU General Public License for more details.                          *
00027  *                                                                         *
00028  *   You should have received a copy of the GNU General Public License     *
00029  *   along with this program; if not, write to the                         *
00030  *   Free Software Foundation, Inc.,                                       *
00031  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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 );         // Enable lighting
00117         glEnable ( GL_LIGHT0 );           // Enable light 0
00118         glEnable ( GL_COLOR_MATERIAL );  // Enable material color
00119 
00120 }
00121 
00122 
00123 

Generated on Thu Aug 16 23:53:26 2007 for K3dEngine by  doxygen 1.5.0