aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/patch__vegetable_8cpp-source.html
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
committerneodarz <neodarz@neodarz.net>2018-08-11 20:21:34 +0200
commit0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch)
tree2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/patch__vegetable_8cpp-source.html
downloadnevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz
nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip
Initial commit
Diffstat (limited to '')
-rw-r--r--docs/doxygen/nel/patch__vegetable_8cpp-source.html411
1 files changed, 411 insertions, 0 deletions
diff --git a/docs/doxygen/nel/patch__vegetable_8cpp-source.html b/docs/doxygen/nel/patch__vegetable_8cpp-source.html
new file mode 100644
index 00000000..ca374488
--- /dev/null
+++ b/docs/doxygen/nel/patch__vegetable_8cpp-source.html
@@ -0,0 +1,411 @@
+<!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>patch_vegetable.cpp</h1><a href="patch__vegetable_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
+00029 <font class="preprocessor">#include "<a class="code" href="patch_8h.html">3d/patch.h</a>"</font>
+00030 <font class="preprocessor">#include "<a class="code" href="vegetable_8h.html">3d/vegetable.h</a>"</font>
+00031 <font class="preprocessor">#include "<a class="code" href="vegetable__manager_8h.html">3d/vegetable_manager.h</a>"</font>
+00032 <font class="preprocessor">#include "<a class="code" href="landscape__vegetable__block_8h.html">3d/landscape_vegetable_block.h</a>"</font>
+00033 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font>
+00034 <font class="preprocessor">#include "<a class="code" href="vector_8h.html">nel/misc/vector.h</a>"</font>
+00035 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font>
+00036 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
+00037 <font class="preprocessor">#include "<a class="code" href="tile__vegetable__desc_8h.html">3d/tile_vegetable_desc.h</a>"</font>
+00038 <font class="preprocessor">#include "<a class="code" href="vegetable__light__ex_8h.html">3d/vegetable_light_ex.h</a>"</font>
+00039 <font class="preprocessor">#include "<a class="code" href="patchdlm__context_8h.html">3d/patchdlm_context.h</a>"</font>
+00040
+00041
+00042 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
+00043 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
+00044
+00045 <font class="keyword">namespace </font>NL3D
+00046 {
+00047
+00048
+00049 <font class="comment">// ***************************************************************************</font>
+<a name="l00050"></a><a class="code" href="classNL3D_1_1CPatch.html#z686_2">00050</a> <font class="keywordtype">void</font> CPatch::generateTileVegetable(CVegetableInstanceGroup *vegetIg, uint distType, uint ts, uint tt,
+00051 CLandscapeVegetableBlockCreateContext &amp;vbCreateCtx)
+00052 {
+00053 uint i;
+00054
+00055 <font class="comment">// Get tile infos for vegetable</font>
+00056 <font class="comment">// =========================</font>
+00057
+00058 <font class="comment">// Get the state for this vegetable tile</font>
+00059 CTileElement::TVegetableInfo vegetWaterState= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tt * <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a> + ts].getVegetableState();
+00060 <font class="comment">// If vegetable disabled, skip!</font>
+00061 <font class="keywordflow">if</font>(vegetWaterState == CTileElement::VegetableDisabled)
+00062 <font class="keywordflow">return</font>;
+00063
+00064 <font class="comment">// get the tileId under this tile (&lt;=&gt; the tile material)</font>
+00065 uint tileId= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tt * <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a> + ts].Tile[0];
+00066
+00067 <font class="comment">// get list of vegetable for this tile, and for hist distanceType category.</font>
+00068 <font class="keyword">const</font> CTileVegetableDesc &amp;tileVegetDesc= <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;getTileVegetableDesc(tileId);
+00069 <font class="keyword">const</font> std::vector&lt;CVegetable&gt; &amp;vegetableList= tileVegetDesc.getVegetableList(distType);
+00070 uint distAddSeed= tileVegetDesc.getVegetableSeed(distType);
+00071 uint numVegetable= vegetableList.size();
+00072
+00073 <font class="comment">// If no vegetables at all, skip.</font>
+00074 <font class="keywordflow">if</font>(numVegetable==0)
+00075 <font class="keywordflow">return</font>;
+00076
+00077 <font class="comment">// compute approximate tile position and normal: get the middle</font>
+00078 <font class="keywordtype">float</font> tileU= (ts + 0.5f) / (float)<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>;
+00079 <font class="keywordtype">float</font> tileV= (tt + 0.5f) / (float)<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>;
+00080 CBezierPatch *bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
+00081 <font class="comment">// Get approximate position for the tile (usefull for noise). NB: eval() is faster than computeVertex().</font>
+00082 CVector tilePos= bpatch-&gt;eval(tileU, tileV);
+00083 <font class="comment">// Get also the normal used for all instances on this tile (not precise, </font>
+00084 <font class="comment">// don't take noise into account, but faster).</font>
+00085 CVector tileNormal= bpatch-&gt;evalNormal(tileU, tileV);
+00086
+00087 <font class="comment">// Compute also position on middle of 4 edges of this tile, for generateGroupBiLinear().</font>
+00088 CVector tilePosBiLinear[4];
+00089 <font class="keywordtype">float</font> OOos= 1.0f / <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>;
+00090 <font class="keywordtype">float</font> OOot= 1.0f / <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>;
+00091 tilePosBiLinear[0]= bpatch-&gt;eval( (ts + 0.0f) * OOos, (tt + 0.5f) * OOot);
+00092 tilePosBiLinear[1]= bpatch-&gt;eval( (ts + 1.0f) * OOos, (tt + 0.5f) * OOot);
+00093 tilePosBiLinear[2]= bpatch-&gt;eval( (ts + 0.5f) * OOos, (tt + 0.0f) * OOot);
+00094 tilePosBiLinear[3]= bpatch-&gt;eval( (ts + 0.5f) * OOos, (tt + 1.0f) * OOot);
+00095
+00096
+00097 <font class="comment">// compute a rotation matrix with the normal</font>
+00098 CMatrix matInstance;
+00099 matInstance.setRot(CVector::I, CVector::J, tileNormal);
+00100 <font class="comment">// must normalize the matrix. use the vector which is the most orthogonal to tileNormal</font>
+00101 <font class="comment">// If tileNormal is much more a J vector, then use plane (I,tileNormal), and vice-versa</font>
+00102 <font class="keywordflow">if</font>(fabs(tileNormal.y) &gt; fabs(tileNormal.x))
+00103 matInstance.normalize(CMatrix::ZXY);
+00104 <font class="keywordflow">else</font>
+00105 matInstance.normalize(CMatrix::ZYX);
+00106
+00107
+00108 <font class="comment">// prepare color / lighting</font>
+00109 <font class="comment">// =========================</font>
+00110
+00111 <font class="comment">// say that ambient never change. VegetableManager handle the ambient and diffuse itself (for precomputeLighting)</font>
+00112 CRGBAF ambientF= CRGBAF(1,1,1,1);
+00113
+00114 <font class="comment">// Compute the tileLightmap (not modified by tileColor).</font>
+00115 <font class="keyword">static</font> uint8 tileLumelmap[<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a> * <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>];
+00116 <a class="code" href="classNL3D_1_1CPatch.html#z686_3">getTileLumelmapPrecomputed</a>(ts, tt, tileLumelmap, <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>);
+00117 <font class="comment">// compute diffuse color by substracting from ambient.</font>
+00118 CRGBAF diffuseColorF[<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a> * <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>];
+00119 <font class="comment">// TODO_VEGET_OPTIM: optimize this.</font>
+00120 <font class="comment">// For all lumel of this tile.</font>
+00121 <font class="keywordflow">for</font>(i= 0; i&lt;<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>*<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>; i++)
+00122 {
+00123 <font class="comment">// mul by 2, because shade is done twice here: by vertex, and by landscape.</font>
+00124 sint tileLumel= 2*tileLumelmap[i];
+00125 tileLumel= <a class="code" href="bit__set_8cpp.html#a0">min</a>(tileLumel, 255);
+00126 <font class="keywordtype">float</font> tlf= tileLumel / 255.f;
+00127 diffuseColorF[i].R= tlf;
+00128 diffuseColorF[i].G= tlf;
+00129 diffuseColorF[i].B= tlf;
+00130 diffuseColorF[i].A= 1;
+00131 }
+00132
+00133 <font class="comment">// Compute The CVegetableLightEx, adding pointLight effect to vegetation</font>
+00134 <font class="comment">// First get pointLight at this tiles.</font>
+00135 <font class="keyword">static</font> vector&lt;CPointLightInfluence&gt; lightList;
+00136 lightList.clear();
+00137 <a class="code" href="classNL3D_1_1CPatch.html#z671_1">appendTileLightInfluences</a>( CUV(tileU, tileV), lightList);
+00138 <font class="comment">// for each light, modulate the factor of influence</font>
+00139 <font class="keywordflow">for</font>(i=0; i&lt;lightList.size();i++)
+00140 {
+00141 CPointLight *pl= lightList[i].PointLight;
+00142 <font class="comment">// compute the attenuation to the pos of the tile</font>
+00143 <font class="keywordtype">float</font> att= pl-&gt;computeLinearAttenuation(tilePos);
+00144 <font class="comment">// modulate the influence with this factor</font>
+00145 lightList[i].BkupInfluence= lightList[i].Influence;
+00146 lightList[i].Influence*= att;
+00147 }
+00148 <font class="comment">// sort the light by influence</font>
+00149 sort(lightList.begin(), lightList.end());
+00150 <font class="comment">// Setup the vegetLex directly in the ig. </font>
+00151 CVegetableLightEx &amp;vegetLex= vegetIg-&gt;VegetableLightEx;
+00152 <font class="comment">// take only 2 first, computing direction to tilePos and computing attenuation.</font>
+00153 vegetLex.NumLights= <a class="code" href="bit__set_8cpp.html#a0">min</a>((uint)CVegetableLightEx::MaxNumLight, lightList.size());
+00154 <font class="keywordflow">for</font>(i=0;i&lt;vegetLex.NumLights;i++)
+00155 {
+00156 CPointLight *pl= lightList[i].PointLight;
+00157 <font class="comment">// copy to vegetLex.</font>
+00158 vegetLex.PointLight[i]= pl;
+00159 <font class="comment">// get the attenuation</font>
+00160 vegetLex.PointLightFactor[i]= (uint)(256* lightList[i].Influence);
+00161 <font class="comment">// Setup the direction from pointLight.</font>
+00162 vegetLex.Direction[i]= tilePos - pl-&gt;getPosition();
+00163 vegetLex.Direction[i].normalize();
+00164 }
+00165 <font class="comment">// compute now the current colors of the vegetLex.</font>
+00166 vegetLex.computeCurrentColors();
+00167
+00168
+00169 <font class="comment">// Compute Dynamic Lightmap UV for this tile.</font>
+00170 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>);
+00171 CUV dlmUV;
+00172 <font class="comment">// get coordinate in 0..1 in texture.</font>
+00173 dlmUV.U= <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;DLMUBias + <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;DLMUScale * tileU;
+00174 dlmUV.V= <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;DLMVBias + <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;DLMVScale * tileV;
+00175 <font class="comment">// get coordinate in 0..255.</font>
+00176 CVegetableUV8 dlmUV8;
+00177 dlmUV8.U= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(dlmUV.U * 255 + 0.5f);
+00178 dlmUV8.V= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(dlmUV.V * 255 + 0.5f);
+00179 <font class="comment">// bound them, ensuring 8Bits UV "uncompressed" by driver are in the lightmap area.</font>
+00180 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(dlmUV8.U, <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;MinU8, <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;MaxU8);
+00181 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(dlmUV8.V, <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;MinV8, <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>-&gt;MaxV8);
+00182
+00183
+00184 <font class="comment">// for all vegetable of this list, generate instances.</font>
+00185 <font class="comment">// =========================</font>
+00186
+00187 <font class="comment">// Get an array for each vegetable (static for speed).</font>
+00188 <font class="keyword">typedef</font> std::vector&lt;NLMISC::CVector2f&gt; TPositionVector;
+00189 <font class="keyword">static</font> std::vector&lt;TPositionVector&gt; instanceUVArray;
+00190 <font class="comment">// realloc if necessary.</font>
+00191 <font class="keywordflow">if</font>(instanceUVArray.size() &lt; numVegetable)
+00192 {
+00193 <font class="comment">// clean.</font>
+00194 <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(instanceUVArray);
+00195 <font class="comment">// realloc.</font>
+00196 instanceUVArray.resize(numVegetable);
+00197 }
+00198
+00199 <font class="comment">// First, for each vegetable, generate the number of instance to create, and their relative position.</font>
+00200 <font class="keywordflow">for</font>(i= 0; i&lt;numVegetable; i++)
+00201 {
+00202 <font class="comment">// get the vegetable</font>
+00203 <font class="keyword">const</font> CVegetable &amp;veget= vegetableList[i];
+00204
+00205 <font class="comment">// generate instance for this vegetable.</font>
+00206 veget.generateGroupBiLinear(tilePos, tilePosBiLinear, tileNormal, <a class="code" href="landscape__def_8h.html#a11">NL3D_PATCH_TILE_AREA</a>, i + distAddSeed, instanceUVArray[i]);
+00207 }
+00208
+00209 <font class="comment">// Then, now that we kno how many instance to generate for each vegetable, reserve space.</font>
+00210 CVegetableInstanceGroupReserve vegetIgReserve;
+00211 <font class="keywordflow">for</font>(i= 0; i&lt;numVegetable; i++)
+00212 {
+00213 <font class="comment">// get the vegetable</font>
+00214 <font class="keyword">const</font> CVegetable &amp;veget= vegetableList[i];
+00215
+00216 <font class="comment">// reseve instance space for this vegetable.</font>
+00217 <font class="comment">// instanceUVArray[i].size() is the number of instances to create.</font>
+00218 veget.reserveIgAddInstances(vegetIgReserve, (CVegetable::TVegetableWater)vegetWaterState, instanceUVArray[i].<a class="code" href="cf__lexical_8cpp.html#a94">size</a>());
+00219 }
+00220 <font class="comment">// actual reseve memory of the ig.</font>
+00221 <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;_VegetableManager-&gt;reserveIgCompile(vegetIg, vegetIgReserve);
+00222
+00223
+00224 <font class="comment">// generate the instances for all the vegetables.</font>
+00225 <font class="keywordflow">for</font>(i= 0; i&lt;numVegetable; i++)
+00226 {
+00227 <font class="comment">// get the vegetable</font>
+00228 <font class="keyword">const</font> CVegetable &amp;veget= vegetableList[i];
+00229
+00230 <font class="comment">// get the relatives position of the instances</font>
+00231 std::vector&lt;CVector2f&gt; &amp;instanceUV= instanceUVArray[i];
+00232
+00233 <font class="comment">// For all instance, generate the real instances.</font>
+00234 <font class="keywordflow">for</font>(uint j=0; j&lt;instanceUV.size(); j++)
+00235 {
+00236 <font class="comment">// generate the position in world Space.</font>
+00237 <font class="comment">// instanceUV is in [0..1] interval, which maps to a tile, so explode to the patch</font>
+00238 CVector instancePos;
+00239 vbCreateCtx.eval(ts, tt, instanceUV[j].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, instanceUV[j].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, instancePos);
+00240 <font class="comment">// NB: use same normal for rotation for all instances in a same tile.</font>
+00241 matInstance.setPos( instancePos );
+00242
+00243 <font class="comment">// peek color into the lightmap.</font>
+00244 sint lumelS= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(instanceUV[j].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> * <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>);
+00245 sint lumelT= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(instanceUV[j].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> * <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>);
+00246 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(lumelS, 0, <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>-1);
+00247 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(lumelT, 0, <a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>-1);
+00248
+00249 <font class="comment">// generate the instance of the vegetable</font>
+00250 veget.generateInstance(vegetIg, matInstance, ambientF,
+00251 diffuseColorF[ (lumelT&lt;&lt;<a class="code" href="patch_8h.html#a6">NL_LUMEL_BY_TILE_SHIFT</a>) + lumelS ],
+00252 (distType+1) * <a class="code" href="vegetable__def_8h.html#a8">NL3D_VEGETABLE_BLOCK_ELTDIST</a>, (CVegetable::TVegetableWater)vegetWaterState, dlmUV8);
+00253 }
+00254 }
+00255 }
+00256
+00257
+00258 <font class="comment">// ***************************************************************************</font>
+<a name="l00259"></a><a class="code" href="classNL3D_1_1CPatch.html#z674_1">00259</a> <font class="keywordtype">void</font> CPatch::recreateAllVegetableIgs()
+00260 {
+00261 <font class="comment">// For all TessBlocks, try to release their VegetableBlock</font>
+00262 <font class="keywordflow">for</font>(uint numtb=0; numtb&lt;<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>.size(); numtb++)
+00263 {
+00264 <font class="comment">// if the vegetableBlock is deleted, and if there is at least one Material in the tessBlock, and if possible</font>
+00265 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].VegetableBlock==NULL &amp;&amp; <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].TileMaterialRefCount&gt;0
+00266 &amp;&amp; <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;isVegetableActive())
+00267 {
+00268 <font class="comment">// compute tessBlock coordinate</font>
+00269 uint tbWidth= <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>&gt;&gt;1;
+00270 uint ts= numtb&amp;(tbWidth-1);
+00271 uint tt= numtb/tbWidth;
+00272 <font class="comment">// crate the vegetable with tilecooridante (ie tessBlock coord *2);</font>
+00273 <a class="code" href="classNL3D_1_1CPatch.html#z686_0">createVegetableBlock</a>(numtb, ts*2, tt*2);
+00274 }
+00275 }
+00276
+00277 }
+00278
+00279
+00280 <font class="comment">// ***************************************************************************</font>
+<a name="l00281"></a><a class="code" href="classNL3D_1_1CPatch.html#z674_0">00281</a> <font class="keywordtype">void</font> CPatch::deleteAllVegetableIgs()
+00282 {
+00283 <font class="comment">// For all TessBlocks, try to release their VegetableBlock</font>
+00284 <font class="keywordflow">for</font>(uint i=0; i&lt;<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>.size(); i++)
+00285 {
+00286 <a class="code" href="classNL3D_1_1CPatch.html#z686_1">releaseVegetableBlock</a>(i);
+00287 }
+00288
+00289 }
+00290
+00291
+00292 <font class="comment">// ***************************************************************************</font>
+<a name="l00293"></a><a class="code" href="classNL3D_1_1CPatch.html#z686_0">00293</a> <font class="keywordtype">void</font> CPatch::createVegetableBlock(uint numTb, uint ts, uint tt)
+00294 {
+00295 <font class="comment">// TessBlock width</font>
+00296 uint tbWidth= <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a> &gt;&gt; 1;
+00297 <font class="comment">// clipBlock width</font>
+00298 uint nTbPerCb= <a class="code" href="patch_8h.html#a13">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK</a>;
+00299 uint cbWidth= (tbWidth + nTbPerCb-1) &gt;&gt; <a class="code" href="patch_8h.html#a12">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT</a>;
+00300
+00301 <font class="comment">// compute tessBlock coordinate.</font>
+00302 uint tbs ,tbt;
+00303 tbs= ts &gt;&gt; 1;
+00304 tbt= tt &gt;&gt; 1;
+00305 <font class="comment">// compute clipBlock coordinate.</font>
+00306 uint cbs,cbt;
+00307 cbs= tbs &gt;&gt; <a class="code" href="patch_8h.html#a12">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT</a>;
+00308 cbt= tbt &gt;&gt; <a class="code" href="patch_8h.html#a12">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT</a>;
+00309
+00310 <font class="comment">// create the vegetable block.</font>
+00311 <a class="code" href="classNL3D_1_1CPatch.html#l2">CLandscapeVegetableBlock</a> *vegetBlock= <font class="keyword">new</font> <a class="code" href="classNL3D_1_1CPatch.html#l2">CLandscapeVegetableBlock</a>;
+00312 <font class="comment">// Init / append to list.</font>
+00313 <font class="comment">// compute center of the vegetableBlock (approx).</font>
+00314 CBezierPatch *bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
+00315 CVector center= bpatch-&gt;eval( (<font class="keywordtype">float</font>)(tbs*2+1)/<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>, (<font class="keywordtype">float</font>)(tbt*2+1)/<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a> );
+00316 <font class="comment">// Lower-Left tile is (tbs*2, tbt*2)</font>
+00317 vegetBlock-&gt;init(center, <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;_VegetableManager, <a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>[cbt *cbWidth + cbs], <font class="keyword">this</font>, tbs*2, tbt*2, <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;_VegetableBlockList);
+00318
+00319 <font class="comment">// set in the tessBlock</font>
+00320 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numTb].VegetableBlock= vegetBlock;
+00321 }
+00322
+00323
+00324 <font class="comment">// ***************************************************************************</font>
+<a name="l00325"></a><a class="code" href="classNL3D_1_1CPatch.html#z686_1">00325</a> <font class="keywordtype">void</font> CPatch::releaseVegetableBlock(uint numTb)
+00326 {
+00327 <font class="comment">// if exist, must delete the VegetableBlock.</font>
+00328 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numTb].VegetableBlock)
+00329 {
+00330 <font class="comment">// delete Igs, and remove from list.</font>
+00331 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numTb].VegetableBlock-&gt;release(<a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;_VegetableManager, <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()-&gt;_VegetableBlockList);
+00332 <font class="comment">// delete.</font>
+00333 <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numTb].VegetableBlock;
+00334 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numTb].VegetableBlock= NULL;
+00335 }
+00336 }
+00337
+00338
+00339
+00340
+00341
+00342 } <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>