light_trav.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000 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 #include "std3d.h"
00025 
00026 #include "nel/3d/light_trav.h"
00027 #include "nel/3d/hrc_trav.h"
00028 #include "nel/3d/clip_trav.h"
00029 #include "nel/3d/root_model.h"
00030 #include "nel/misc/hierarchical_timer.h"
00031 #include "nel/3d/point_light_model.h"
00032 #include "nel/3d/scene.h"
00033 
00034 using namespace std;
00035 using namespace NLMISC;
00036 
00037 
00038 namespace   NL3D
00039 {
00040 
00041 using namespace NLMISC;
00042 
00043 // ***************************************************************************
00044 CLightTrav::CLightTrav(bool bSmallScene) : LightingManager(bSmallScene)
00045 {
00046     _LightedList.resize(1024);
00047     _CurrentNumVisibleModels= 0;
00048 
00049     LightingSystemEnabled= false;
00050 }
00051 
00052 // ***************************************************************************
00053 void        CLightTrav::clearLightedList()
00054 {
00055     _CurrentNumVisibleModels= 0;
00056 }
00057 
00058 
00059 // ***************************************************************************
00060 void        CLightTrav::addPointLightModel(CPointLightModel *pl)
00061 {
00062     _DynamicLightList.insert(pl, &pl->_PointLightNode);
00063 }
00064 
00065 
00066 // ***************************************************************************
00067 void        CLightTrav::traverse()
00068 {
00069     H_AUTO( NL3D_TravLight );
00070 
00071     uint i;
00072 
00073 
00074     // If lighting System disabled, skip
00075     if(!LightingSystemEnabled)
00076         return;
00077 
00078     /* for each visible lightable transform, reset them only if they have MergedPointLight.
00079         NB: dynamic objetcs don't need it because already done in traverseHRC()
00080         (but don't worry, reset state is flagged, so resetLighting() no op...)
00081         This is important only for static object (freezeHRC()).
00082         Why? because we are not sure the MergedPointLight does not represent moving DynamicPointLights.
00083         Actually, it surely does. Because most of the static light setup return<=2 lights, and MaxLightContribution
00084         is typically==3. So any additional light may surely be a dynamic one.
00085         NB: this may not be useful since dynamicLights resetLighting() of all models in range. But this is important
00086         when the dynamic light leave the model quiclky! (because don't dirt the model).
00087         NB: this is also useful only if there is no dynamic light but the ones merged in MergedPointLight.
00088         Because dynamic always reset their old attached models (see below). This still can arise if for example
00089         _MaxLightContribution=2 and there is a FrozenStaticLightSetup of 2 lights....
00090     */
00091     for(i=0; i<_CurrentNumVisibleModels; i++ )
00092     {
00093         // if the model has a MergedPointLight, reset him (NB: already done for dynamics models)
00094         if(_LightedList[i]->useMergedPointLight())
00095         {
00096             _LightedList[i]->resetLighting();
00097         }
00098     }
00099 
00100 
00101     // By default, lightmaped objects are not lit by any light
00102     CLight  noLight;
00103     noLight.setupDirectional(CRGBA::Black, CRGBA::Black, CRGBA::Black, CVector::K);
00104     Scene->getDriver()->setLightMapDynamicLight(false, noLight);
00105 
00106     // clear the quadGrid of dynamicLights
00107     LightingManager.clearDynamicLights();
00108 
00109     // for each lightModel, process her: recompute position, resetLightedModels(), and append to the quadGrid.
00110     CPointLightModel    **pLight= _DynamicLightList.begin();
00111     uint    numPls= _DynamicLightList.size();
00112     for(;numPls>0;numPls--, pLight++)
00113     {
00114         (*pLight)->traverseLight();
00115     }
00116 
00117     // for each visible lightable transform
00118     for(i=0; i<_CurrentNumVisibleModels; i++ )
00119     {
00120         // traverse(), to recompute light contribution (if needed).
00121         _LightedList[i]->traverseLight();
00122     }
00123 
00124 }
00125 
00126 
00127 // ***************************************************************************
00128 void        CLightTrav::reserveLightedList(uint numModels)
00129 {
00130     // enlarge only.
00131     if(numModels>_LightedList.size())
00132         _LightedList.resize(numModels);
00133 }
00134 
00135 
00136 }

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