NL3D::CSurfaceLightGrid Class Reference

#include <surface_light_grid.h>


Detailed Description

Dynamic objects lighted by IG's Static Lights lookup into this grid. Builded by CInstanceLighter. Used by CIGSurfaceLight
Author:
Lionel Berenguier

Nevrax France

Date:
2002

Definition at line 57 of file surface_light_grid.h.

Public Types

enum  { NumLightPerCorner = 2 }
 We support only 2 light per corner. Should never be changed. More...


Public Member Functions

 CSurfaceLightGrid ()
 Constructor.

void getStaticLightSetup (const CVector &localPos, std::vector< CPointLightInfluence > &pointLightList, uint8 &sunContribution, CIGSurfaceLight &igsl, NLMISC::CRGBA &localAmbient) const
void serial (NLMISC::IStream &f)

Data Fields

NLMISC::CObjectVector< CCellCornerCells
uint32 Height
NLMISC::CVector2f Origin
uint32 Width


Member Enumeration Documentation

anonymous enum
 

We support only 2 light per corner. Should never be changed.

Enumeration values:
NumLightPerCorner 

Definition at line 62 of file surface_light_grid.h.

00062 {NumLightPerCorner= 2};


Constructor & Destructor Documentation

NL3D::CSurfaceLightGrid::CSurfaceLightGrid  ) 
 

Constructor.

Definition at line 43 of file surface_light_grid.cpp.

00044 {
00045         Width= 0;
00046         Height= 0;
00047 }


Member Function Documentation

void NL3D::CSurfaceLightGrid::getStaticLightSetup const CVector localPos,
std::vector< CPointLightInfluence > &  pointLightList,
uint8 sunContribution,
CIGSurfaceLight igsl,
NLMISC::CRGBA localAmbient
const
 

Definition at line 62 of file surface_light_grid.cpp.

References NL3D::CIGSurfaceLight::_Owner, NLMISC::CRGBA::A, NLMISC::CRGBA::B, NLMISC::clamp(), NL3D::CLightInfluenceInterpolator::Corners, NLMISC::CRGBA::G, NL3D::CPointLight::getAmbient(), NL3D::CIGSurfaceLight::getOOCellSize(), NL3D::CInstanceGroup::getPointLightList(), NL3D::CLightInfluenceInterpolator::interpolate(), NL3D::CSurfaceLightGrid::CCellCorner::Light, NL3D::CLightInfluenceInterpolator::CCorner::Lights, NL3D::CSurfaceLightGrid::CCellCorner::LocalAmbientId, nlassert, NLMISC::OptFastFloor(), NLMISC::CRGBA::R, sint, NL3D::CSurfaceLightGrid::CCellCorner::SunContribution, uint, uint8, x, NLMISC::CVector2f::x, NLMISC::CVector::x, y, NLMISC::CVector2f::y, and NLMISC::CVector::y.

