point_light.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2001 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_POINT_LIGHT_H
00025 #define NL_POINT_LIGHT_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/rgba.h"
00029 #include "nel/misc/vector.h"
00030 #include "nel/misc/stl_block_list.h"
00031 
00032 
00033 namespace NL3D
00034 {
00035 
00036 
00037 using NLMISC::CVector;
00038 using NLMISC::CRGBA;
00039 
00040 
00041 class   CLight;
00042 class   CTransform;
00043 
00044 
00045 // ***************************************************************************
00046 // Size of a block for allocation of lighted models nodes.
00047 #define NL3D_LIGHTED_MODEL_ALLOC_BLOCKSIZE  1024
00048 
00049 
00050 // ***************************************************************************
00067 class CPointLight
00068 {
00069 public:
00071     //typedef   NLMISC::CSTLBlockList<CTransform*>  TTransformList;
00072     typedef std::list<CTransform*>  TTransformList;
00073     typedef TTransformList::iterator            ItTransformList;
00074 
00075     enum    TType
00076     {
00077         // The light is a point.
00078         PointLight= 0,
00079 
00080         // The light is a spotlight with a cone.
00081         SpotLight,
00082 
00083         // The light is an Ambient PointLight in an Ig.
00084         AmbientLight
00085     };
00086 
00087 
00088 public:
00089 
00096     CPointLight();
00098     ~CPointLight();
00100     CPointLight(const CPointLight &o);
00102     CPointLight &operator=(const CPointLight &o);
00103 
00104 
00106     // @{
00107 
00109     void            setType(TType type);
00110     TType           getType() const;
00111 
00113     void            setPosition(const CVector &v) {_Position= v;}
00115     const CVector   &getPosition() const {return _Position;}
00116 
00117 
00119     void            setAmbient (NLMISC::CRGBA ambient)  {_Ambient=ambient;}
00121     void            setDiffuse (NLMISC::CRGBA diffuse)  {_Diffuse=diffuse;}
00123     void            setSpecular (NLMISC::CRGBA specular)    {_Specular=specular;}
00125     void            setColor (NLMISC::CRGBA color)  {_Diffuse= _Specular= color;}
00126 
00128     NLMISC::CRGBA   getAmbient () const {return _Ambient;}
00130     NLMISC::CRGBA   getDiffuse () const {return _Diffuse;}
00132     NLMISC::CRGBA   getSpecular () const    {return _Specular;}
00133 
00134 
00138     void            setupAttenuation(float attenuationBegin, float attenuationEnd);
00140     float           getAttenuationBegin() const {return _AttenuationBegin;}
00142     float           getAttenuationEnd() const {return _AttenuationEnd;}
00143 
00144 
00148     void            setupSpotAngle(float spotAngleBegin, float spotAngleEnd);
00150     float           getSpotAngleBegin() const {return _SpotAngleBegin;}
00152     float           getSpotAngleEnd() const {return _SpotAngleEnd;}
00153 
00154 
00158     void            setupSpotDirection(const CVector &dir);
00160     const CVector   &getSpotDirection() const {return _SpotDirection;}
00161 
00162 
00163     // serial
00164     void            serial(NLMISC::IStream &f);
00165 
00166 
00167     // @}
00168 
00169 
00170 
00172     // @{
00173 
00175     float           computeLinearAttenuation(const CVector &pos) const;
00176 
00181     float           computeLinearAttenuation(const CVector &pos, float precomputedDist, float modelRadius=0) const;
00182 
00184     void            setupDriverLight(CLight &light, uint8 factor);
00185 
00190     void            setupDriverLightUserAttenuation(CLight &light, uint8 factor);
00191 
00193     void            resetLightedModels();
00194 
00196     ItTransformList appendLightedModel(CTransform *model);
00198     void            removeLightedModel(ItTransformList it);
00199 
00200     // @}
00201 
00202     // Purge static memory
00203     static void     purge ();
00204 
00205     // Specific For Ambient light
00206     bool            getAddAmbientWithSun() const {return _AddAmbientWithSun;}
00207     void            setAddAmbientWithSun(bool state);
00208 
00209 // ******************
00210 private:
00211 
00212     // Type of the light
00213     TType           _Type;
00214 
00215     // The position.
00216     CVector         _Position;
00217 
00218     // The light color.
00219     NLMISC::CRGBA   _Ambient;
00220     NLMISC::CRGBA   _Diffuse;
00221     NLMISC::CRGBA   _Specular;
00222 
00223     // Attenuation. setup / preComputed.
00224     float           _AttenuationBegin, _AttenuationEnd;
00225     float           _OODeltaAttenuation;
00226     float           _ConstantAttenuation;
00227     float           _LinearAttenuation;
00228     float           _QuadraticAttenuation;
00229 
00230     // Spot Setup
00231     CVector         _SpotDirection;
00232     float           _SpotAngleBegin;
00233     float           _SpotAngleEnd;
00234     float           _CosSpotAngleEnd;
00235     // 1 / (_CosSpotAngleBegin * _CosSpotAngleEnd)
00236     float           _OOCosSpotAngleDelta;
00237     float           _SpotExponent;
00238 
00239     // Ambient specific
00240     bool            _AddAmbientWithSun;
00241 
00242     // The memory for list of LightedModels
00243     //static    NLMISC::CBlockMemory<CTransform*, false>        _LightedModelListMemory;
00244     // LightedModels. NB: do not contains models that have this light in their FrozenStaticLightSetup
00245     TTransformList      _LightedModels;
00246 
00247 
00248     void        computeAttenuationFactors();
00249     void        computeSpotAttenuationFactors();
00250 
00251 };
00252 
00253 
00254 } // NL3D
00255 
00256 
00257 #endif // NL_POINT_LIGHT_H
00258 
00259 /* End of point_light.h */

Generated on Thu Jan 7 08:26:19 2010 for NeL by  doxygen 1.6.1