aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/instance__lighter_8cpp-source.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--docs/doxygen/nel/instance__lighter_8cpp-source.html1916
1 files changed, 1916 insertions, 0 deletions
diff --git a/docs/doxygen/nel/instance__lighter_8cpp-source.html b/docs/doxygen/nel/instance__lighter_8cpp-source.html
new file mode 100644
index 00000000..c5e2b885
--- /dev/null
+++ b/docs/doxygen/nel/instance__lighter_8cpp-source.html
@@ -0,0 +1,1916 @@
+<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
+<HTML>
+<HEAD>
+ <TITLE>nevrax.org : docs</TITLE>
+ <LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css">
+ <link href="doxygen.css" rel="stylesheet" type="text/css">
+</HEAD>
+<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
+
+<!-- uplinks -->
+<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
+ <TR>
+ <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
+ <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
+ </TR>
+</TABLE>
+
+<!-- banner Nevrax -->
+<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
+ <TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
+</TABLE>
+
+<!-- main table -->
+<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
+ <TR>
+ <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
+ <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
+
+ <!------ Begin Box ------>
+ <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
+ <FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
+ <TABLE cellspacing=0 cellpadding=1 border=0>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
+ <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
+ </TABLE>
+ </TD></TR></TABLE></TD></TR></TABLE>
+ <!------ End Box ------>
+
+ </TD>
+ <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
+ <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
+
+<!-- title -->
+<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
+<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
+</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
+</td></tr></table>
+&nbsp;
+
+<!-- block -->
+<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD>
+ <TD><B>Documentation</B></TD>
+ <TD ALIGN=RIGHT>&nbsp;</td>
+</tr></table>
+<!-- Generated by Doxygen 1.2.14 -->
+<center>
+<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
+<hr><h1>instance_lighter.cpp</h1><a href="instance__lighter_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
+00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
+00008 <font class="comment"> *</font>
+00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
+00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
+00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
+00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
+00013 <font class="comment"> * any later version.</font>
+00014 <font class="comment"></font>
+00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
+00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
+00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
+00018 <font class="comment"> * General Public License for more details.</font>
+00019 <font class="comment"></font>
+00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
+00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
+00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
+00023 <font class="comment"> * MA 02111-1307, USA.</font>
+00024 <font class="comment"> */</font>
+00025
+00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
+00027
+00028 <font class="preprocessor">#include "<a class="code" href="instance__lighter_8h.html">3d/instance_lighter.h</a>"</font>
+00029 <font class="preprocessor">#include "<a class="code" href="mesh__multi__lod_8h.html">3d/mesh_multi_lod.h</a>"</font>
+00030 <font class="preprocessor">#include "<a class="code" href="file_8h.html">nel/misc/file.h</a>"</font>
+00031 <font class="preprocessor">#include "<a class="code" href="path_8h.html">nel/misc/path.h</a>"</font>
+00032 <font class="preprocessor">#include "<a class="code" href="visual__collision__manager_8h.html">3d/visual_collision_manager.h</a>"</font>
+00033 <font class="preprocessor">#include "<a class="code" href="visual__collision__entity_8h.html">3d/visual_collision_entity.h</a>"</font>
+00034 <font class="preprocessor">#include "<a class="code" href="ig__surface__light__build_8h.html">3d/ig_surface_light_build.h</a>"</font>
+00035
+00036
+00037 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
+00038 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
+00039
+00040 <font class="keyword">namespace </font>NL3D {
+00041
+00042
+00043 <font class="comment">// Bad coded: don't set too big else it allocates too much memory.</font>
+<a name="l00044"></a><a class="code" href="instance__lighter_8cpp.html#a0">00044</a> <font class="preprocessor">#define NL3D_INSTANCE_LIGHTER_CUBE_GRID_SIZE 16</font>
+00045 <font class="preprocessor"></font>
+00046
+00047 <font class="comment">// ***************************************************************************</font>
+00048 <font class="comment">// ***************************************************************************</font>
+00049 <font class="comment">// Setup part</font>
+00050 <font class="comment">// ***************************************************************************</font>
+00051 <font class="comment">// ***************************************************************************</font>
+00052
+00053
+00054 <font class="comment">// ***************************************************************************</font>
+<a name="l00055"></a><a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#a0">00055</a> CInstanceLighter::CLightDesc::CLightDesc ()
+00056 {
+00057 <a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#m1">LightDirection</a>.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a> (1, 1, -1);
+00058 <a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#m2">GridSize</a>=512;
+00059 <a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#m3">GridCellSize</a>=4;
+00060 <a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#m4">Shadow</a>= <font class="keyword">true</font>;
+00061 <a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#m5">OverSampling</a>= 0;
+00062 <a class="code" href="classNL3D_1_1CInstanceLighter_1_1CLightDesc.html#m0">DisableSunContribution</a>= <font class="keyword">false</font>;
+00063 }
+00064
+00065 <font class="comment">// ***************************************************************************</font>
+<a name="l00066"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#a0">00066</a> CInstanceLighter::CInstanceLighter()
+00067 {
+00068 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>= NULL;
+00069 }
+00070
+00071 <font class="comment">// ***************************************************************************</font>
+<a name="l00072"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#a2">00072</a> <font class="keywordtype">void</font> CInstanceLighter::init ()
+00073 {
+00074 }
+00075
+00076 <font class="comment">// ***************************************************************************</font>
+<a name="l00077"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#d1">00077</a> <font class="keywordtype">void</font> CInstanceLighter::addTriangles (CLandscape &amp;landscape, std::vector&lt;uint&gt; &amp;listZone, uint order, std::vector&lt;CTriangle&gt;&amp; triangleArray)
+00078 {
+00079 <font class="comment">// Lamed from CZoneLighter.</font>
+00080 <font class="comment">// Set all to refine</font>
+00081 <a class="code" href="classNL3D_1_1CInstanceLighter.html#f2">excludeAllPatchFromRefineAll</a> (landscape, listZone, <font class="keyword">false</font>);
+00082
+00083 <font class="comment">// Setup the landscape</font>
+00084 landscape.setThreshold (0);
+00085 landscape.setTileMaxSubdivision (order);
+00086
+00087 <font class="comment">// Refine it</font>
+00088 landscape.refineAll (CVector (0, 0, 0));
+00089
+00090 <font class="comment">// Dump tesselated triangles</font>
+00091 std::vector&lt;const CTessFace*&gt; leaves;
+00092 landscape.getTessellationLeaves(leaves);
+00093
+00094 <font class="comment">// Number of leaves</font>
+00095 uint leavesCount=leaves.size();
+00096
+00097 <font class="comment">// Reserve the array</font>
+00098 triangleArray.reserve (triangleArray.size()+leavesCount);
+00099
+00100 <font class="comment">// Scan each leaves</font>
+00101 <font class="keywordflow">for</font> (uint leave=0; leave&lt;leavesCount; leave++)
+00102 {
+00103 <font class="comment">// Leave</font>
+00104 <font class="keyword">const</font> CTessFace *face=leaves[leave];
+00105
+00106 <font class="comment">// Add a triangle. -1 because not an instance from an IG</font>
+00107 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (face-&gt;VBase-&gt;EndPos, face-&gt;VLeft-&gt;EndPos, face-&gt;VRight-&gt;EndPos), -1 ));
+00108 }
+00109
+00110 <font class="comment">// Setup the landscape</font>
+00111 landscape.setThreshold (1000);
+00112 landscape.setTileMaxSubdivision (0);
+00113
+00114 <font class="comment">// Remove all triangles</font>
+00115 landscape.refineAll (CVector (0, 0, 0));
+00116 landscape.refineAll (CVector (0, 0, 0));
+00117 landscape.refineAll (CVector (0, 0, 0));
+00118 landscape.refineAll (CVector (0, 0, 0));
+00119 landscape.refineAll (CVector (0, 0, 0));
+00120 landscape.refineAll (CVector (0, 0, 0));
+00121 landscape.refineAll (CVector (0, 0, 0));
+00122 landscape.refineAll (CVector (0, 0, 0));
+00123 landscape.refineAll (CVector (0, 0, 0));
+00124 landscape.refineAll (CVector (0, 0, 0));
+00125
+00126 }
+00127
+00128 <font class="comment">// ***************************************************************************</font>
+<a name="l00129"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#d2">00129</a> <font class="keywordtype">void</font> CInstanceLighter::addTriangles (<font class="keyword">const</font> IShape &amp;shape, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a>&amp; modelMT, std::vector&lt;CTriangle&gt;&amp; triangleArray, sint instanceId)
+00130 {
+00131 <font class="comment">// Lamed from CZoneLighter.</font>
+00132
+00133 <font class="comment">// Cast to CMesh</font>
+00134 <font class="keyword">const</font> CMesh *mesh=dynamic_cast&lt;const CMesh*&gt;(&amp;shape);
+00135
+00136 <font class="comment">// Cast to CMeshMultiLod</font>
+00137 <font class="keyword">const</font> CMeshMultiLod *meshMulti=dynamic_cast&lt;const CMeshMultiLod*&gt;(&amp;shape);
+00138
+00139 <font class="comment">// Cast to CMeshMultiLod</font>
+00140 <font class="keyword">const</font> CMeshMRM *meshMRM=dynamic_cast&lt;const CMeshMRM*&gt;(&amp;shape);
+00141
+00142 <font class="comment">// It is a mesh ?</font>
+00143 <font class="keywordflow">if</font> (mesh)
+00144 {
+00145 <font class="comment">// Add its triangles</font>
+00146 <a class="code" href="classNL3D_1_1CInstanceLighter.html#d1">addTriangles</a> (mesh-&gt;getMeshGeom (), modelMT, triangleArray, instanceId);
+00147 }
+00148 <font class="comment">// It is a CMeshMultiLod ?</font>
+00149 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (meshMulti)
+00150 {
+00151 <font class="comment">// Get the first geommesh</font>
+00152 <font class="keyword">const</font> IMeshGeom *meshGeom=&amp;meshMulti-&gt;getMeshGeom (0);
+00153
+00154 <font class="comment">// Dynamic cast</font>
+00155 <font class="keyword">const</font> CMeshGeom *geomMesh=dynamic_cast&lt;const CMeshGeom*&gt;(meshGeom);
+00156 <font class="keywordflow">if</font> (geomMesh)
+00157 {
+00158 <a class="code" href="classNL3D_1_1CInstanceLighter.html#d1">addTriangles</a> (*geomMesh, modelMT, triangleArray, instanceId);
+00159 }
+00160
+00161 <font class="comment">// Dynamic cast</font>
+00162 <font class="keyword">const</font> CMeshMRMGeom *mrmGeomMesh=dynamic_cast&lt;const CMeshMRMGeom*&gt;(meshGeom);
+00163 <font class="keywordflow">if</font> (mrmGeomMesh)
+00164 {
+00165 <a class="code" href="classNL3D_1_1CInstanceLighter.html#d1">addTriangles</a> (*mrmGeomMesh, modelMT, triangleArray, instanceId);
+00166 }
+00167 }
+00168 <font class="comment">// It is a CMeshMultiLod ?</font>
+00169 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (meshMRM)
+00170 {
+00171 <font class="comment">// Get the first lod mesh geom</font>
+00172 <a class="code" href="classNL3D_1_1CInstanceLighter.html#d1">addTriangles</a> (meshMRM-&gt;getMeshGeom (), modelMT, triangleArray, instanceId);
+00173 }
+00174 }
+00175
+00176
+00177 <font class="comment">// ***************************************************************************</font>
+00178
+<a name="l00179"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#f0">00179</a> <font class="keywordtype">void</font> CInstanceLighter::addTriangles (<font class="keyword">const</font> CMeshGeom &amp;meshGeom, <font class="keyword">const</font> CMatrix&amp; modelMT, std::vector&lt;CTriangle&gt;&amp; triangleArray, sint instanceId)
+00180 {
+00181 <font class="comment">// Get the vertex buffer</font>
+00182 <font class="keyword">const</font> CVertexBuffer &amp;vb=meshGeom.getVertexBuffer();
+00183
+00184 <font class="comment">// For each matrix block</font>
+00185 uint numBlock=meshGeom.getNbMatrixBlock();
+00186 <font class="keywordflow">for</font> (uint block=0; block&lt;numBlock; block++)
+00187 {
+00188 <font class="comment">// For each render pass</font>
+00189 uint numRenderPass=meshGeom.getNbRdrPass(block);
+00190 <font class="keywordflow">for</font> (uint pass=0; pass&lt;numRenderPass; pass++)
+00191 {
+00192 <font class="comment">// Get the primitive block</font>
+00193 <font class="keyword">const</font> CPrimitiveBlock &amp;primitive=meshGeom.getRdrPassPrimitiveBlock ( block, pass);
+00194
+00195 <font class="comment">// Dump triangles</font>
+00196 <font class="keyword">const</font> uint32* triIndex=primitive.getTriPointer ();
+00197 uint numTri=primitive.getNumTri ();
+00198 uint tri;
+00199 <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
+00200 {
+00201 <font class="comment">// Vertex</font>
+00202 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3]));
+00203 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+1]));
+00204 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+2]));
+00205
+00206 <font class="comment">// Make a triangle</font>
+00207 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2), instanceId));
+00208 }
+00209
+00210 <font class="comment">// Dump quad</font>
+00211 triIndex=primitive.getQuadPointer ();
+00212 numTri=primitive.getNumQuad ();
+00213 <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
+00214 {
+00215 <font class="comment">// Vertex</font>
+00216 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4]));
+00217 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+1]));
+00218 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+2]));
+00219 CVector v3=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+3]));
+00220
+00221 <font class="comment">// Make 2 triangles</font>
+00222 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2), instanceId));
+00223 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v2, v3), instanceId));
+00224 }
+00225 }
+00226 }
+00227 }
+00228
+00229 <font class="comment">// ***************************************************************************</font>
+00230
+<a name="l00231"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#f1">00231</a> <font class="keywordtype">void</font> CInstanceLighter::addTriangles (<font class="keyword">const</font> CMeshMRMGeom &amp;meshGeom, <font class="keyword">const</font> CMatrix&amp; modelMT, std::vector&lt;CTriangle&gt;&amp; triangleArray, sint instanceId)
+00232 {
+00233 <font class="comment">// Get the vertex buffer</font>
+00234 <font class="keyword">const</font> CVertexBuffer &amp;vb=meshGeom.getVertexBuffer();
+00235
+00236 <font class="comment">// For each render pass</font>
+00237 uint numRenderPass=meshGeom.getNbRdrPass(0);
+00238 <font class="keywordflow">for</font> (uint pass=0; pass&lt;numRenderPass; pass++)
+00239 {
+00240 <font class="comment">// Get the primitive block</font>
+00241 <font class="keyword">const</font> CPrimitiveBlock &amp;primitive=meshGeom.getRdrPassPrimitiveBlock ( 0, pass);
+00242
+00243 <font class="comment">// Dump triangles</font>
+00244 <font class="keyword">const</font> uint32* triIndex=primitive.getTriPointer ();
+00245 uint numTri=primitive.getNumTri ();
+00246 uint tri;
+00247 <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
+00248 {
+00249 <font class="comment">// Vertex</font>
+00250 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3]));
+00251 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+1]));
+00252 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+2]));
+00253
+00254 <font class="comment">// Make a triangle</font>
+00255 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2), instanceId));
+00256 }
+00257
+00258 <font class="comment">// Dump quad</font>
+00259 triIndex=primitive.getQuadPointer ();
+00260 numTri=primitive.getNumQuad ();
+00261 <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
+00262 {
+00263 <font class="comment">// Vertex</font>
+00264 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4]));
+00265 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+1]));
+00266 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+2]));
+00267 CVector v3=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+3]));
+00268
+00269 <font class="comment">// Make 2 triangles</font>
+00270 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2), instanceId));
+00271 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v2, v3), instanceId));
+00272 }
+00273 }
+00274 }
+00275
+00276 <font class="comment">// ***************************************************************************</font>
+00277
+<a name="l00278"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#f2">00278</a> <font class="keywordtype">void</font> CInstanceLighter::excludeAllPatchFromRefineAll (CLandscape &amp;landscape, vector&lt;uint&gt; &amp;listZone, <font class="keywordtype">bool</font> exclude)
+00279 {
+00280 <font class="comment">// For each zone</font>
+00281 <font class="keywordflow">for</font> (uint zone=0; zone&lt;listZone.size(); zone++)
+00282 {
+00283 <font class="comment">// Get num patches</font>
+00284 uint patchCount=landscape.getZone(listZone[zone])-&gt;getNumPatchs();
+00285
+00286 <font class="comment">// For each patches</font>
+00287 <font class="keywordflow">for</font> (uint patch=0; patch&lt;patchCount; patch++)
+00288 {
+00289 <font class="comment">// Exclude all the patches from refine all</font>
+00290 landscape.excludePatchFromRefineAll (listZone[zone], patch, exclude);
+00291 }
+00292 }
+00293 }
+00294
+00295
+00296 <font class="comment">// ***************************************************************************</font>
+00297 <font class="comment">// ***************************************************************************</font>
+00298 <font class="comment">// light part</font>
+00299 <font class="comment">// ***************************************************************************</font>
+00300 <font class="comment">// ***************************************************************************</font>
+00301
+00302
+00303
+00304 <font class="comment">// ***************************************************************************</font>
+<a name="l00305"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#a3">00305</a> <font class="keywordtype">void</font> CInstanceLighter::light (<font class="keyword">const</font> CInstanceGroup &amp;igIn, CInstanceGroup &amp;igOut, <font class="keyword">const</font> CLightDesc &amp;lightDesc,
+00306 std::vector&lt;CTriangle&gt;&amp; obstacles, CLandscape *landscape, CIGSurfaceLightBuild *igSurfaceLightBuild)
+00307 {
+00308 sint i;
+00309 CVector outGlobalPos;
+00310 std::vector&lt;CCluster&gt; outClusters;
+00311 std::vector&lt;CPortal&gt; outPortals;
+00312 std::vector&lt;CPointLightNamed&gt; pointLightList;
+00313
+00314 <a class="code" href="debug_8h.html#a6">nlassert</a>(lightDesc.OverSampling==0 || lightDesc.OverSampling==2 || lightDesc.OverSampling==4
+00315 || lightDesc.OverSampling==8 || lightDesc.OverSampling==16);
+00316
+00317 <font class="comment">// Setup.</font>
+00318 <font class="comment">//========</font>
+00319
+00320 <font class="comment">// Prepare IGSurfaceLight lighting</font>
+00321 <font class="comment">//-----------</font>
+00322 <font class="comment">// Bkup SurfaceLightBuild to know if must light the surfaces, in differents part of the process.</font>
+00323 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>= igSurfaceLightBuild;
+00324 <font class="comment">// Prepare _IGRetrieverGridMap.</font>
+00325 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>.clear();
+00326 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+00327 {
+00328 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_17">_TotalCellNumber</a>= 0;
+00329 CIGSurfaceLightBuild::ItRetrieverGridMap itSrc;
+00330 itSrc= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;RetrieverGridMap.begin();
+00331 <font class="comment">// For all retrievers Infos in _IGSurfaceLightBuild</font>
+00332 <font class="keywordflow">while</font>(itSrc!=<a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;RetrieverGridMap.end())
+00333 {
+00334 uint numSurfaces= itSrc-&gt;second.Grids.size();
+00335 <font class="comment">// If !empty retriever.</font>
+00336 <font class="keywordflow">if</font>(numSurfaces&gt;0)
+00337 {
+00338 <font class="comment">// Add it to the map, </font>
+00339 CIGSurfaceLight::CRetrieverLightGrid &amp;rlgDst= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>[itSrc-&gt;first];
+00340 <font class="comment">// resize Array of surfaces.</font>
+00341 rlgDst.Grids.resize(numSurfaces);
+00342 <font class="comment">// For all surfaces, init them in rlgDst.</font>
+00343 <font class="keywordflow">for</font>(uint i=0; i&lt;numSurfaces; i++)
+00344 {
+00345 CIGSurfaceLightBuild::CSurface &amp;surfSrc= itSrc-&gt;second.Grids[i];
+00346 CSurfaceLightGrid &amp;surfDst= rlgDst.Grids[i];
+00347 <font class="comment">// Init Cells with a default CellCorner</font>
+00348 CSurfaceLightGrid::CCellCorner defaultCellCorner;
+00349 defaultCellCorner.SunContribution= 0;
+00350 defaultCellCorner.Light[0]= 0xFF;
+00351 defaultCellCorner.LocalAmbientId= 0xFF;
+00352
+00353 <font class="comment">// Init the grid.</font>
+00354 surfDst.Origin= surfSrc.Origin;
+00355 surfDst.Width= surfSrc.Width;
+00356 surfDst.Height= surfSrc.Height;
+00357 surfDst.Cells.resize(surfSrc.Cells.size());
+00358 surfDst.Cells.fill(defaultCellCorner);
+00359 <font class="comment">// The grid must be valid an not empty</font>
+00360 <a class="code" href="debug_8h.html#a6">nlassert</a>( surfDst.Cells.size() == surfDst.Width*surfDst.Height );
+00361 <a class="code" href="debug_8h.html#a6">nlassert</a>( surfDst.Width&gt;= 2 );
+00362 <a class="code" href="debug_8h.html#a6">nlassert</a>( surfDst.Height&gt;= 2 );
+00363
+00364 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_17">_TotalCellNumber</a>+= surfDst.Cells.size();
+00365 }
+00366 }
+00367
+00368 <font class="comment">// Next localRetriever info.</font>
+00369 itSrc++;
+00370 }
+00371 }
+00372 <font class="comment">// Reset cell iteration.</font>
+00373 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_15">_IsEndCell</a>= <font class="keyword">true</font>;
+00374
+00375
+00376 <font class="comment">// Retrieve info from igIn.</font>
+00377 <font class="comment">//-----------</font>
+00378 igIn.retrieve (outGlobalPos, <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>, outClusters, outPortals, pointLightList);
+00379
+00380
+00381 <font class="comment">// set All Instances StaticLightEnabled= true, and Build _InstanceInfos.</font>
+00382 <font class="comment">//-----------</font>
+00383 <font class="comment">// Map of shape</font>
+00384 std::map&lt;string, IShape*&gt; shapeMap;
+00385 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>.resize(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size());
+00386 <font class="keywordflow">for</font>(i=0; i&lt;(sint)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size();i++)
+00387 {
+00388 <font class="comment">// Avoid StaticLight precomputing??</font>
+00389 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].AvoidStaticLightPreCompute)
+00390 {
+00391 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled= <font class="keyword">false</font>;
+00392 <font class="comment">// Next instance.</font>
+00393 <font class="keywordflow">continue</font>;
+00394 }
+00395
+00396 <font class="comment">// Else let's do it.</font>
+00397 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled= <font class="keyword">true</font>;
+00398
+00399
+00400 <font class="comment">// Get the shape centerPos;</font>
+00401 <font class="comment">//------------</font>
+00402 CVector shapeCenterPos;
+00403 CVector overSamples[<a class="code" href="classNL3D_1_1CInstanceLighter.html#s1s0">MaxOverSamples</a>];
+00404
+00405 <font class="comment">// Get the instance shape name</font>
+00406 string name= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].Name;
+00407 <font class="keywordtype">bool</font> shapeFound= <font class="keyword">true</font>;
+00408
+00409 <font class="comment">// Try to find the shape in the UseShapeMap.</font>
+00410 std::map&lt;string, IShape*&gt;::const_iterator iteMap= lightDesc.UserShapeMap.find (name);
+00411
+00412 <font class="comment">// If not found in userShape map, try to load it from the temp loaded ShapeBank.</font>
+00413 <font class="keywordflow">if</font>( iteMap == lightDesc.UserShapeMap.end() )
+00414 {
+00415 <font class="comment">// Add a .shape at the end ?</font>
+00416 <font class="keywordflow">if</font> (name.find(<font class="charliteral">'.'</font>) == std::string::npos)
+00417 name += <font class="stringliteral">".shape"</font>;
+00418
+00419 <font class="comment">// Get the instance shape name</font>
+00420 string nameLookup = CPath::lookup (name, <font class="keyword">false</font>, <font class="keyword">false</font>);
+00421 <font class="keywordflow">if</font> (!nameLookup.empty())
+00422 name = nameLookup;
+00423
+00424 <font class="comment">// Find the shape in the bank</font>
+00425 iteMap= shapeMap.find (name);
+00426 <font class="keywordflow">if</font> (iteMap==shapeMap.end())
+00427 {
+00428 <font class="comment">// Input file</font>
+00429 CIFile inputFile;
+00430
+00431 <font class="keywordflow">if</font> (!name.empty() &amp;&amp; inputFile.open (name))
+00432 {
+00433 <font class="comment">// Load it</font>
+00434 CShapeStream stream;
+00435 stream.serial (inputFile);
+00436
+00437 <font class="comment">// Get the pointer</font>
+00438 iteMap=shapeMap.insert (std::map&lt;string, IShape*&gt;::value_type (name, stream.getShapePointer ())).first;
+00439 }
+00440 <font class="keywordflow">else</font>
+00441 {
+00442 <font class="comment">// Error</font>
+00443 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"WARNING can't load shape %s\n"</font>, name.c_str());
+00444 shapeFound= <font class="keyword">false</font>;
+00445 }
+00446 }
+00447 }
+00448
+00449
+00450 <font class="comment">// Last chance to skip it: fully LightMapped ??</font>
+00451 <font class="comment">//-----------</font>
+00452 <font class="keywordflow">if</font>(shapeFound)
+00453 {
+00454 CMeshBase *mesh= dynamic_cast&lt;CMeshBase*&gt;(iteMap-&gt;second);
+00455 <font class="keywordflow">if</font>(mesh)
+00456 {
+00457 <font class="comment">// If this mesh is not lightable (fully lightMapped)</font>
+00458 <font class="keywordflow">if</font>(!mesh-&gt;isLightable())
+00459 {
+00460 <font class="comment">// Force Avoid StaticLight precomputing</font>
+00461 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].AvoidStaticLightPreCompute= <font class="keyword">true</font>;
+00462 <font class="comment">// Disable static lighting.</font>
+00463 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled= <font class="keyword">false</font>;
+00464 <font class="comment">// Next instance.</font>
+00465 <font class="keywordflow">continue</font>;
+00466 }
+00467 }
+00468 }
+00469
+00470
+00471 <font class="comment">// Compute pos and OverSamples</font>
+00472 <font class="comment">//-----------</font>
+00473 {
+00474 <font class="comment">// Compute bbox, or default bbox</font>
+00475 CAABBox bbox;
+00476 <font class="keywordflow">if</font>(!shapeFound)
+00477 {
+00478 bbox.setCenter(CVector::Null);
+00479 bbox.setHalfSize(CVector::Null);
+00480 }
+00481 <font class="keywordflow">else</font>
+00482 {
+00483 iteMap-&gt;second-&gt;getAABBox(bbox);
+00484 }
+00485 <font class="comment">// get pos</font>
+00486 shapeCenterPos= bbox.getCenter();
+00487
+00488
+00489 <font class="comment">// Compute overSamples</font>
+00490 <font class="keywordtype">float</font> qx= bbox.getHalfSize().x/2;
+00491 <font class="keywordtype">float</font> qy= bbox.getHalfSize().y/2;
+00492 <font class="keywordtype">float</font> qz= bbox.getHalfSize().z/2;
+00493 <font class="comment">// No OverSampling =&gt; just copy.</font>
+00494 <font class="keywordflow">if</font>(lightDesc.OverSampling==0)
+00495 overSamples[0]= shapeCenterPos;
+00496 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(lightDesc.OverSampling==2)
+00497 {
+00498 <font class="comment">// Prefer Z Axis.</font>
+00499 overSamples[0]= shapeCenterPos + CVector(0, 0, qz);
+00500 overSamples[1]= shapeCenterPos - CVector(0, 0, qz);
+00501 }
+00502 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(lightDesc.OverSampling==4)
+00503 {
+00504 <font class="comment">// Apply an overSampling such that we see 4 points if we look on each side of the bbox.</font>
+00505 overSamples[0]= shapeCenterPos + CVector(-qx, -qy, -qz);
+00506 overSamples[1]= shapeCenterPos + CVector(+qx, -qy, +qz);
+00507 overSamples[2]= shapeCenterPos + CVector(-qx, +qy, +qz);
+00508 overSamples[3]= shapeCenterPos + CVector(+qx, +qy, -qz);
+00509 }
+00510 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(lightDesc.OverSampling==8 || lightDesc.OverSampling==16)
+00511 {
+00512 <font class="comment">// 8x is the best overSampling shceme for bbox</font>
+00513 overSamples[0]= shapeCenterPos + CVector(-qx, -qy, -qz);
+00514 overSamples[1]= shapeCenterPos + CVector(+qx, -qy, -qz);
+00515 overSamples[2]= shapeCenterPos + CVector(-qx, +qy, -qz);
+00516 overSamples[3]= shapeCenterPos + CVector(+qx, +qy, -qz);
+00517 overSamples[4]= shapeCenterPos + CVector(-qx, -qy, +qz);
+00518 overSamples[5]= shapeCenterPos + CVector(+qx, -qy, +qz);
+00519 overSamples[6]= shapeCenterPos + CVector(-qx, +qy, +qz);
+00520 overSamples[7]= shapeCenterPos + CVector(+qx, +qy, +qz);
+00521
+00522 <font class="comment">// 16x =&gt; use this setup, and decal from 1/8</font>
+00523 <font class="keywordflow">if</font>(lightDesc.OverSampling==16)
+00524 {
+00525 CVector decal(qx/2, qy/2, qz/2);
+00526 <font class="keywordflow">for</font>(uint sample=0; sample&lt;8; sample++)
+00527 {
+00528 <font class="comment">// Copy and decal</font>
+00529 overSamples[sample+8]= overSamples[sample] + decal;
+00530 <font class="comment">// neg decal me</font>
+00531 overSamples[sample]-= decal;
+00532 }
+00533 }
+00534 }
+00535 }
+00536
+00537
+00538 <font class="comment">// Compute pos of the instance</font>
+00539 <font class="comment">//------------</font>
+00540 CMatrix matInst;
+00541 matInst.setPos(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].Pos);
+00542 matInst.setRot(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].Rot);
+00543 matInst.scale(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].Scale);
+00544 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i].CenterPos= matInst * shapeCenterPos;
+00545 <font class="comment">// Apply matInst to samples.</font>
+00546 uint nSamples= max(1U, lightDesc.OverSampling);
+00547 <font class="keywordflow">for</font>(uint sample=0; sample&lt;nSamples; sample++)
+00548 {
+00549 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i].OverSamples[sample]= matInst * overSamples[sample];
+00550 }
+00551 }
+00552
+00553 <font class="comment">// Clean Up shapes.</font>
+00554 <font class="comment">//-----------</font>
+00555 std::map&lt;string, IShape*&gt;::iterator iteMap;
+00556 iteMap= shapeMap.begin();
+00557 <font class="keywordflow">while</font>(iteMap!= shapeMap.end())
+00558 {
+00559 <font class="comment">// delte shape</font>
+00560 <font class="keyword">delete</font> iteMap-&gt;second;
+00561 <font class="comment">// delete entry in map</font>
+00562 shapeMap.erase(iteMap);
+00563 <font class="comment">// next</font>
+00564 iteMap= shapeMap.begin();
+00565 }
+00566
+00567 <font class="comment">// Build all obstacles plane.</font>
+00568 <font class="comment">//-----------</font>
+00569 <font class="keywordflow">for</font>(i=0; i&lt;(sint)obstacles.size();i++)
+00570 {
+00571 CInstanceLighter::CTriangle&amp; triangle=obstacles[i];
+00572 <font class="comment">// Calc the plane</font>
+00573 triangle.Plane.make (triangle.Triangle.V0, triangle.Triangle.V1, triangle.Triangle.V2);
+00574 }
+00575
+00576
+00577 <font class="comment">// Lighting</font>
+00578 <font class="comment">//========</font>
+00579 <font class="comment">// Light With Sun: build the grid, and do it on all _Instances, using _InstanceInfos</font>
+00580 <font class="comment">// Compute also Lighting on surface.</font>
+00581 <a class="code" href="classNL3D_1_1CInstanceLighter.html#c0">computeSunContribution</a>(lightDesc, obstacles, landscape);
+00582
+00583 <font class="comment">// Light With PointLights</font>
+00584 <font class="comment">// build the cubeGrids</font>
+00585 <a class="code" href="classNL3D_1_1CInstanceLighter.html#c2">compilePointLightRT</a>(lightDesc.GridSize, lightDesc.GridCellSize, obstacles, lightDesc.Shadow);
+00586 <font class="comment">// kill pointLightList, because will use mine.</font>
+00587 pointLightList.clear();
+00588 <font class="comment">// Light for all _Instances, using _InstanceInfos</font>
+00589 <font class="comment">// Compute also Lighting on surface.</font>
+00590 <a class="code" href="classNL3D_1_1CInstanceLighter.html#c3">processIGPointLightRT</a>(pointLightList);
+00591
+00592 <font class="comment">// If _IGSurfaceLightBuild, then dilate lighting</font>
+00593 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+00594 {
+00595 <a class="code" href="classNL3D_1_1CInstanceLighter.html#c1">dilateLightingOnSurfaceCells</a>();
+00596 }
+00597
+00598
+00599 <font class="comment">// Build result.</font>
+00600 <font class="comment">//========</font>
+00601 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+00602 {
+00603 <font class="comment">// build with IGSurfaceLight lighting</font>
+00604 igOut.build(outGlobalPos, <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>, outClusters, outPortals, pointLightList,
+00605 &amp;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>, <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;CellSize);
+00606 }
+00607 <font class="keywordflow">else</font>
+00608 {
+00609 <font class="comment">// build without IGSurfaceLight lighting</font>
+00610 igOut.build(outGlobalPos, <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>, outClusters, outPortals, pointLightList);
+00611 }
+00612
+00613 }
+00614
+00615
+00616 <font class="comment">// ***************************************************************************</font>
+00617 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a369">NEL3DCalcBase</a> (CVector &amp;direction, CMatrix&amp; <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>)
+00618 {
+00619 direction.normalize();
+00620 CVector I=(fabs(direction*CVector(1.f,0,0))&gt;0.99)?CVector(0.f,1.f,0.f):CVector(1.f,0.f,0.f);
+00621 CVector K=-direction;
+00622 CVector J=K^I;
+00623 J.normalize();
+00624 I=J^K;
+00625 I.normalize();
+00626 <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>.identity();
+00627 <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>.setRot(I,J,K, <font class="keyword">true</font>);
+00628 }
+00629
+00630
+00631
+00632 <font class="comment">// ***************************************************************************</font>
+<a name="l00633"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#c0">00633</a> <font class="keywordtype">void</font> CInstanceLighter::computeSunContribution(<font class="keyword">const</font> CLightDesc &amp;lightDesc, std::vector&lt;CTriangle&gt;&amp; obstacles, CLandscape *landscape)
+00634 {
+00635 sint i;
+00636 <font class="comment">// Use precoputed landscape SunContribution</font>
+00637 CVisualCollisionManager *VCM= NULL;
+00638 CVisualCollisionEntity *VCE= NULL;
+00639 <font class="keywordflow">if</font>(landscape)
+00640 {
+00641 <font class="comment">// create a CVisualCollisionManager and a CVisualCollisionEntity</font>
+00642 VCM= <font class="keyword">new</font> CVisualCollisionManager;
+00643 VCM-&gt;setLandscape(landscape);
+00644 VCE= VCM-&gt;createEntity();
+00645 }
+00646 std::vector&lt;CPointLightInfluence&gt; dummyPointLightFromLandscape;
+00647 dummyPointLightFromLandscape.reserve(1024);
+00648
+00649
+00650 <font class="comment">// If DisableSunContribution, easy, </font>
+00651 <font class="keywordflow">if</font>(lightDesc.DisableSunContribution)
+00652 {
+00653 <font class="comment">// Light all instances.</font>
+00654 <font class="comment">//==========</font>
+00655 <font class="keywordflow">for</font>(i=0; i&lt;(sint)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size(); i++)
+00656 {
+00657 <font class="comment">// If staticLight not enabled, skip.</font>
+00658 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled )
+00659 <font class="keywordflow">continue</font>;
+00660
+00661 <font class="comment">// fill SunContribution to 0</font>
+00662 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].SunContribution= 0;
+00663 }
+00664
+00665 <font class="comment">// Light SurfaceGrid Cells.</font>
+00666 <font class="comment">//==========</font>
+00667 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+00668 {
+00669 <font class="comment">// Begin cell iteration</font>
+00670 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">beginCell</a>();
+00671 <font class="comment">// For all surface cell corners</font>
+00672 <font class="keywordflow">while</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>() )
+00673 {
+00674 <font class="comment">// get the current cell and cellInfo iterated.</font>
+00675 CIGSurfaceLightBuild::CCellCorner &amp;cellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">getCurrentCellInfo</a>();
+00676 CSurfaceLightGrid::CCellCorner &amp;cell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_3">getCurrentCell</a>();
+00677
+00678 <font class="comment">// if the cell corner lies in the polygon surface.</font>
+00679 <font class="keywordflow">if</font>(cellInfo.InSurface)
+00680 {
+00681 <font class="comment">// fill SunContribution to 0</font>
+00682 cell.SunContribution= 0;
+00683 <font class="comment">// copy it to cellInfo</font>
+00684 cellInfo.SunContribution= cell.SunContribution;
+00685 }
+00686
+00687 <font class="comment">// next cell</font>
+00688 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">nextCell</a>();
+00689 }
+00690 }
+00691 }
+00692 <font class="comment">// If no Raytrace Shadow, easy, </font>
+00693 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(!lightDesc.Shadow)
+00694 {
+00695 <font class="comment">// Light all instances.</font>
+00696 <font class="comment">//==========</font>
+00697 <font class="keywordflow">for</font>(i=0; i&lt;(sint)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size(); i++)
+00698 {
+00699 <a class="code" href="classNL3D_1_1CInstanceLighter.html#a4">progress</a> (<font class="stringliteral">"Compute SunContribution on Instances"</font>, i / <font class="keywordtype">float</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size()) );
+00700
+00701 <font class="comment">// If staticLight not enabled, skip.</font>
+00702 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled )
+00703 <font class="keywordflow">continue</font>;
+00704
+00705 <font class="comment">// by default, fill SunContribution to 255</font>
+00706 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].SunContribution= 255;
+00707 <font class="comment">// Try to get landscape SunContribution (better)</font>
+00708 <font class="keywordflow">if</font>(landscape)
+00709 {
+00710 CVector pos= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i].CenterPos;
+00711 uint8 landSunContribution;
+00712 dummyPointLightFromLandscape.clear();
+00713 <font class="comment">// If find faces under me</font>
+00714 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> dummyAmbient;
+00715 <font class="keywordflow">if</font>(VCE-&gt;getStaticLightSetup(pos, dummyPointLightFromLandscape, landSunContribution, dummyAmbient) )
+00716 {
+00717 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].SunContribution= landSunContribution;
+00718 }
+00719 }
+00720 }
+00721
+00722 <font class="comment">// Light SurfaceGrid Cells.</font>
+00723 <font class="comment">//==========</font>
+00724 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+00725 {
+00726 <font class="comment">// Begin cell iteration</font>
+00727 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">beginCell</a>();
+00728 <font class="comment">// For all surface cell corners</font>
+00729 <font class="keywordflow">while</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>() )
+00730 {
+00731 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_10">progressCell</a>(<font class="stringliteral">"Compute SunContribution on Surfaces"</font>);
+00732
+00733 <font class="comment">// get the current cell and cellInfo iterated.</font>
+00734 CIGSurfaceLightBuild::CCellCorner &amp;cellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">getCurrentCellInfo</a>();
+00735 CSurfaceLightGrid::CCellCorner &amp;cell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_3">getCurrentCell</a>();
+00736
+00737 <font class="comment">// if the cell corner lies in the polygon surface.</font>
+00738 <font class="keywordflow">if</font>(cellInfo.InSurface)
+00739 {
+00740 <font class="comment">// Just init SunContribution to 255, since no shadowing.</font>
+00741 cell.SunContribution= 255;
+00742 <font class="comment">// copy it to cellInfo</font>
+00743 cellInfo.SunContribution= cell.SunContribution;
+00744 }
+00745
+00746 <font class="comment">// next cell</font>
+00747 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">nextCell</a>();
+00748 }
+00749 }
+00750 }
+00751 <font class="keywordflow">else</font>
+00752 {
+00753 <font class="comment">// Compute rayBasis</font>
+00754 CVector rayDir= lightDesc.LightDirection;
+00755 CMatrix rayBasis;
+00756 rayDir.normalize();
+00757 <a class="code" href="zone__lighter_8cpp.html#a7">NEL3DCalcBase</a>(rayDir, rayBasis);
+00758 CMatrix invRayBasis;
+00759 invRayBasis= rayBasis.inverted();
+00760
+00761 <font class="comment">// Build QuadGrid of obstacles.</font>
+00762 <font class="comment">//=========</font>
+00763 <font class="comment">// setup quadGrid</font>
+00764 CQuadGrid&lt;const CTriangle*&gt; quadGrid;
+00765 quadGrid.changeBase (invRayBasis);
+00766 quadGrid.create(lightDesc.GridSize, lightDesc.GridCellSize);
+00767 <font class="comment">// Insert all obstacles in quadGrid</font>
+00768 <font class="keywordflow">for</font>(i=0; i&lt;(sint)obstacles.size(); i++)
+00769 {
+00770 CAABBox triBBox;
+00771 <font class="comment">// Compute the bbox in rayBasis.</font>
+00772 triBBox.setCenter(invRayBasis * obstacles[i].Triangle.V0);
+00773 triBBox.extend(invRayBasis * obstacles[i].Triangle.V1);
+00774 triBBox.extend(invRayBasis * obstacles[i].Triangle.V2);
+00775 <font class="comment">// And set the coord in our world, because will be multiplied with invRayBasis in insert()</font>
+00776 quadGrid.insert(rayBasis * triBBox.getMin(), rayBasis * triBBox.getMax(), &amp;obstacles[i]);
+00777 }
+00778
+00779 <font class="comment">// For all instances, light them.</font>
+00780 <font class="comment">//=========</font>
+00781 <font class="keywordflow">for</font>(i=0; i&lt;(sint)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size(); i++)
+00782 {
+00783 <a class="code" href="classNL3D_1_1CInstanceLighter.html#a4">progress</a> (<font class="stringliteral">"Compute SunContribution on Instances"</font>, i / <font class="keywordtype">float</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size()) );
+00784
+00785 <font class="comment">// If staticLight not enabled, skip.</font>
+00786 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled )
+00787 <font class="keywordflow">continue</font>;
+00788
+00789 <font class="comment">// try to use landscape SunContribution.</font>
+00790 <font class="keywordtype">bool</font> landUsed= <font class="keyword">false</font>;
+00791 <font class="keywordflow">if</font>(landscape)
+00792 {
+00793 CVector pos= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i].CenterPos;
+00794 uint8 landSunContribution;
+00795 dummyPointLightFromLandscape.clear();
+00796 <font class="comment">// If find faces under me</font>
+00797 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> dummyAmbient;
+00798 <font class="keywordflow">if</font>(VCE-&gt;getStaticLightSetup(pos, dummyPointLightFromLandscape, landSunContribution, dummyAmbient) )
+00799 {
+00800 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].SunContribution= landSunContribution;
+00801 landUsed= <font class="keyword">true</font>;
+00802 }
+00803 }
+00804
+00805 <font class="comment">// If failed to use landscape SunContribution, rayTrace</font>
+00806 <font class="keywordflow">if</font>(!landUsed)
+00807 {
+00808 <font class="comment">// number of samples (1 if no overSampling)</font>
+00809 uint nSamples= max(1U, lightDesc.OverSampling);
+00810
+00811 <font class="comment">// Default is full lighted.</font>
+00812 uint sunAccum= 255*nSamples;
+00813
+00814 <font class="comment">// For all samples</font>
+00815 <font class="keywordflow">for</font>(uint sample=0; sample&lt;nSamples; sample++)
+00816 {
+00817 <font class="comment">// pos to rayTrace against</font>
+00818 CVector pos= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i].OverSamples[sample];
+00819
+00820 <font class="comment">// rayTrace from this pos.</font>
+00821 CVector lightPos= pos-(rayDir*1000.f);
+00822 <font class="comment">// Select an element with the X axis as a 3d ray</font>
+00823 quadGrid.select (lightPos, lightPos);
+00824 <font class="comment">// For each triangle selected</font>
+00825 CQuadGrid&lt;const CTriangle*&gt;::CIterator it=quadGrid.begin();
+00826 <font class="keywordflow">while</font> (it!=quadGrid.end())
+00827 {
+00828 <font class="keyword">const</font> CTriangle *tri= *it;
+00829
+00830 <font class="comment">// If same instanceId, skip</font>
+00831 <font class="keywordflow">if</font>(tri-&gt;InstanceId != i)
+00832 {
+00833 CVector hit;
+00834 <font class="comment">// If triangle occlude the ray, no sun Contribution</font>
+00835 <font class="keywordflow">if</font>(tri-&gt;Triangle.intersect(lightPos, pos, hit, tri-&gt;Plane))
+00836 {
+00837 <font class="comment">// The sample is not touched by sun. sub his contribution</font>
+00838 sunAccum-= 255;
+00839 <font class="comment">// End</font>
+00840 <font class="keywordflow">break</font>;
+00841 }
+00842 }
+00843
+00844 it++;
+00845 }
+00846 }
+00847
+00848 <font class="comment">// Average samples</font>
+00849 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].SunContribution= sunAccum / nSamples;
+00850 }
+00851
+00852 }
+00853
+00854
+00855 <font class="comment">// Light SurfaceGrid Cells.</font>
+00856 <font class="comment">//==========</font>
+00857 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+00858 {
+00859 <font class="comment">// No instance currenlty computed, since we compute surface cells.</font>
+00860 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o2">_CurrentInstanceComputed</a>= -1;
+00861
+00862 <font class="comment">// Begin cell iteration</font>
+00863 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">beginCell</a>();
+00864 <font class="comment">// For all surface cell corners</font>
+00865 <font class="keywordflow">while</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>() )
+00866 {
+00867 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_10">progressCell</a>(<font class="stringliteral">"Compute SunContribution on Surfaces"</font>);
+00868
+00869 <font class="comment">// get the current cell and cellInfo iterated.</font>
+00870 CIGSurfaceLightBuild::CCellCorner &amp;cellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">getCurrentCellInfo</a>();
+00871 CSurfaceLightGrid::CCellCorner &amp;cell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_3">getCurrentCell</a>();
+00872
+00873 <font class="comment">// if the cell corner lies in the polygon surface.</font>
+00874 <font class="keywordflow">if</font>(cellInfo.InSurface)
+00875 {
+00876 <font class="comment">// number of samples (at least 1 if no overSampling)</font>
+00877 uint nSamples= cellInfo.NumOverSamples;
+00878 <a class="code" href="debug_8h.html#a6">nlassert</a>(nSamples&gt;=1);
+00879
+00880 <font class="comment">// Default is full lighted.</font>
+00881 uint sunAccum= 255*nSamples;
+00882
+00883 <font class="comment">// For all samples</font>
+00884 <font class="keywordflow">for</font>(uint sample=0; sample&lt;nSamples; sample++)
+00885 {
+00886 <font class="comment">// Get pos to rayTrace.</font>
+00887 CVector pos= cellInfo.OverSamples[sample];
+00888
+00889 <font class="comment">// rayTrace from the pos of this Cell sample.</font>
+00890 CVector lightPos= pos-(rayDir*1000.f);
+00891 <font class="comment">// Select an element with the X axis as a 3d ray</font>
+00892 quadGrid.select (lightPos, lightPos);
+00893 <font class="comment">// For each triangle selected</font>
+00894 CQuadGrid&lt;const CTriangle*&gt;::CIterator it=quadGrid.begin();
+00895 <font class="keywordflow">while</font> (it!=quadGrid.end())
+00896 {
+00897 <font class="keyword">const</font> CTriangle *tri= *it;
+00898
+00899 CVector hit;
+00900 <font class="comment">// If triangle occlude the ray, no sun Contribution</font>
+00901 <font class="keywordflow">if</font>(tri-&gt;Triangle.intersect(lightPos, pos, hit, tri-&gt;Plane))
+00902 {
+00903 <font class="comment">// The cell sample is not touched by sun. sub his contribution</font>
+00904 sunAccum-= 255;
+00905 <font class="comment">// End</font>
+00906 <font class="keywordflow">break</font>;
+00907 }
+00908
+00909 it++;
+00910 }
+00911 }
+00912
+00913 <font class="comment">// Average SunContribution</font>
+00914 cell.SunContribution= sunAccum / nSamples;
+00915
+00916 <font class="comment">// copy it to cellInfo</font>
+00917 cellInfo.SunContribution= cell.SunContribution;
+00918 }
+00919
+00920 <font class="comment">// next cell</font>
+00921 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">nextCell</a>();
+00922 }
+00923 }
+00924 }
+00925
+00926
+00927 <font class="comment">// Clean VCM and VCE</font>
+00928 <font class="keywordflow">if</font>(landscape)
+00929 {
+00930 <font class="comment">// delete CVisualCollisionManager and CVisualCollisionEntity</font>
+00931 VCM-&gt;deleteEntity(VCE);
+00932 <font class="keyword">delete</font> VCM;
+00933 }
+00934
+00935 }
+00936
+00937
+00938
+00939 <font class="comment">// ***************************************************************************</font>
+00940 <font class="comment">// ***************************************************************************</font>
+00941 <font class="comment">// PointLights part</font>
+00942 <font class="comment">// ***************************************************************************</font>
+00943 <font class="comment">// ***************************************************************************</font>
+00944
+00945
+00946 <font class="comment">// ***************************************************************************</font>
+<a name="l00947"></a><a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#a0">00947</a> CInstanceLighter::CPointLightRT::CPointLightRT()
+00948 {
+00949 <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m4">RefCount</a>= 0;
+00950 }
+00951
+00952
+00953 <font class="comment">// ***************************************************************************</font>
+<a name="l00954"></a><a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#a1">00954</a> <font class="keywordtype">bool</font> CInstanceLighter::CPointLightRT::testRaytrace(<font class="keyword">const</font> CVector &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, sint instanceComputed)
+00955 {
+00956 CVector dummy;
+00957
+00958 <font class="keywordflow">if</font>(!<a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m2">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#a2">include</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>))
+00959 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00960
+00961 <font class="comment">// If Ambient light, just skip</font>
+00962 <font class="keywordflow">if</font>(<a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m0">PointLight</a>.getType()== CPointLight::AmbientLight)
+00963 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00964
+00965 <font class="comment">// If SpotLight verify in angle radius.</font>
+00966 <font class="keywordflow">if</font>(<a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m0">PointLight</a>.getType()== CPointLight::SpotLight)
+00967 {
+00968 <font class="keywordtype">float</font> att= <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m0">PointLight</a>.computeLinearAttenuation(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
+00969 <font class="keywordflow">if</font> (att==0)
+00970 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00971 }
+00972
+00973
+00974 <font class="comment">// Select in the cubeGrid</font>
+00975 <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.select(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
+00976 <font class="comment">// For all faces selected</font>
+00977 <font class="keywordflow">while</font>(!<a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.isEndSel())
+00978 {
+00979 <font class="keyword">const</font> CTriangle *tri= <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.getSel();
+00980
+00981 <font class="comment">// If the triangle is not a triangle of the instance currenlty lighted</font>
+00982 <font class="keywordflow">if</font>( instanceComputed&lt;0 || tri-&gt;InstanceId != instanceComputed )
+00983 {
+00984 <font class="comment">// If intersect, the point is occluded.</font>
+00985 <font class="keywordflow">if</font>( tri-&gt;Triangle.intersect(<a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m2">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, dummy, tri-&gt;getPlane()) )
+00986 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+00987 }
+00988
+00989 <font class="comment">// next</font>
+00990 <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.nextSel();
+00991 }
+00992
+00993 <font class="comment">// Ok the point is visilbe from the light</font>
+00994 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+00995 }
+00996
+00997
+00998 <font class="comment">// ***************************************************************************</font>
+<a name="l00999"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z463_0">00999</a> <font class="keywordtype">void</font> CInstanceLighter::addStaticPointLight(<font class="keyword">const</font> CPointLightNamed &amp;pln)
+01000 {
+01001 <font class="comment">// build the plRT.</font>
+01002 CPointLightRT plRT;
+01003 plRT.PointLight= pln;
+01004 <font class="comment">// compute plRT.OODeltaAttenuation</font>
+01005 plRT.OODeltaAttenuation= pln.getAttenuationEnd() - pln.getAttenuationBegin();
+01006 <font class="keywordflow">if</font>(plRT.OODeltaAttenuation &lt;=0 )
+01007 plRT.OODeltaAttenuation= 1e10f;
+01008 <font class="keywordflow">else</font>
+01009 plRT.OODeltaAttenuation= 1.0f / plRT.OODeltaAttenuation;
+01010 <font class="comment">// compute plRT.BSphere</font>
+01011 plRT.BSphere.Center= pln.getPosition();
+01012 plRT.BSphere.Radius= pln.getAttenuationEnd();
+01013 <font class="comment">// NB: FaceCubeGrid will be computed during light()</font>
+01014
+01015 <font class="comment">// add the plRT</font>
+01016 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.push_back(plRT);
+01017
+01018 }
+01019
+01020
+01021 <font class="comment">// ***************************************************************************</font>
+<a name="l01022"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#c2">01022</a> <font class="keywordtype">void</font> CInstanceLighter::compilePointLightRT(uint gridSize, <font class="keywordtype">float</font> gridCellSize, std::vector&lt;CTriangle&gt;&amp; obstacles, <font class="keywordtype">bool</font> doShadow)
+01023 {
+01024 uint i;
+01025
+01026 <font class="comment">// Fill the quadGrid of Lights.</font>
+01027 <font class="comment">// ===========</font>
+01028 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.create(gridSize, gridCellSize);
+01029 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.size();i++)
+01030 {
+01031 CPointLightRT &amp;plRT= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>[i];
+01032
+01033 <font class="comment">// Compute the bbox of the light</font>
+01034 CAABBox bbox;
+01035 bbox.setCenter(plRT.BSphere.Center);
+01036 <font class="keywordtype">float</font> hl= plRT.BSphere.Radius;
+01037 bbox.setHalfSize(CVector(hl,hl,hl));
+01038
+01039 <font class="comment">// Insert the pointLight in the quadGrid.</font>
+01040 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.insert(bbox.getMin(), bbox.getMax(), &amp;plRT);
+01041 }
+01042
+01043
+01044 <font class="comment">// Append triangles to cubeGrid ??</font>
+01045 <font class="keywordflow">if</font>(doShadow)
+01046 {
+01047 <font class="comment">// For all obstacles, Fill a quadGrid.</font>
+01048 <font class="comment">// ===========</font>
+01049 CQuadGrid&lt;CTriangle*&gt; obstacleGrid;
+01050 obstacleGrid.create(gridSize, gridCellSize);
+01051 uint size= obstacles.size();
+01052 <font class="keywordflow">for</font>(i=0; i&lt;size; i++)
+01053 {
+01054 <font class="comment">// bbox of triangle</font>
+01055 CAABBox bbox;
+01056 bbox.setCenter(obstacles[i].Triangle.V0);
+01057 bbox.extend(obstacles[i].Triangle.V1);
+01058 bbox.extend(obstacles[i].Triangle.V2);
+01059 <font class="comment">// insert triangle in quadGrid.</font>
+01060 obstacleGrid.insert(bbox.getMin(), bbox.getMax(), &amp;obstacles[i]);
+01061 }
+01062
+01063
+01064 <font class="comment">// For all PointLights, fill his CubeGrid</font>
+01065 <font class="comment">// ===========</font>
+01066 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.size();i++)
+01067 {
+01068 <font class="comment">// progress</font>
+01069 <a class="code" href="classNL3D_1_1CInstanceLighter.html#a4">progress</a> (<font class="stringliteral">"Compute Influences of PointLights 1/2"</font>, i / (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.size());
+01070
+01071 CPointLightRT &amp;plRT= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>[i];
+01072 <font class="comment">// Create the cubeGrid</font>
+01073 plRT.FaceCubeGrid.create(plRT.PointLight.getPosition(), <a class="code" href="instance__lighter_8cpp.html#a0">NL3D_INSTANCE_LIGHTER_CUBE_GRID_SIZE</a>);
+01074
+01075 <font class="comment">// AmbiantLIghts: do nothing.</font>
+01076 <font class="keywordflow">if</font>(plRT.PointLight.getType()!=CPointLight::AmbientLight)
+01077 {
+01078 <font class="comment">// Select only obstacle Faces around the light. Other are not usefull</font>
+01079 CAABBox bbox;
+01080 bbox.setCenter(plRT.PointLight.getPosition());
+01081 <font class="keywordtype">float</font> hl= plRT.PointLight.getAttenuationEnd();
+01082 bbox.setHalfSize(CVector(hl,hl,hl));
+01083 obstacleGrid.select(bbox.getMin(), bbox.getMax());
+01084
+01085 <font class="comment">// For all faces, fill the cubeGrid.</font>
+01086 CQuadGrid&lt;CTriangle*&gt;::CIterator itObstacle;
+01087 itObstacle= obstacleGrid.begin();
+01088 <font class="keywordflow">while</font>( itObstacle!=obstacleGrid.end() )
+01089 {
+01090 CTriangle &amp;tri= *(*itObstacle);
+01091 <font class="comment">/* Don't Test BackFace culling Here (unlike in CZoneLighter !!).</font>
+01092 <font class="comment"> For objects:</font>
+01093 <font class="comment"> AutoOccluding problem is avoided with _CurrentInstanceComputed scheme.</font>
+01094 <font class="comment"> Also, With pointLights, there is no multiSampling (since no factor stored)</font>
+01095 <font class="comment"> Hence we are sure that no Object samples will lies under floor, and that the center of the </font>
+01096 <font class="comment"> object is far away.</font>
+01097 <font class="comment"> For IGSurface lighting:</font>
+01098 <font class="comment"> notice that we already add 20cm in height because of "stairs problem" so</font>
+01099 <font class="comment"> floor/surface auto_shadowing is not a problem here...</font>
+01100 <font class="comment"> */</font>
+01101 <font class="comment">// Insert the triangle in the CubeGrid</font>
+01102 plRT.FaceCubeGrid.insert( tri.Triangle, &amp;tri);
+01103
+01104 itObstacle++;
+01105 }
+01106 }
+01107
+01108 <font class="comment">// Compile the CubeGrid.</font>
+01109 plRT.FaceCubeGrid.compile();
+01110
+01111 <font class="comment">// And Reset RefCount.</font>
+01112 plRT.RefCount= 0;
+01113 }
+01114 }
+01115 <font class="comment">// else, just build empty grid</font>
+01116 <font class="keywordflow">else</font>
+01117 {
+01118 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.size();i++)
+01119 {
+01120 <font class="comment">// progress</font>
+01121 <a class="code" href="classNL3D_1_1CInstanceLighter.html#a4">progress</a> (<font class="stringliteral">"Compute Influences of PointLights 1/2"</font>, i / (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.size());
+01122
+01123 CPointLightRT &amp;plRT= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>[i];
+01124 <font class="comment">// Create a dummy empty cubeGrid =&gt; no rayTrace :)</font>
+01125 plRT.FaceCubeGrid.create(plRT.PointLight.getPosition(), 4);
+01126
+01127 <font class="comment">// Compile the CubeGrid.</font>
+01128 plRT.FaceCubeGrid.compile();
+01129
+01130 <font class="comment">// And Reset RefCount.</font>
+01131 plRT.RefCount= 0;
+01132 }
+01133 }
+01134
+01135 }
+01136
+01137
+01138 <font class="comment">// ***************************************************************************</font>
+<a name="l01139"></a><a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPredPointLightToPoint.html#a0">01139</a> <font class="keywordtype">bool</font> CInstanceLighter::CPredPointLightToPoint::operator() (CPointLightRT *pla, CPointLightRT *plb)<font class="keyword"> const</font>
+01140 <font class="keyword"></font>{
+01141 <font class="keywordtype">float</font> ra= (pla-&gt;BSphere.Center - <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPredPointLightToPoint.html#m0">Point</a>).norm();
+01142 <font class="keywordtype">float</font> rb= (plb-&gt;BSphere.Center - <a class="code" href="structNL3D_1_1CInstanceLighter_1_1CPredPointLightToPoint.html#m0">Point</a>).norm();
+01143 <font class="keywordtype">float</font> infA= (pla-&gt;PointLight.getAttenuationEnd() - ra) * pla-&gt;OODeltaAttenuation;
+01144 <font class="keywordtype">float</font> infB= (plb-&gt;PointLight.getAttenuationEnd() - rb) * plb-&gt;OODeltaAttenuation;
+01145 <font class="comment">// It is important to clamp, else strange results...</font>
+01146 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(infA, 0.f, 1.f);
+01147 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(infB, 0.f, 1.f);
+01148 <font class="comment">// return which light impact the most.</font>
+01149 <font class="comment">// If same impact</font>
+01150 <font class="keywordflow">if</font>(infA==infB)
+01151 <font class="comment">// return nearest</font>
+01152 <font class="keywordflow">return</font> ra &lt; rb;
+01153 <font class="keywordflow">else</font>
+01154 <font class="comment">// return better impact</font>
+01155 <font class="keywordflow">return</font> infA &gt; infB;
+01156 }
+01157
+01158
+01159 <font class="comment">// ***************************************************************************</font>
+<a name="l01160"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#c3">01160</a> <font class="keywordtype">void</font> CInstanceLighter::processIGPointLightRT(std::vector&lt;CPointLightNamed&gt; &amp;listPointLight)
+01161 {
+01162 uint i;
+01163 vector&lt;CPointLightRT*&gt; lightInfs;
+01164 lightInfs.reserve(1024);
+01165
+01166 <font class="comment">// clear result list</font>
+01167 listPointLight.clear();
+01168
+01169
+01170 <font class="comment">// Compute each Instance</font>
+01171 <font class="comment">//===========</font>
+01172 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>.size(); i++)
+01173 {
+01174 <font class="comment">// If staticLight not enabled, skip.</font>
+01175 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled )
+01176 <font class="keywordflow">continue</font>;
+01177
+01178 CInstanceInfo &amp;inst= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i];
+01179 <font class="comment">// Avoid autoShadowing</font>
+01180 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o2">_CurrentInstanceComputed</a>= i;
+01181
+01182 <font class="comment">// progress</font>
+01183 <a class="code" href="classNL3D_1_1CInstanceLighter.html#a4">progress</a> (<font class="stringliteral">"Compute Influences of PointLights 2/2"</font>, i / (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>.size());
+01184
+01185 <font class="comment">// get the point of the instance.</font>
+01186 CVector pos= inst.CenterPos;
+01187
+01188 <font class="comment">// Default: takes no LocalAmbientLight;</font>
+01189 inst.LocalAmbientLight= NULL;
+01190 <font class="keywordtype">float</font> furtherAmbLight= 0;
+01191
+01192 <font class="comment">// Compute Which light influences him.</font>
+01193 <font class="comment">//---------</font>
+01194 lightInfs.clear();
+01195 <font class="comment">// Search possible lights around the position.</font>
+01196 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.select(pos, pos);
+01197 <font class="comment">// For all of them, get the ones which touch this point.</font>
+01198 CQuadGrid&lt;CPointLightRT*&gt;::CIterator it= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.begin();
+01199 <font class="keywordflow">while</font>(it != <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.end())
+01200 {
+01201 CPointLightRT *pl= *it;
+01202
+01203 <font class="comment">// Test if really in the radius of the light, no occlusion, not an ambient, and in Spot Angle setup</font>
+01204 <font class="keywordflow">if</font>( pl-&gt;testRaytrace(pos, <a class="code" href="classNL3D_1_1CInstanceLighter.html#o2">_CurrentInstanceComputed</a>) )
+01205 {
+01206 <font class="comment">// Ok, add the light to the lights which influence the instance</font>
+01207 lightInfs.push_back(pl);
+01208 }
+01209
+01210 <font class="comment">// Ambient Light ??</font>
+01211 <font class="keywordflow">if</font>( pl-&gt;PointLight.getType() == CPointLight::AmbientLight )
+01212 {
+01213 <font class="comment">// If the instance is in radius of the ambiant light.</font>
+01214 <font class="keywordtype">float</font> dRadius= pl-&gt;BSphere.Radius - (pl-&gt;BSphere.Center - pos).norm();
+01215 <font class="keywordflow">if</font>(dRadius&gt;0)
+01216 {
+01217 <font class="comment">// Take the best ambient light: the one which is further from the circumference</font>
+01218 <font class="keywordflow">if</font>(dRadius &gt; furtherAmbLight)
+01219 {
+01220 furtherAmbLight= dRadius;
+01221 inst.LocalAmbientLight= pl;
+01222 }
+01223 }
+01224 }
+01225
+01226 <font class="comment">// next</font>
+01227 it++;
+01228 }
+01229
+01230 <font class="comment">// If ambientLight chosen, inc Ref count of it</font>
+01231 <font class="keywordflow">if</font>(inst.LocalAmbientLight)
+01232 inst.LocalAmbientLight-&gt;RefCount++;
+01233
+01234 <font class="comment">// Choose the Best ones.</font>
+01235 <font class="comment">//---------</font>
+01236 CPredPointLightToPoint predPLTP;
+01237 predPLTP.Point= pos;
+01238 <font class="comment">// sort.</font>
+01239 sort(lightInfs.begin(), lightInfs.end(), predPLTP);
+01240 <font class="comment">// truncate.</font>
+01241 lightInfs.resize( <a class="code" href="bit__set_8cpp.html#a0">min</a>(lightInfs.size(), (uint)CInstanceGroup::NumStaticLightPerInstance) );
+01242
+01243
+01244 <font class="comment">// For each of them, fill instance</font>
+01245 <font class="comment">//---------</font>
+01246 uint lightInfId;
+01247 <font class="keywordflow">for</font>(lightInfId=0; lightInfId&lt;lightInfs.size(); lightInfId++)
+01248 {
+01249 CPointLightRT *pl= lightInfs[lightInfId];
+01250
+01251 <font class="comment">// copy light.</font>
+01252 inst.Light[lightInfId]= pl;
+01253
+01254 <font class="comment">// Inc RefCount of the light.</font>
+01255 pl-&gt;RefCount++;
+01256 }
+01257 <font class="comment">// Reset any empty slot to NULL.</font>
+01258 <font class="keywordflow">for</font>(; lightInfId&lt;CInstanceGroup::NumStaticLightPerInstance; lightInfId++)
+01259 {
+01260 inst.Light[lightInfId]= NULL;
+01261 }
+01262
+01263 }
+01264
+01265
+01266 <font class="comment">// Compute Lighting on SurfaceLightGrid</font>
+01267 <font class="comment">//===========</font>
+01268 <font class="comment">// Must do it before compression !!</font>
+01269 <font class="comment">// NB: big copy/Past from above</font>
+01270 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+01271 {
+01272 <font class="comment">// No instance currenlty computed, since we compute surface cells.</font>
+01273 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o2">_CurrentInstanceComputed</a>= -1;
+01274
+01275 <font class="comment">// Begin cell iteration</font>
+01276 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">beginCell</a>();
+01277 <font class="comment">// For all surface cell corners</font>
+01278 <font class="keywordflow">while</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>() )
+01279 {
+01280 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_10">progressCell</a>(<font class="stringliteral">"Compute PointLights on Surfaces"</font>);
+01281
+01282 <font class="comment">// get the current cellInfo iterated.</font>
+01283 CIGSurfaceLightBuild::CCellCorner &amp;cellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">getCurrentCellInfo</a>();
+01284
+01285 <font class="comment">// if the cell corner lies in the polygon surface.</font>
+01286 <font class="keywordflow">if</font>(cellInfo.InSurface)
+01287 {
+01288 <font class="comment">// get the point of the cell.</font>
+01289 CVector pos= cellInfo.CenterPos;
+01290
+01291 <font class="comment">// Default: takes no LocalAmbientLight;</font>
+01292 cellInfo.LocalAmbientLight= NULL;
+01293 <font class="keywordtype">float</font> furtherAmbLight= 0;
+01294
+01295 <font class="comment">// Compute Which light influences him.</font>
+01296 <font class="comment">//---------</font>
+01297 lightInfs.clear();
+01298 <font class="comment">// Search possible lights around the position.</font>
+01299 <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.select(pos, pos);
+01300 <font class="comment">// For all of them, get the ones which touch this point.</font>
+01301 CQuadGrid&lt;CPointLightRT*&gt;::CIterator it= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.begin();
+01302 <font class="keywordflow">while</font>(it != <a class="code" href="classNL3D_1_1CInstanceLighter.html#o6">_StaticPointLightQuadGrid</a>.end())
+01303 {
+01304 CPointLightRT *pl= *it;
+01305
+01306 <font class="comment">// Test if really in the radius of the light, no occlusion, not an ambient, and in Spot Angle setup</font>
+01307 <font class="keywordflow">if</font>( pl-&gt;testRaytrace(pos, <a class="code" href="classNL3D_1_1CInstanceLighter.html#o2">_CurrentInstanceComputed</a>) )
+01308 {
+01309 <font class="comment">// Ok, add the light to the lights which influence the cell</font>
+01310 lightInfs.push_back(pl);
+01311 }
+01312
+01313 <font class="comment">// Ambient Light ??</font>
+01314 <font class="keywordflow">if</font>( pl-&gt;PointLight.getType() == CPointLight::AmbientLight )
+01315 {
+01316 <font class="comment">// If the instance is in radius of the ambiant light.</font>
+01317 <font class="keywordtype">float</font> dRadius= pl-&gt;BSphere.Radius - (pl-&gt;BSphere.Center - pos).norm();
+01318 <font class="keywordflow">if</font>(dRadius&gt;0)
+01319 {
+01320 <font class="comment">// Take the best ambient light: the one which is further from the circumference</font>
+01321 <font class="keywordflow">if</font>(dRadius &gt; furtherAmbLight)
+01322 {
+01323 furtherAmbLight= dRadius;
+01324 cellInfo.LocalAmbientLight= pl;
+01325 }
+01326 }
+01327 }
+01328
+01329 <font class="comment">// next</font>
+01330 it++;
+01331 }
+01332
+01333 <font class="comment">// If ambientLight chosen, inc Ref count of it</font>
+01334 <font class="keywordflow">if</font>(cellInfo.LocalAmbientLight)
+01335 ((CPointLightRT*)cellInfo.LocalAmbientLight)-&gt;RefCount++;
+01336
+01337
+01338 <font class="comment">// Choose the Best ones.</font>
+01339 <font class="comment">//---------</font>
+01340 CPredPointLightToPoint predPLTP;
+01341 predPLTP.Point= pos;
+01342 <font class="comment">// sort.</font>
+01343 sort(lightInfs.begin(), lightInfs.end(), predPLTP);
+01344 <font class="comment">// truncate.</font>
+01345 lightInfs.resize( <a class="code" href="bit__set_8cpp.html#a0">min</a>(lightInfs.size(), (uint)CSurfaceLightGrid::NumLightPerCorner) );
+01346
+01347
+01348 <font class="comment">// For each of them, fill cellInfo</font>
+01349 <font class="comment">//---------</font>
+01350 uint lightInfId;
+01351 <font class="keywordflow">for</font>(lightInfId=0; lightInfId&lt;lightInfs.size(); lightInfId++)
+01352 {
+01353 CPointLightRT *pl= lightInfs[lightInfId];
+01354
+01355 <font class="comment">// copy light.</font>
+01356 cellInfo.LightInfo[lightInfId]= pl;
+01357
+01358 <font class="comment">// Inc RefCount of the light.</font>
+01359 pl-&gt;RefCount++;
+01360 }
+01361 <font class="comment">// Reset any empty slot to NULL.</font>
+01362 <font class="keywordflow">for</font>(; lightInfId&lt;CSurfaceLightGrid::NumLightPerCorner; lightInfId++)
+01363 {
+01364 cellInfo.LightInfo[lightInfId]= NULL;
+01365 }
+01366
+01367 }
+01368
+01369 <font class="comment">// next cell</font>
+01370 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">nextCell</a>();
+01371 }
+01372 }
+01373
+01374
+01375
+01376 <font class="comment">// Compress and setup _Instances with compressed data.</font>
+01377 <font class="comment">//===========</font>
+01378 uint plId= 0;
+01379 <font class="comment">// Process each pointLights</font>
+01380 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>.size(); i++)
+01381 {
+01382 CPointLightRT &amp;plRT= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o5">_StaticPointLights</a>[i];
+01383 <font class="comment">// If this light is used.</font>
+01384 <font class="keywordflow">if</font>(plRT.RefCount &gt; 0)
+01385 {
+01386 <font class="comment">// Must Copy it into Ig.</font>
+01387 listPointLight.push_back(plRT.PointLight);
+01388 plRT.DstId= plId++;
+01389 <font class="comment">// If index &gt;= 255, too many lights (NB: =&gt; because 255 is a NULL code).</font>
+01390 <font class="keywordflow">if</font>(plId&gt;=0xFF)
+01391 {
+01392 <font class="keywordflow">throw</font> Exception(<font class="stringliteral">"Too many Static Point Lights influence the IG!!"</font>);
+01393 }
+01394 }
+01395 }
+01396
+01397 <font class="comment">// For each instance, compress Point light info</font>
+01398 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>.size(); i++)
+01399 {
+01400 <font class="comment">// If staticLight not enabled, skip.</font>
+01401 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i].StaticLightEnabled )
+01402 <font class="keywordflow">continue</font>;
+01403
+01404 CInstanceInfo &amp;instSrc= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o1">_InstanceInfos</a>[i];
+01405 CInstanceGroup::CInstance &amp;instDst= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o0">_Instances</a>[i];
+01406
+01407 <font class="comment">// Do it for PointLights</font>
+01408 <font class="keywordflow">for</font>(uint lightId= 0; lightId&lt;CInstanceGroup::NumStaticLightPerInstance; lightId++)
+01409 {
+01410 <font class="keywordflow">if</font>(instSrc.Light[lightId] == NULL)
+01411 {
+01412 <font class="comment">// Mark as unused.</font>
+01413 instDst.Light[lightId]= 0xFF;
+01414 }
+01415 <font class="keywordflow">else</font>
+01416 {
+01417 <font class="comment">// Get index.</font>
+01418 instDst.Light[lightId]= instSrc.Light[lightId]-&gt;DstId;
+01419 }
+01420 }
+01421
+01422 <font class="comment">// Do it for Ambientlight</font>
+01423 <font class="keywordflow">if</font>(instSrc.LocalAmbientLight == NULL)
+01424 instDst.LocalAmbientId= 0xFF;
+01425 <font class="keywordflow">else</font>
+01426 instDst.LocalAmbientId= instSrc.LocalAmbientLight-&gt;DstId;
+01427 }
+01428
+01429 <font class="comment">// For each cell, compress Point light info</font>
+01430 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+01431 {
+01432 <font class="comment">// Begin cell iteration</font>
+01433 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">beginCell</a>();
+01434 <font class="comment">// For all surface cell corners</font>
+01435 <font class="keywordflow">while</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>() )
+01436 {
+01437 <font class="comment">// get the current cell and cellInfo iterated.</font>
+01438 CIGSurfaceLightBuild::CCellCorner &amp;cellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">getCurrentCellInfo</a>();
+01439 CSurfaceLightGrid::CCellCorner &amp;cell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_3">getCurrentCell</a>();
+01440
+01441 <font class="keywordflow">if</font>(cellInfo.InSurface)
+01442 {
+01443 <font class="comment">// Do it for PointLights</font>
+01444 <font class="keywordflow">for</font>(uint lightId= 0; lightId&lt;CSurfaceLightGrid::NumLightPerCorner; lightId++)
+01445 {
+01446 <font class="keywordflow">if</font>(cellInfo.LightInfo[lightId] == NULL)
+01447 {
+01448 <font class="comment">// Mark as unused.</font>
+01449 cell.Light[lightId]= 0xFF;
+01450 }
+01451 <font class="keywordflow">else</font>
+01452 {
+01453 <font class="comment">// Get index.</font>
+01454 cell.Light[lightId]= reinterpret_cast&lt;CPointLightRT*&gt;(cellInfo.LightInfo[lightId])-&gt;DstId;
+01455 }
+01456 }
+01457
+01458 <font class="comment">// Do it for Ambientlight</font>
+01459 <font class="keywordflow">if</font>(cellInfo.LocalAmbientLight == NULL)
+01460 cell.LocalAmbientId= 0xFF;
+01461 <font class="keywordflow">else</font>
+01462 cell.LocalAmbientId= ((CPointLightRT*)cellInfo.LocalAmbientLight)-&gt;DstId;
+01463 }
+01464
+01465 <font class="comment">// next cell</font>
+01466 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">nextCell</a>();
+01467 }
+01468 }
+01469
+01470
+01471 }
+01472
+01473
+01474 <font class="comment">// ***************************************************************************</font>
+01475 <font class="comment">// ***************************************************************************</font>
+01476 <font class="comment">// lightIgSimple</font>
+01477 <font class="comment">// ***************************************************************************</font>
+01478 <font class="comment">// ***************************************************************************</font>
+01479
+01480
+01481 <font class="comment">// ***************************************************************************</font>
+<a name="l01482"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#d0">01482</a> <font class="keywordtype">void</font> CInstanceLighter::lightIgSimple(CInstanceLighter &amp;instLighter, <font class="keyword">const</font> CInstanceGroup &amp;igIn, CInstanceGroup &amp;igOut, <font class="keyword">const</font> CLightDesc &amp;lightDesc)
+01483 {
+01484 sint i;
+01485
+01486
+01487 <font class="comment">// Setup.</font>
+01488 <font class="comment">//=======</font>
+01489 <font class="comment">// Init</font>
+01490 instLighter.init();
+01491
+01492 <font class="comment">// Add obstacles.</font>
+01493 std::vector&lt;CInstanceLighter::CTriangle&gt; obstacles;
+01494 <font class="comment">// only if Shadowing On.</font>
+01495 <font class="keywordflow">if</font>(lightDesc.Shadow)
+01496 {
+01497 <font class="comment">// Map of shape to load</font>
+01498 std::map&lt;string, IShape*&gt; shapeMap;
+01499
+01500 <font class="comment">// For all instances of igIn.</font>
+01501 <font class="keywordflow">for</font>(i=0; i&lt;(sint)igIn.getNumInstance();i++)
+01502 {
+01503 <font class="comment">// progress</font>
+01504 instLighter.progress(<font class="stringliteral">"Loading Shapes obstacles"</font>, <font class="keywordtype">float</font>(i)/igIn.getNumInstance());
+01505
+01506 <font class="comment">// Skip it??</font>
+01507 <font class="keywordflow">if</font>(igIn.getInstance(i).DontCastShadow)
+01508 <font class="keywordflow">continue</font>;
+01509
+01510 <font class="comment">// Get the instance shape name</font>
+01511 string name= igIn.getShapeName(i);
+01512 <font class="keywordtype">bool</font> shapeFound= <font class="keyword">true</font>;
+01513
+01514 <font class="comment">// Try to find the shape in the UseShapeMap.</font>
+01515 std::map&lt;string, IShape*&gt;::const_iterator iteMap= lightDesc.UserShapeMap.find (name);
+01516
+01517 <font class="comment">// If not found in userShape map, try to load it from the temp loaded ShapeBank.</font>
+01518 <font class="keywordflow">if</font>( iteMap == lightDesc.UserShapeMap.end() )
+01519 {
+01520 <font class="comment">// Add a .shape at the end ?</font>
+01521 <font class="keywordflow">if</font> (name.find(<font class="charliteral">'.'</font>) == std::string::npos)
+01522 name += <font class="stringliteral">".shape"</font>;
+01523
+01524 <font class="comment">// Get the instance shape name</font>
+01525 string nameLookup = CPath::lookup (name, <font class="keyword">false</font>, <font class="keyword">false</font>);
+01526 <font class="keywordflow">if</font> (!nameLookup.empty())
+01527 name = nameLookup;
+01528
+01529 <font class="comment">// Find the shape in the bank</font>
+01530 iteMap= shapeMap.find (name);
+01531 <font class="keywordflow">if</font> (iteMap==shapeMap.end())
+01532 {
+01533 <font class="comment">// Input file</font>
+01534 CIFile inputFile;
+01535
+01536 <font class="keywordflow">if</font> (!name.empty() &amp;&amp; inputFile.open (name))
+01537 {
+01538 <font class="comment">// Load it</font>
+01539 CShapeStream stream;
+01540 stream.serial (inputFile);
+01541
+01542 <font class="comment">// Get the pointer</font>
+01543 iteMap=shapeMap.insert (std::map&lt;string, IShape*&gt;::value_type (name, stream.getShapePointer ())).first;
+01544 }
+01545 <font class="keywordflow">else</font>
+01546 {
+01547 <font class="comment">// Error</font>
+01548 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"WARNING can't load shape %s\n"</font>, name.c_str());
+01549 shapeFound= <font class="keyword">false</font>;
+01550 }
+01551 }
+01552 }
+01553
+01554 <font class="keywordflow">if</font>(shapeFound)
+01555 {
+01556 CMatrix matInst;
+01557 matInst.setPos(igIn.getInstancePos(i));
+01558 matInst.setRot(igIn.getInstanceRot(i));
+01559 matInst.scale(igIn.getInstanceScale(i));
+01560 <font class="comment">// Add triangles of this shape</font>
+01561 CInstanceLighter::addTriangles(*iteMap-&gt;second, matInst, obstacles, i);
+01562 }
+01563
+01564 }
+01565
+01566 <font class="comment">// Clean Up shapes.</font>
+01567 <font class="comment">//-----------</font>
+01568 std::map&lt;string, IShape*&gt;::iterator iteMap;
+01569 iteMap= shapeMap.begin();
+01570 <font class="keywordflow">while</font>(iteMap!= shapeMap.end())
+01571 {
+01572 <font class="comment">// delte shape</font>
+01573 <font class="keyword">delete</font> iteMap-&gt;second;
+01574 <font class="comment">// delete entry in map</font>
+01575 shapeMap.erase(iteMap);
+01576 <font class="comment">// next</font>
+01577 iteMap= shapeMap.begin();
+01578 }
+01579 }
+01580
+01581 <font class="comment">// Add pointLights of the IG.</font>
+01582 <font class="keywordflow">for</font>(i=0; i&lt;(sint)igIn.getPointLightList().size();i++)
+01583 {
+01584 instLighter.addStaticPointLight( igIn.getPointLightList()[i] );
+01585 }
+01586
+01587
+01588 <font class="comment">// Run.</font>
+01589 <font class="comment">//=======</font>
+01590 instLighter.light(igIn, igOut, lightDesc, obstacles);
+01591
+01592 }
+01593
+01594
+01595 <font class="comment">// ***************************************************************************</font>
+01596 <font class="comment">// ***************************************************************************</font>
+01597 <font class="comment">// Cell Iteration</font>
+01598 <font class="comment">// ***************************************************************************</font>
+01599 <font class="comment">// ***************************************************************************</font>
+01600
+01601
+01602 <font class="comment">// ***************************************************************************</font>
+<a name="l01603"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_10">01603</a> <font class="keywordtype">void</font> CInstanceLighter::progressCell(<font class="keyword">const</font> <font class="keywordtype">char</font> *message)
+01604 {
+01605 <font class="keywordtype">float</font> cp= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_8">getCurrentCellNumber</a>() / float(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_9">getTotalCellNumber</a>());
+01606 <font class="keywordflow">if</font>( cp &gt; <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_18">_LastCellProgress</a>+0.05f)
+01607 {
+01608 <a class="code" href="classNL3D_1_1CInstanceLighter.html#a4">progress</a>(message, cp);
+01609 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_18">_LastCellProgress</a>= cp;
+01610 }
+01611 }
+01612
+01613
+01614 <font class="comment">// ***************************************************************************</font>
+<a name="l01615"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">01615</a> <font class="keywordtype">void</font> CInstanceLighter::beginCell()
+01616 {
+01617 <font class="keywordflow">if</font>(_IGSurfaceLightBuild)
+01618 {
+01619 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>.begin();
+01620 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a> != <a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>.end() )
+01621 {
+01622 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a>= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;RetrieverGridMap.find(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;first);
+01623 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a> != <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;RetrieverGridMap.end() );
+01624 <font class="comment">// We are suze here that the retriever is not empty, and that the grid herself is not empty too</font>
+01625 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>= 0;
+01626 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>= 0;
+01627 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_16">_ItCurrentCellNumber</a>= 0;
+01628 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_15">_IsEndCell</a>= <font class="keyword">false</font>;
+01629 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_18">_LastCellProgress</a>= 0;
+01630 }
+01631 <font class="keywordflow">else</font>
+01632 {
+01633 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_15">_IsEndCell</a>= <font class="keyword">true</font>;
+01634 }
+01635 }
+01636 <font class="keywordflow">else</font>
+01637 {
+01638 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_15">_IsEndCell</a>= <font class="keyword">true</font>;
+01639 }
+01640 }
+01641
+01642 <font class="comment">// ***************************************************************************</font>
+<a name="l01643"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">01643</a> <font class="keywordtype">void</font> CInstanceLighter::nextCell()
+01644 {
+01645 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>());
+01646
+01647 <font class="comment">// Next Cell.</font>
+01648 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>++;
+01649 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_16">_ItCurrentCellNumber</a>++;
+01650
+01651 <font class="comment">// If end of Cells, next surface.</font>
+01652 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a> &gt;= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>].Cells.size() )
+01653 {
+01654 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>= 0;
+01655 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a> ++;
+01656 }
+01657
+01658 <font class="comment">// If end of surface, next retriever.</font>
+01659 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a> &gt;= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;second.Grids.size() )
+01660 {
+01661 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>= 0;
+01662 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>++;
+01663 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a> != <a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>.end())
+01664 {
+01665 <font class="comment">// Get info.</font>
+01666 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a>= <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;RetrieverGridMap.find(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;first);
+01667 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a> != <a class="code" href="classNL3D_1_1CInstanceLighter.html#o3">_IGSurfaceLightBuild</a>-&gt;RetrieverGridMap.end() );
+01668 }
+01669 }
+01670
+01671 <font class="comment">// If end of retreiver, End.</font>
+01672 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a> == <a class="code" href="classNL3D_1_1CInstanceLighter.html#o4">_IGRetrieverGridMap</a>.end())
+01673 {
+01674 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_15">_IsEndCell</a>= <font class="keyword">true</font>;
+01675 }
+01676 }
+01677
+01678 <font class="comment">// ***************************************************************************</font>
+<a name="l01679"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">01679</a> <font class="keywordtype">bool</font> CInstanceLighter::isEndCell()
+01680 {
+01681 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_15">_IsEndCell</a>;
+01682 }
+01683
+01684 <font class="comment">// ***************************************************************************</font>
+<a name="l01685"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_3">01685</a> CSurfaceLightGrid::CCellCorner &amp;CInstanceLighter::getCurrentCell()
+01686 {
+01687 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>());
+01688
+01689 <font class="comment">// return ref on Cell.</font>
+01690 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>].Cells[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>];
+01691 }
+01692
+01693 <font class="comment">// ***************************************************************************</font>
+<a name="l01694"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">01694</a> CIGSurfaceLightBuild::CCellCorner &amp;CInstanceLighter::getCurrentCellInfo()
+01695 {
+01696 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>());
+01697
+01698 <font class="comment">// return ref on CellInfo.</font>
+01699 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>].Cells[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>];
+01700 }
+01701
+01702
+01703 <font class="comment">// ***************************************************************************</font>
+<a name="l01704"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_5">01704</a> <font class="keywordtype">bool</font> CInstanceLighter::isCurrentNeighborCellInSurface(sint xnb, sint ynb)
+01705 {
+01706 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>());
+01707
+01708 <font class="comment">// get a ref on the current grid.</font>
+01709 CSurfaceLightGrid &amp;surfGrid= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>];
+01710 <font class="comment">// copute coordinate of the current cellCorner.</font>
+01711 sint xCell, yCell;
+01712 xCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>%surfGrid.Width;
+01713 yCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>/surfGrid.Width;
+01714 <font class="comment">// compute coordinate of the neighbor cell corner</font>
+01715 xCell+= xnb;
+01716 yCell+= ynb;
+01717
+01718 <font class="comment">// check if in the surfaceGrid</font>
+01719 <font class="keywordflow">if</font>(xCell&lt;0 || xCell&gt;=(sint)surfGrid.Width)
+01720 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+01721 <font class="keywordflow">if</font>(yCell&lt;0 || yCell&gt;=(sint)surfGrid.Height)
+01722 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+01723
+01724 <font class="comment">// compute the neighbor id</font>
+01725 uint nbId= yCell*surfGrid.Width + xCell;
+01726
+01727 <font class="comment">// Now check in the cellInfo if this cell is InSurface.</font>
+01728 <font class="keywordflow">if</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>].Cells[nbId].InSurface )
+01729 <font class="keywordflow">return</font> <font class="keyword">false</font>;
+01730
+01731 <font class="comment">// Ok, the neighbor cell is valid.</font>
+01732
+01733 <font class="keywordflow">return</font> <font class="keyword">true</font>;
+01734 }
+01735
+01736 <font class="comment">// ***************************************************************************</font>
+<a name="l01737"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_6">01737</a> CSurfaceLightGrid::CCellCorner &amp;CInstanceLighter::getCurrentNeighborCell(sint xnb, sint ynb)
+01738 {
+01739 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_5">isCurrentNeighborCellInSurface</a>(xnb, ynb));
+01740
+01741 <font class="comment">// get a ref on the current grid.</font>
+01742 CSurfaceLightGrid &amp;surfGrid= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_11">_ItRetriever</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>];
+01743 <font class="comment">// copute coordinate of the current cellCorner.</font>
+01744 sint xCell, yCell;
+01745 xCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>%surfGrid.Width;
+01746 yCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>/surfGrid.Width;
+01747 <font class="comment">// compute coordinate of the neighbor cell corner</font>
+01748 xCell+= xnb;
+01749 yCell+= ynb;
+01750 <font class="comment">// compute the neighbor id</font>
+01751 uint nbId= yCell*surfGrid.Width + xCell;
+01752
+01753 <font class="comment">// then return a ref on it</font>
+01754 <font class="keywordflow">return</font> surfGrid.Cells[nbId];
+01755 }
+01756
+01757
+01758 <font class="comment">// ***************************************************************************</font>
+<a name="l01759"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_7">01759</a> CIGSurfaceLightBuild::CCellCorner &amp;CInstanceLighter::getCurrentNeighborCellInfo(sint xnb, sint ynb)
+01760 {
+01761 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_5">isCurrentNeighborCellInSurface</a>(xnb, ynb));
+01762
+01763 <font class="comment">// get a ref on the current grid.</font>
+01764 CIGSurfaceLightBuild::CSurface &amp;surfGrid= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_12">_ItRetrieverInfo</a>-&gt;second.Grids[<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_13">_ItSurfId</a>];
+01765 <font class="comment">// copute coordinate of the current cellCorner.</font>
+01766 sint xCell, yCell;
+01767 xCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>%surfGrid.Width;
+01768 yCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_14">_ItCellId</a>/surfGrid.Width;
+01769 <font class="comment">// compute coordinate of the neighbor cell corner</font>
+01770 xCell+= xnb;
+01771 yCell+= ynb;
+01772 <font class="comment">// compute the neighbor id</font>
+01773 uint nbId= yCell*surfGrid.Width + xCell;
+01774
+01775 <font class="comment">// then return a ref on it</font>
+01776 <font class="keywordflow">return</font> surfGrid.Cells[nbId];
+01777 }
+01778
+01779
+01780 <font class="comment">// ***************************************************************************</font>
+<a name="l01781"></a><a class="code" href="classNL3D_1_1CInstanceLighter.html#c1">01781</a> <font class="keywordtype">void</font> CInstanceLighter::dilateLightingOnSurfaceCells()
+01782 {
+01783 <font class="comment">// Begin cell iteration</font>
+01784 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_0">beginCell</a>();
+01785 <font class="comment">// For all surface cell corners</font>
+01786 <font class="keywordflow">while</font>( !<a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_2">isEndCell</a>() )
+01787 {
+01788 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_10">progressCell</a>(<font class="stringliteral">"Dilate Surfaces grids"</font>);
+01789
+01790 <font class="comment">// get the current cell and cellInfo iterated.</font>
+01791 CIGSurfaceLightBuild::CCellCorner &amp;cellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_4">getCurrentCellInfo</a>();
+01792 CSurfaceLightGrid::CCellCorner &amp;cell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_3">getCurrentCell</a>();
+01793
+01794 <font class="comment">// if the cell is not in the polygon surface, try to get from his neighbors.</font>
+01795 <font class="keywordflow">if</font>(!cellInfo.InSurface)
+01796 {
+01797 <font class="comment">// Add Weighted influence of SunContribution, and get one of the PointLightContribution (random).</font>
+01798 uint wgtSunContribution= 0;
+01799 uint wgtSunCount= 0;
+01800 <font class="comment">// search if one of 8 neighbors is InSurface.</font>
+01801 <font class="keywordflow">for</font>(sint ynb= -1; ynb&lt;= 1; ynb++)
+01802 {
+01803 <font class="keywordflow">for</font>(sint xnb= -1; xnb&lt;= 1; xnb++)
+01804 {
+01805 <font class="comment">// center =&gt; skip.</font>
+01806 <font class="keywordflow">if</font>( xnb==0 &amp;&amp; ynb==0 )
+01807 <font class="keywordflow">continue</font>;
+01808 <font class="comment">// If the neighbor point is not out of the grid, and if in Surface.</font>
+01809 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_5">isCurrentNeighborCellInSurface</a>(xnb, ynb) )
+01810 {
+01811 <font class="comment">// get the neighbor cell</font>
+01812 CIGSurfaceLightBuild::CCellCorner &amp;nbCellInfo= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_7">getCurrentNeighborCellInfo</a>(xnb, ynb);
+01813 CSurfaceLightGrid::CCellCorner &amp;nbCell= <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_6">getCurrentNeighborCell</a>(xnb, ynb);
+01814 <font class="comment">// Add SunContribution.</font>
+01815 wgtSunContribution+= nbCell.SunContribution;
+01816 wgtSunCount++;
+01817 <font class="comment">// Just Copy PointLight info.</font>
+01818 <font class="keywordflow">for</font>(uint lightId= 0; lightId&lt;CSurfaceLightGrid::NumLightPerCorner; lightId++)
+01819 cell.Light[lightId]= nbCell.Light[lightId];
+01820 <font class="comment">// Just Copy AmbientLight info.</font>
+01821 cell.LocalAmbientId= nbCell.LocalAmbientId;
+01822
+01823
+01824 <font class="comment">// For debug mesh only, copy z from nb cellInfo</font>
+01825 cellInfo.CenterPos.z= nbCellInfo.CenterPos.z;
+01826 }
+01827 }
+01828 }
+01829 <font class="comment">// average SunContribution.</font>
+01830 <font class="keywordflow">if</font>(wgtSunCount&gt;0)
+01831 {
+01832 cell.SunContribution= wgtSunContribution / wgtSunCount;
+01833
+01834 <font class="comment">// For debug mesh only, copy SunContribution into cellInfo</font>
+01835 cellInfo.SunContribution= cell.SunContribution;
+01836 cellInfo.Dilated= <font class="keyword">true</font>;
+01837 }
+01838 }
+01839
+01840 <font class="comment">// next cell</font>
+01841 <a class="code" href="classNL3D_1_1CInstanceLighter.html#z464_1">nextCell</a>();
+01842 }
+01843 }
+01844
+01845
+01846
+01847 } <font class="comment">// NL3D</font>
+</pre></div>
+
+<!-- footer -->
+<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
+</TD>
+<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
+</TR>
+</TABLE>
+</BODY>
+</HTML>