00064 {
00065         // Get local coordinate to the grid.
00066         float   xfloat= (localPos.x - Origin.x) * igsl.getOOCellSize();
00067         float   yfloat= (localPos.y - Origin.y) * igsl.getOOCellSize();
00068         sint    wCell= Width-1;
00069         sint    hCell= Height-1;
00070         // fastFloor: use a precision of 256 to avoid doing OptFastFloorBegin.
00071         sint    wfixed= wCell<<8;
00072         sint    hfixed= hCell<<8;
00073         sint    xfixed= NLMISC::OptFastFloor(xfloat * 256);
00074         sint    yfixed= NLMISC::OptFastFloor(yfloat * 256);
00075         clamp(xfixed, 0, wfixed);
00076         clamp(yfixed, 0, hfixed);
00077         // compute the cell coord, and the subCoord for bilinear.
00078         sint    xCell, yCell, xSub, ySub;
00079         xCell= xfixed>>8;
00080         yCell= yfixed>>8;
00081         clamp(xCell, 0, wCell-1);
00082         clamp(yCell, 0, hCell-1);
00083         // Hence, xSub and ySub range is [0, 256].
00084         xSub= xfixed - (xCell<<8);
00085         ySub= yfixed - (yCell<<8);
00086 
00087 
00088         // Use a CLightInfluenceInterpolator to biLinear light influence
00089         CLightInfluenceInterpolator             interp;
00090         // Must support only 2 light per cell corner.
00091         nlassert(CSurfaceLightGrid::NumLightPerCorner==2);
00092         nlassert(CLightInfluenceInterpolator::NumLightPerCorner==2);
00093         // Get ref on array of PointLightNamed.
00094         CPointLightNamed        *igPointLights= NULL;;
00095         if( igsl._Owner->getPointLightList().size() >0 )
00096         {
00097                 // const_cast, because will only change _IdInfluence, and 
00098                 // also because CLightingManager will call appendLightedModel()
00099                 igPointLights= const_cast<CPointLightNamed*>(&(igsl._Owner->getPointLightList()[0]));
00100         }
00101         // For 4 corners.
00102         uint    x,y;
00103         uint    sunContribFixed= 0;
00104         uint    rLocalAmbientFixed= 0;
00105         uint    gLocalAmbientFixed= 0;
00106         uint    bLocalAmbientFixed= 0;
00107         uint    aLocalAmbientFixed= 0;
00108         for(y=0;y<2;y++)
00109         {
00110                 for(x=0;x<2;x++)
00111                 {
00112                         // Prepare compute for PointLights.
00113                         //-------------
00114                         // get ref on TLI, and on corner.
00115                         const CCellCorner                                               &cellCorner= Cells[ (yCell+y)*Width + xCell+x ];
00116                         CLightInfluenceInterpolator::CCorner    &corner= interp.Corners[y*2 + x];
00117                         // For all lights
00118                         uint lid;
00119                         for(lid= 0; lid<CSurfaceLightGrid::NumLightPerCorner; lid++)
00120                         {
00121                                 // get the id of the light in the ig
00122                                 uint    igLightId= cellCorner.Light[lid];
00123                                 // If empty id, stop
00124                                 if(igLightId==0xFF)
00125                                         break;
00126                                 else
00127                                 {
00128                                         // Set pointer of the light in the corner
00129                                         corner.Lights[lid]= igPointLights + igLightId;
00130                                 }
00131                         }
00132                         // Reset Empty slots.
00133                         for(; lid<CSurfaceLightGrid::NumLightPerCorner; lid++)
00134                         {
00135                                 // set to NULL
00136                                 corner.Lights[lid]= NULL;
00137                         }
00138 
00139                         // BiLinear SunContribution.
00140                         //-------------
00141                         uint    xBi= (x==0)?256-xSub : xSub;
00142                         uint    yBi= (y==0)?256-ySub : ySub;
00143                         uint    mulBi= xBi * yBi;
00144                         sunContribFixed+= cellCorner.SunContribution * mulBi;
00145 
00146 
00147                         // BiLinear Ambient Contribution.
00148                         //-------------
00149                         // If FF, then take Sun Ambient => leave color and alpha To 0.
00150                         if(cellCorner.LocalAmbientId!=0xFF)
00151                         {
00152                                 // take current ambient from pointLight
00153                                 CRGBA   ambCorner= igPointLights[cellCorner.LocalAmbientId].getAmbient();
00154                                 rLocalAmbientFixed+= ambCorner.R * mulBi;
00155                                 gLocalAmbientFixed+= ambCorner.G * mulBi;
00156                                 bLocalAmbientFixed+= ambCorner.B * mulBi;
00157                                 // increase the influence of igPointLights in alpha
00158                                 aLocalAmbientFixed+= 255 * mulBi;
00159                         }
00160                 }
00161         }
00162         // interpolate PointLights.
00163         interp.interpolate(pointLightList, xSub/256.f, ySub/256.f);
00164 
00165         // Final SunContribution
00166         sunContribution= sunContribFixed>>16;
00167 
00168         // Final SunContribution
00169         localAmbient.R= rLocalAmbientFixed>>16;
00170         localAmbient.G= gLocalAmbientFixed>>16;
00171         localAmbient.B= bLocalAmbientFixed>>16;
00172         localAmbient.A= aLocalAmbientFixed>>16;
00173 
00174 }

void NL3D::CSurfaceLightGrid::serial NLMISC::IStream f  ) 
 

Definition at line 51 of file surface_light_grid.cpp.

References NLMISC::IStream::serial(), and NLMISC::IStream::serialVersion().

00052 {
00053         (void)f.serialVersion(0);
00054         f.serial(Origin);
00055         f.serial(Width);
00056         f.serial(Height);
00057         f.serial(Cells);
00058 }


Field Documentation

NLMISC::CObjectVector<CCellCorner> NL3D::CSurfaceLightGrid::Cells
 

Definition at line 101 of file surface_light_grid.h.

Referenced by NL3D::CIGSurfaceLight::build(), NL3D::CIGSurfaceLightBuild::buildPLDebugMesh(), NL3D::CInstanceLighter::getCurrentNeighborCell(), and NL3D::CInstanceLighter::light().

uint32 NL3D::CSurfaceLightGrid::Height
 

Definition at line 100 of file surface_light_grid.h.

Referenced by NL3D::CInstanceLighter::isCurrentNeighborCellInSurface(), and NL3D::CInstanceLighter::light().

NLMISC::CVector2f NL3D::CSurfaceLightGrid::Origin
 

Definition at line 98 of file surface_light_grid.h.

Referenced by NL3D::CInstanceLighter::light().

uint32 NL3D::CSurfaceLightGrid::Width
 

Definition at line 99 of file surface_light_grid.h.

Referenced by NL3D::CInstanceLighter::getCurrentNeighborCell(), NL3D::CInstanceLighter::isCurrentNeighborCellInSurface(), and NL3D::CInstanceLighter::light().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 07:47:33 2004 for NeL by doxygen 1.3.6