# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

ig_surface_light.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000-2002 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "std3d.h"
00027 
00028 #include "3d/ig_surface_light.h"
00029 
00030 
00031 namespace NL3D 
00032 {
00033 
00034 // ***************************************************************************
00035 CIGSurfaceLight::CIGSurfaceLight()
00036 {
00037         _Owner= NULL;
00038         _CellSize= 1;
00039         _OOCellSize= 1;
00040 }
00041 
00042 // ***************************************************************************
00043 void                    CIGSurfaceLight::setOwner(CInstanceGroup *owner)
00044 {
00045         nlassert(owner!=NULL);
00046         _Owner= owner;
00047 }
00048 
00049 // ***************************************************************************
00050 void                    CIGSurfaceLight::build(const TRetrieverGridMap &retrieverGridMap, float cellSize,
00051         const std::vector<uint> &plRemap)
00052 {
00053         _RetrieverGridMap= retrieverGridMap;
00054         nlassert(cellSize>0);
00055         _CellSize= cellSize;
00056         _OOCellSize= 1.f/_CellSize;
00057 
00058         // remap indices.
00059         ItRetrieverGridMap      it;
00060         for(it= _RetrieverGridMap.begin(); it!=_RetrieverGridMap.end(); it++)
00061         {
00062                 // For all grids of this retriever
00063                 for(uint iGrid= 0; iGrid<it->second.Grids.size(); iGrid++)
00064                 {
00065                         CSurfaceLightGrid       &grid= it->second.Grids[iGrid];
00066 
00067                         // For all cells of this grid.
00068                         for(uint iCell= 0; iCell<grid.Cells.size(); iCell++)
00069                         {
00070                                 CSurfaceLightGrid::CCellCorner  &cell= grid.Cells[iCell];
00071 
00072                                 // For all point light id.
00073                                 for(uint lid= 0; lid<CSurfaceLightGrid::NumLightPerCorner; lid++)
00074                                 {
00075                                         if(cell.Light[lid] == 0xFF)
00076                                                 break;
00077                                         else
00078                                                 cell.Light[lid]= plRemap[cell.Light[lid]];
00079                                 }
00080 
00081                                 // remap ambient light
00082                                 if(cell.LocalAmbientId!=0xFF)
00083                                         cell.LocalAmbientId= plRemap[cell.LocalAmbientId];
00084                         }
00085                 }
00086         }
00087 }
00088 
00089 // ***************************************************************************
00090 void                    CIGSurfaceLight::clear()
00091 {
00092         _RetrieverGridMap.clear();
00093         _CellSize= 1;
00094         _OOCellSize= 1;
00095 }
00096 
00097 // ***************************************************************************
00098 void                    CIGSurfaceLight::serial(NLMISC::IStream &f)
00099 {
00100         (void)f.serialVersion(0);
00101 
00102         f.serial(_CellSize);
00103         f.serial(_OOCellSize);
00104         f.serialCont(_RetrieverGridMap);
00105 }
00106 
00107 // ***************************************************************************
00108 bool                    CIGSurfaceLight::getStaticLightSetup(const std::string &retrieverIdentifier, sint surfaceId, const CVector &localPos, 
00109         std::vector<CPointLightInfluence> &pointLightList, uint8 &sunContribution, NLMISC::CRGBA &localAmbient)
00110 {
00111         nlassert(_Owner);
00112 
00113         // default
00114         sunContribution= 255;
00115         localAmbient.set(0,0,0,0);
00116 
00117         ItRetrieverGridMap      it;
00118         it= _RetrieverGridMap.find(retrieverIdentifier);
00119         // If bad ident
00120         if(it==_RetrieverGridMap.end())
00121                 return false;
00122         CRetrieverLightGrid             &rlg= it->second;
00123         // if bad surfaceId
00124         if(surfaceId<0 || surfaceId>= (sint)rlg.Grids.size())
00125                 return false;
00126 
00127         // Else, ok, get it.
00128         rlg.Grids[surfaceId].getStaticLightSetup(localPos, pointLightList, sunContribution, *this, localAmbient);
00129         return true;
00130 }
00131 
00132 
00133 
00134 
00135 } // NL3D