KeosLight.cpp

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 
00022 #include "KeosLight.h"
00023 #include "KeosUtil.h"
00024 
00025 namespace Keos
00026 {
00027   //=======================================================================
00028   // CLight implementation
00029   //=======================================================================
00030 
00031   //-----------------------------------------------------------------------
00032   CLight::CLight()
00033   {
00034     // Default to point light, white diffuse light, linear attenuation, fair range
00035     m_nLightType = LT_POINT;
00036     m_Diffuse = CColor::White;
00037     m_Specular = CColor::Black;
00038 
00039     m_Range = 5000;
00040     m_AttenuationConst = 1.0f;
00041     m_AttenuationLinear = 0.0f;
00042     m_AttenuationQuad = 0.0f;
00043 
00044     m_SpotOuter = CRadian(CDegree(40.0f));
00045     m_SpotInner = CRadian(CDegree(30.0f));
00046     m_SpotFalloff = 1.0f;
00047 
00048     // Center in world, direction irrelevant but set anyway
00049     m_Position = TVector3F(0.0f, 0.0f, 0.0f);
00050     m_Direction = TVector3F(0.0f, 0.0f, 1.0f);
00051   }
00052 
00053   //-----------------------------------------------------------------------
00054   CLight::~CLight()
00055   {}
00056 
00057   //-----------------------------------------------------------------------
00058   void CLight::SetType(TLightType nType)
00059   {
00060     m_nLightType = nType;
00061   }
00062 
00063   //-----------------------------------------------------------------------
00064   CLight::TLightType CLight::GetType(void) const
00065   {
00066     return m_nLightType;
00067   }
00068 
00069   //-----------------------------------------------------------------------
00070   void CLight::SetPosition(float x, float y, float z)
00071   {
00072     m_Position.x = x;
00073     m_Position.y = y;
00074     m_Position.z = z;
00075   }
00076 
00077   //-----------------------------------------------------------------------
00078   void CLight::SetPosition(const TVector3F& Vec)
00079   {
00080     m_Position = Vec;
00081   }
00082 
00083   //-----------------------------------------------------------------------
00084   const TVector3F& CLight::GetPosition(void) const
00085   {
00086     return m_Position;
00087   }
00088 
00089   //-----------------------------------------------------------------------
00090   void CLight::SetDirection(float x, float y, float z)
00091   {
00092     m_Direction.x = x;
00093     m_Direction.y = y;
00094     m_Direction.z = z;
00095   }
00096 
00097   //-----------------------------------------------------------------------
00098   void CLight::SetDirection(const TVector3F& Vec)
00099   {
00100     m_Direction = Vec;
00101   }
00102 
00103   //-----------------------------------------------------------------------
00104   const TVector3F& CLight::GetDirection(void) const
00105   {
00106     return m_Direction;
00107   }
00108 
00109   //-----------------------------------------------------------------------
00110   void CLight::SetDiffuseColor(float fRed, float fGreen, float fBlue)
00111   {
00112     m_Diffuse.SetFloats(fRed, fBlue, fGreen);
00113   }
00114 
00115   //-----------------------------------------------------------------------
00116   void CLight::SetDiffuseColor(const CColor& Color)
00117   {
00118     m_Diffuse = Color;
00119   }
00120 
00121   //-----------------------------------------------------------------------
00122   const CColor& CLight::GetDiffuseColor(void) const
00123   {
00124     return m_Diffuse;
00125   }
00126 
00127   //-----------------------------------------------------------------------
00128   void CLight::SetSpecularColor(float fRed, float fGreen, float fBlue)
00129   {
00130     m_Specular.SetFloats(fRed, fBlue, fGreen);
00131   }
00132 
00133   //-----------------------------------------------------------------------
00134   void CLight::SetSpecularColor(const CColor& Color)
00135   {
00136     m_Specular = Color;
00137   }
00138 
00139   //-----------------------------------------------------------------------
00140   const CColor& CLight::GetSpecularColor(void) const
00141   {
00142     return m_Specular;
00143   }
00144 
00145   //-----------------------------------------------------------------------
00146   void CLight::SetAttenuation(Real range, Real constant,
00147                               Real linear, Real quadratic)
00148   {
00149     m_Range = range;
00150     m_AttenuationConst = constant;
00151     m_AttenuationLinear = linear;
00152     m_AttenuationQuad = quadratic;
00153   }
00154 
00155   //-----------------------------------------------------------------------
00156   Real CLight::GetAttenuationRange(void) const
00157   {
00158     return m_Range;
00159   }
00160 
00161   //-----------------------------------------------------------------------
00162   Real CLight::GetAttenuationConstant(void) const
00163   {
00164     return m_AttenuationConst;
00165   }
00166 
00167   //-----------------------------------------------------------------------
00168   Real CLight::GetAttenuationLinear(void) const
00169   {
00170     return m_AttenuationLinear;
00171   }
00172 
00173   //-----------------------------------------------------------------------
00174   Real CLight::GetAttenuationQuadric(void) const
00175   {
00176     return m_AttenuationQuad;
00177   }
00178 
00179   //-----------------------------------------------------------------------
00180   void CLight::SetSpotRange(const CRadian& innerAngle, const CRadian& outerAngle, Real falloff)
00181   {
00182     m_SpotInner = innerAngle;
00183     m_SpotOuter = outerAngle;
00184     m_SpotFalloff = falloff;
00185   }
00186 
00187   //-----------------------------------------------------------------------
00188   void CLight::SetSpotInnerAngle(const CRadian& val)
00189   {
00190     m_SpotInner = val;
00191   }
00192 
00193   //-----------------------------------------------------------------------
00194   void CLight::SetSpotOuterAngle(const CRadian& val)
00195   {
00196     m_SpotOuter = val;
00197   }
00198 
00199   //-----------------------------------------------------------------------
00200   void CLight::SetSpotFalloff(Real val)
00201   {
00202     m_SpotFalloff = val;
00203   }
00204 
00205   //-----------------------------------------------------------------------
00206   const CRadian& CLight::GetSpotInnerAngle(void) const
00207   {
00208     return m_SpotInner;
00209   }
00210 
00211   //-----------------------------------------------------------------------
00212   const CRadian& CLight::GetSpotOuterAngle(void) const
00213   {
00214     return m_SpotOuter;
00215   }
00216 
00217   //-----------------------------------------------------------------------
00218   Real CLight::GetSpotFalloff(void) const
00219   {
00220     return m_SpotFalloff;
00221   }
00222 
00223 } // namespace Keos

Generated on Fri Mar 9 14:29:02 2007 for Keos by  doxygen 1.5.1-p1