diff options
Diffstat (limited to 'docs/doxygen/nel/3d_2zone_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/3d_2zone_8cpp-source.html | 1970 |
1 files changed, 1970 insertions, 0 deletions
diff --git a/docs/doxygen/nel/3d_2zone_8cpp-source.html b/docs/doxygen/nel/3d_2zone_8cpp-source.html new file mode 100644 index 00000000..8ee9bbfa --- /dev/null +++ b/docs/doxygen/nel/3d_2zone_8cpp-source.html @@ -0,0 +1,1970 @@ +<!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> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </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> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </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> + + +<!-- 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> </td> +</tr></table> +<!-- Generated by Doxygen 1.2.14 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <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> </center> +<hr><h1>zone.cpp</h1><a href="3d_2zone_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2000 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="src_23d_2zone_8h.html">3d/zone.h</a>"</font> +00029 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font> +00030 <font class="preprocessor">#include "<a class="code" href="zone__symmetrisation_8h.html">3d/zone_symmetrisation.h</a>"</font> +00031 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font> +00032 +00033 +00034 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00035 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00036 +00037 +00038 <font class="comment">// define it only for debug bind.</font> +00039 <font class="comment">//#define NL3D_DEBUG_DONT_BIND_PATCH</font> +00040 +00041 +00042 <font class="keyword">namespace </font>NL3D +00043 { +00044 +00045 +00046 +00047 <font class="comment">// ***************************************************************************</font> +00048 <font class="comment">// ***************************************************************************</font> +00049 <font class="comment">// CPatchInfo</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="structNL3D_1_1CPatchInfo.html#z919_0">00055</a> <font class="keywordtype">void</font> CPatchInfo::setCornerSmoothFlag(uint corner, <font class="keywordtype">bool</font> smooth) +00056 { +00057 <a class="code" href="debug_8h.html#a6">nlassert</a>(corner<=3); +00058 uint mask= 1<<corner; +00059 <font class="keywordflow">if</font>(smooth) +00060 <a class="code" href="structNL3D_1_1CPatchInfo.html#o0">_CornerSmoothFlag</a>|= mask; +00061 <font class="keywordflow">else</font> +00062 <a class="code" href="structNL3D_1_1CPatchInfo.html#o0">_CornerSmoothFlag</a>&= ~mask; +00063 } +00064 +00065 <font class="comment">// ***************************************************************************</font> +<a name="l00066"></a><a class="code" href="structNL3D_1_1CPatchInfo.html#z919_1">00066</a> <font class="keywordtype">bool</font> CPatchInfo::getCornerSmoothFlag(uint corner)<font class="keyword"> const</font> +00067 <font class="keyword"></font>{ +00068 <a class="code" href="debug_8h.html#a6">nlassert</a>(corner<=3); +00069 uint mask= 1<<corner; +00070 <font class="keywordflow">return</font> (<a class="code" href="structNL3D_1_1CPatchInfo.html#o0">_CornerSmoothFlag</a> & mask)!=0; +00071 } +00072 +00073 +00074 <font class="comment">// ***************************************************************************</font> +00075 <font class="comment">// ***************************************************************************</font> +00076 <font class="comment">// CZone</font> +00077 <font class="comment">// ***************************************************************************</font> +00078 <font class="comment">// ***************************************************************************</font> +00079 +00080 +00081 <font class="comment">// ***************************************************************************</font> +<a name="l00082"></a><a class="code" href="classNL3D_1_1CZone.html#a0">00082</a> CZone::CZone() +00083 { +00084 <a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>= 0; +00085 <a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>= <font class="keyword">false</font>; +00086 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>= NULL; +00087 <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>= <a class="code" href="classNL3D_1_1CZone.html#u5u3">ClipOut</a>; +00088 } +00089 <font class="comment">// ***************************************************************************</font> +<a name="l00090"></a><a class="code" href="classNL3D_1_1CZone.html#a1">00090</a> CZone::~CZone() +00091 { +00092 <font class="comment">// release() must have been called.</font> +00093 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +00094 } +00095 +00096 +00097 <font class="comment">// ***************************************************************************</font> +<a name="l00098"></a><a class="code" href="classNL3D_1_1CZone.html#c4">00098</a> <font class="keywordtype">void</font> CZone::computeBBScaleBias(<font class="keyword">const</font> CAABBox &bb) +00099 { +00100 <a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>= bb; +00101 <font class="comment">// Take a security for noise. (usefull for zone clipping).</font> +00102 <a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>.setHalfSize(<a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>.getHalfSize()+CVector(<a class="code" href="patch_8h.html#a11">NL3D_NOISE_MAX</a>, <a class="code" href="patch_8h.html#a11">NL3D_NOISE_MAX</a>, <a class="code" href="patch_8h.html#a11">NL3D_NOISE_MAX</a>)); +00103 CVector hs= <a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>.getHalfSize(); +00104 <font class="keywordtype">float</font> rmax= maxof(hs.x, hs.y, hs.z); +00105 <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>= rmax / 32760; <font class="comment">// Prevent from float imprecision by taking 32760 and not 32767.</font> +00106 <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>= <a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>.getCenter(); +00107 } +00108 +00109 +00110 <font class="comment">// ***************************************************************************</font> +<a name="l00111"></a><a class="code" href="classNL3D_1_1CZone.html#a3">00111</a> <font class="keywordtype">void</font> CZone::build(uint16 zoneId, <font class="keyword">const</font> std::vector<CPatchInfo> &patchs, <font class="keyword">const</font> std::vector<CBorderVertex> &borderVertices, uint32 numVertices) +00112 { +00113 CZoneInfo zinfo; +00114 zinfo.ZoneId= zoneId; +00115 zinfo.Patchs= patchs; +00116 zinfo.BorderVertices= borderVertices; +00117 +00118 <a class="code" href="classNL3D_1_1CZone.html#a2">build</a>(zinfo, numVertices); +00119 } +00120 <font class="comment">// ***************************************************************************</font> +<a name="l00121"></a><a class="code" href="classNL3D_1_1CZone.html#a2">00121</a> <font class="keywordtype">void</font> CZone::build(<font class="keyword">const</font> CZoneInfo &zoneInfo, uint32 numVertices) +00122 { +00123 sint i,j; +00124 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +00125 +00126 <font class="comment">// Ref inupt</font> +00127 uint16 zoneId= zoneInfo.ZoneId; +00128 <font class="keyword">const</font> std::vector<CPatchInfo> &patchs= zoneInfo.Patchs; +00129 <font class="keyword">const</font> std::vector<CBorderVertex> &borderVertices= zoneInfo.BorderVertices; +00130 +00131 +00132 <a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>= zoneId; +00133 <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>= borderVertices; +00134 +00135 <font class="comment">// Compute the bbox and the bias/scale.</font> +00136 <font class="comment">//=====================================</font> +00137 CAABBox bb; +00138 <font class="keywordflow">if</font>(patchs.size()) +00139 bb.setCenter(patchs[0].Patch.Vertices[0]); +00140 bb.setHalfSize(CVector::Null); +00141 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +00142 { +00143 <font class="keyword">const</font> CBezierPatch &p= patchs[j].Patch; +00144 <font class="keywordflow">for</font>(i=0;i<4;i++) +00145 bb.extend(p.Vertices[i]); +00146 <font class="keywordflow">for</font>(i=0;i<8;i++) +00147 bb.extend(p.Tangents[i]); +00148 <font class="keywordflow">for</font>(i=0;i<4;i++) +00149 bb.extend(p.Interiors[i]); +00150 } +00151 <font class="comment">// Compute BBox, and Patch Scale Bias, according to Noise.</font> +00152 <a class="code" href="classNL3D_1_1CZone.html#c4">computeBBScaleBias</a>(bb); +00153 +00154 +00155 <font class="comment">// Compute/compress Patchs.</font> +00156 <font class="comment">//=========================</font> +00157 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.resize(patchs.size()); +00158 <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>.resize(patchs.size()); +00159 sint maxVertex=-1; +00160 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +00161 { +00162 <font class="keyword">const</font> CPatchInfo &pi= patchs[j]; +00163 <font class="keyword">const</font> CBezierPatch &p= pi.Patch; +00164 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00165 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[j]; +00166 +00167 <font class="comment">// Smoothing flags</font> +00168 pa.Flags&=~<a class="code" href="patch_8h.html#a5">NL_PATCH_SMOOTH_FLAG_MASK</a>; +00169 pa.Flags|=<a class="code" href="patch_8h.html#a5">NL_PATCH_SMOOTH_FLAG_MASK</a>&(pi.Flags<<<a class="code" href="patch_8h.html#a4">NL_PATCH_SMOOTH_FLAG_SHIFT</a>); +00170 +00171 +00172 <font class="comment">// Noise Data</font> +00173 <font class="comment">// copy noise rotation.</font> +00174 pa.NoiseRotation= pi.NoiseRotation; +00175 <font class="comment">// copy all noise smoothing info.</font> +00176 <font class="keywordflow">for</font>(i=0;i<4;i++) +00177 { +00178 pa.setCornerSmoothFlag(i, pi.getCornerSmoothFlag(i)); +00179 } +00180 +00181 <font class="comment">// Copy order of the patch</font> +00182 pa.OrderS= pi.OrderS; +00183 pa.OrderT= pi.OrderT; +00184 +00185 <font class="comment">// Build the patch.</font> +00186 <font class="keywordflow">for</font>(i=0;i<4;i++) +00187 pa.Vertices[i].pack(p.Vertices[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +00188 <font class="keywordflow">for</font>(i=0;i<8;i++) +00189 pa.Tangents[i].pack(p.Tangents[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +00190 <font class="keywordflow">for</font>(i=0;i<4;i++) +00191 pa.Interiors[i].pack(p.Interiors[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +00192 pa.Tiles= pi.Tiles; +00193 pa.TileColors= pi.TileColors; +00194 <font class="comment">/* Copy TileLightInfluences. It is possible that pi.TileLightInfluences.size()!= 0</font> +00195 <font class="comment"> and pi.TileLightInfluences.size()!= (uint)(pi.OrderS/2+1)*(pi.OrderT/2+1)</font> +00196 <font class="comment"> Because of a preceding bug where pa.OrderS and pa.OrderT were not initialized before the </font> +00197 <font class="comment"> pa.resetTileLightInfluences();</font> +00198 <font class="comment"> */</font> +00199 <font class="keywordflow">if</font>( pi.TileLightInfluences.size()!= (uint)(pi.OrderS/2+1)*(pi.OrderT/2+1) ) +00200 { +00201 pa.resetTileLightInfluences(); +00202 } +00203 <font class="keywordflow">else</font> +00204 { +00205 pa.TileLightInfluences= pi.TileLightInfluences; +00206 } +00207 +00208 <font class="comment">// Number of lumels in this patch</font> +00209 uint lumelCount=(pi.OrderS*<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>)*(pi.OrderT*<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>); +00210 +00211 <font class="comment">// Lumel empty ?</font> +00212 <font class="keywordflow">if</font> (pi.Lumels.size ()==lumelCount) +00213 { +00214 <font class="comment">// Pack the lumel map</font> +00215 pa.packShadowMap (&pi.Lumels[0]); +00216 } +00217 <font class="keywordflow">else</font> +00218 { +00219 <font class="comment">// Reset lightmap</font> +00220 pa.resetCompressedLumels (); +00221 } +00222 +00223 <a class="code" href="debug_8h.html#a6">nlassert</a>(pa.Tiles.size()== (uint)pi.OrderS*pi.OrderT); +00224 <a class="code" href="debug_8h.html#a6">nlassert</a>(pa.TileColors.size()== (uint)(pi.OrderS+1)*(pi.OrderT+1)); +00225 +00226 <font class="comment">// Build the patchConnect.</font> +00227 pc.ErrorSize= pi.ErrorSize; +00228 <font class="keywordflow">for</font>(i=0;i<4;i++) +00229 { +00230 pc.BaseVertices[i]= pi.BaseVertices[i]; +00231 maxVertex= max((sint)pc.BaseVertices[i], maxVertex); +00232 } +00233 <font class="keywordflow">for</font>(i=0;i<4;i++) +00234 pc.BindEdges[i]= pi.BindEdges[i]; +00235 } +00236 +00237 <a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>= maxVertex+1; +00238 <a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>= max((uint32)<a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>, numVertices); +00239 +00240 +00241 <font class="comment">// Copy PointLights.</font> +00242 <font class="comment">//=========================</font> +00243 <font class="comment">// build array, lights are sorted</font> +00244 std::vector<uint> plRemap; +00245 <a class="code" href="classNL3D_1_1CZone.html#o11">_PointLightArray</a>.build(zoneInfo.PointLights, plRemap); +00246 <font class="comment">// Check TileLightInfluences integrity, and remap PointLight Indices.</font> +00247 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +00248 { +00249 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00250 <font class="keywordflow">for</font>(uint k= 0; k<pa.TileLightInfluences.size(); k++) +00251 { +00252 CTileLightInfluence &tli= pa.TileLightInfluences[k]; +00253 <font class="keywordflow">for</font>(uint <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>=0; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a><CTileLightInfluence::NumLightPerCorner; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>++) +00254 { +00255 <font class="comment">// If NULL light, break and continue to next TileLightInfluence.</font> +00256 <font class="keywordflow">if</font>(tli.Light[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>]== 0xFF) +00257 <font class="keywordflow">break</font>; +00258 <font class="keywordflow">else</font> +00259 { +00260 <font class="comment">// Check good index.</font> +00261 <a class="code" href="debug_8h.html#a6">nlassert</a>(tli.Light[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>] < <a class="code" href="classNL3D_1_1CZone.html#o11">_PointLightArray</a>.getPointLights().size()); +00262 <font class="comment">// Remap index, because of light sorting.</font> +00263 tli.Light[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>]= plRemap[tli.Light[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>]]; +00264 } +00265 +00266 } +00267 } +00268 } +00269 } +00270 +00271 <font class="comment">// ***************************************************************************</font> +<a name="l00272"></a><a class="code" href="classNL3D_1_1CZone.html#a6">00272</a> <font class="keywordtype">void</font> CZone::retrieve(std::vector<CPatchInfo> &patchs, std::vector<CBorderVertex> &borderVertices) +00273 { +00274 CZoneInfo zinfo; +00275 +00276 <a class="code" href="classNL3D_1_1CZone.html#a5">retrieve</a>(zinfo); +00277 +00278 patchs= zinfo.Patchs; +00279 borderVertices= zinfo.BorderVertices; +00280 } +00281 +00282 <font class="comment">// ***************************************************************************</font> +<a name="l00283"></a><a class="code" href="classNL3D_1_1CZone.html#a5">00283</a> <font class="keywordtype">void</font> CZone::retrieve(CZoneInfo &zoneInfo) +00284 { +00285 sint i,j; +00286 +00287 <font class="comment">// Ref on input.</font> +00288 std::vector<CPatchInfo> &patchs= zoneInfo.Patchs; +00289 std::vector<CBorderVertex> &borderVertices= zoneInfo.BorderVertices; +00290 <font class="comment">// Copy zoneId.</font> +00291 zoneInfo.ZoneId= <a class="code" href="classNL3D_1_1CZone.html#a26">getZoneId</a>(); +00292 +00293 +00294 <font class="comment">// uncompress Patchs.</font> +00295 <font class="comment">//=========================</font> +00296 patchs.resize(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()); +00297 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +00298 { +00299 CPatchInfo &pi= patchs[j]; +00300 CBezierPatch &p= pi.Patch; +00301 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00302 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[j]; +00303 +00304 +00305 <font class="comment">// Smoothing flags</font> +00306 pi.Flags= (pa.Flags&<a class="code" href="patch_8h.html#a5">NL_PATCH_SMOOTH_FLAG_MASK</a>)>><a class="code" href="patch_8h.html#a4">NL_PATCH_SMOOTH_FLAG_SHIFT</a>; +00307 +00308 +00309 <font class="comment">// Noise Data</font> +00310 <font class="comment">// copy noise rotation.</font> +00311 pi.NoiseRotation= pa.NoiseRotation; +00312 <font class="comment">// copy all noise smoothing info.</font> +00313 <font class="keywordflow">for</font>(i=0;i<4;i++) +00314 { +00315 pi.setCornerSmoothFlag(i, pa.getCornerSmoothFlag(i)); +00316 } +00317 +00318 +00319 <font class="comment">// re-Build the uncompressed bezier patch.</font> +00320 <font class="keywordflow">for</font>(i=0;i<4;i++) +00321 pa.Vertices[i].unpack(p.Vertices[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +00322 <font class="keywordflow">for</font>(i=0;i<8;i++) +00323 pa.Tangents[i].unpack(p.Tangents[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +00324 <font class="keywordflow">for</font>(i=0;i<4;i++) +00325 pa.Interiors[i].unpack(p.Interiors[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +00326 pi.Tiles= pa.Tiles; +00327 pi.TileColors= pa.TileColors; +00328 pi.TileLightInfluences= pa.TileLightInfluences; +00329 pi.Lumels.resize ((pa.OrderS*4)*(pa.OrderT*4)); +00330 pi.Flags=(pa.Flags&<a class="code" href="patch_8h.html#a5">NL_PATCH_SMOOTH_FLAG_MASK</a>)>><a class="code" href="patch_8h.html#a4">NL_PATCH_SMOOTH_FLAG_SHIFT</a>; +00331 +00332 <font class="comment">// Unpack the lumel map</font> +00333 pa.unpackShadowMap (&pi.Lumels[0]); +00334 +00335 <font class="comment">// from the patchConnect.</font> +00336 pi.OrderS= pa.OrderS; +00337 pi.OrderT= pa.OrderT; +00338 pi.ErrorSize= pc.ErrorSize; +00339 <font class="keywordflow">for</font>(i=0;i<4;i++) +00340 { +00341 pi.BaseVertices[i]= pc.BaseVertices[i]; +00342 } +00343 <font class="keywordflow">for</font>(i=0;i<4;i++) +00344 pi.BindEdges[i]= pc.BindEdges[i]; +00345 } +00346 +00347 <font class="comment">// retrieve bordervertices.</font> +00348 <font class="comment">//=========================</font> +00349 borderVertices= <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>; +00350 +00351 <font class="comment">// retrieve PointLights.</font> +00352 <font class="comment">//=========================</font> +00353 zoneInfo.PointLights= <a class="code" href="classNL3D_1_1CZone.html#o11">_PointLightArray</a>.getPointLights(); +00354 +00355 } +00356 +00357 +00358 <font class="comment">// ***************************************************************************</font> +<a name="l00359"></a><a class="code" href="classNL3D_1_1CZone.html#a4">00359</a> <font class="keywordtype">void</font> CZone::build(<font class="keyword">const</font> CZone &zone) +00360 { +00361 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +00362 +00363 <a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>= zone.ZoneId; +00364 <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>= zone.BorderVertices; +00365 +00366 <font class="comment">// Compute the bbox and the bias/scale.</font> +00367 <font class="comment">//=====================================</font> +00368 <a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>= zone.ZoneBB; +00369 <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>= zone.PatchScale; +00370 <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>= zone.PatchBias; +00371 +00372 +00373 <font class="comment">// Compute/compress Patchs.</font> +00374 <font class="comment">//=========================</font> +00375 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>= zone.Patchs; +00376 <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>= zone.PatchConnects; +00377 +00378 <font class="comment">// copy pointLights.</font> +00379 <font class="comment">//=========================</font> +00380 <a class="code" href="classNL3D_1_1CZone.html#o11">_PointLightArray</a>= zone._PointLightArray; +00381 +00382 +00383 <a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>= zone.NumVertices; +00384 } +00385 +00386 +00387 +00388 <font class="comment">// ***************************************************************************</font> +<a name="l00389"></a><a class="code" href="structNL3D_1_1CBorderVertex.html#a0">00389</a> <font class="keywordtype">void</font> CBorderVertex::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) +00390 { +00391 (void)f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(0); +00392 +00393 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CBorderVertex.html#m0">CurrentVertex</a>, <font class="stringliteral">"CURRENT_VERTEX"</font>); +00394 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CBorderVertex.html#m1">NeighborZoneId</a>, <font class="stringliteral">"NEIGHTBOR_ZONE_ID"</font>); +00395 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CBorderVertex.html#m2">NeighborVertex</a>, <font class="stringliteral">"NEIGHTBOR_VERTEX"</font>); +00396 } +<a name="l00397"></a><a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#a0">00397</a> <font class="keywordtype">void</font> CZone::CPatchConnect::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) +00398 { +00399 uint ver= f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(1); +00400 +00401 <font class="keywordflow">if</font> (ver<1) +00402 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m0">OldOrderS</a>, <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m1">OldOrderT</a>, <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m2">ErrorSize</a>); +00403 <font class="keywordflow">else</font> +00404 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m2">ErrorSize</a>); +00405 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m3">BaseVertices</a>[0], <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m3">BaseVertices</a>[1], <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m3">BaseVertices</a>[2], <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m3">BaseVertices</a>[3], <font class="stringliteral">"BASE_VERTICES"</font>); +00406 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m4">BindEdges</a>[0], <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m4">BindEdges</a>[1], <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m4">BindEdges</a>[2], <a class="code" href="structNL3D_1_1CZone_1_1CPatchConnect.html#m4">BindEdges</a>[3], <font class="stringliteral">"BIND_EDGES"</font>); +00407 } +<a name="l00408"></a><a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#a0">00408</a> <font class="keywordtype">void</font> CPatchInfo::CBindInfo::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) +00409 { +00410 (void)f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(0); +00411 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a>(<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m0">NPatchs</a>, <font class="stringliteral">"NPATCH"</font>); +00412 <a class="code" href="debug_8h.html#a6">nlassert</a> ( (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m0">NPatchs</a>==0) | (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m0">NPatchs</a>==1) | (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m0">NPatchs</a>==2) | (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m0">NPatchs</a>==4) | (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m0">NPatchs</a>==5) ); +00413 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m1">ZoneId</a>, <font class="stringliteral">"ZONE_ID"</font>); +00414 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m2">Next</a>[0], <a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m2">Next</a>[1], <a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m2">Next</a>[2], <a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m2">Next</a>[3], <font class="stringliteral">"NEXT_PATCH"</font>); +00415 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m3">Edge</a>[0], <a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m3">Edge</a>[1], <a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m3">Edge</a>[2], <a class="code" href="structNL3D_1_1CPatchInfo_1_1CBindInfo.html#m3">Edge</a>[3], <font class="stringliteral">"NEXT_EDGE"</font>); +00416 } +00417 +00418 <font class="comment">// ***************************************************************************</font> +<a name="l00419"></a><a class="code" href="classNL3D_1_1CZone.html#a10">00419</a> <font class="keywordtype">void</font> CZone::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) +00420 { +00421 <font class="comment">/*</font> +00422 <font class="comment"> Version 4:</font> +00423 <font class="comment"> - PointLights</font> +00424 <font class="comment"> Version 3:</font> +00425 <font class="comment"> - Lumels compression version 2.</font> +00426 <font class="comment"> Version 2:</font> +00427 <font class="comment"> - Lumels.</font> +00428 <font class="comment"> Version 1:</font> +00429 <font class="comment"> - Tile color.</font> +00430 <font class="comment"> Version 0:</font> +00431 <font class="comment"> - base verison.</font> +00432 <font class="comment"> */</font> +00433 uint ver= f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(4); +00434 +00435 <font class="comment">// No more compatibility before version 3</font> +00436 <font class="keywordflow">if</font> (ver<3) +00437 { +00438 <font class="keywordflow">throw</font> EOlderStream(f); +00439 } +00440 +00441 f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'ENOZ'); +00442 +00443 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>, <font class="stringliteral">"ZONE_ID"</font>); +00444 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>, <font class="stringliteral">"BB"</font>); +00445 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <font class="stringliteral">"PATCH_BIAS"</font>); +00446 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>, <font class="stringliteral">"PATCH_SCALE"</font>); +00447 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>, <font class="stringliteral">"NUM_VERTICES"</font>); +00448 +00449 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"BORDER_VERTICES"</font>); +00450 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>); +00451 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +00452 +00453 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"PATCHES"</font>); +00454 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>); +00455 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +00456 +00457 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"PATCH_CONNECTS"</font>); +00458 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>); +00459 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +00460 +00461 <font class="keywordflow">if</font> (ver>=4) +00462 { +00463 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"POINT_LIGHTS"</font>); +00464 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CZone.html#o11">_PointLightArray</a>); +00465 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +00466 } +00467 +00468 <font class="comment">// If read and version 0, must init default TileColors of patchs.</font> +00469 <font class="comment">//===============================================================</font> +00470 <font class="comment">// if(f.isReading() && ver<2) ... </font> +00471 <font class="comment">// Deprecated, because ver<3 not supported</font> +00472 } +00473 +00474 +00475 <font class="comment">// ***************************************************************************</font> +<a name="l00476"></a><a class="code" href="classNL3D_1_1CZone.html#a8">00476</a> <font class="keywordtype">void</font> CZone::compile(CLandscape *landscape, <a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> &loadedZones) +00477 { +00478 sint i,j; +00479 <a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> neighborZones; +00480 +00481 <font class="comment">//nlinfo("Compile Zone: %d \n", (sint32)getZoneId());</font> +00482 +00483 <font class="comment">// Can't compile if compiled.</font> +00484 <a class="code" href="debug_8h.html#a6">nlassert</a>(!<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +00485 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>= landscape; +00486 +00487 <font class="comment">// Attach this to loadedZones.</font> +00488 <font class="comment">//============================</font> +00489 <a class="code" href="debug_8h.html#a6">nlassert</a>(loadedZones.find(<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>)==loadedZones.end()); +00490 loadedZones[<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>]= <font class="keyword">this</font>; +00491 +00492 <font class="comment">// Create/link the base vertices according to present neigbor zones.</font> +00493 <font class="comment">//============================</font> +00494 <a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>.clear(); +00495 <a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>.resize(<a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>); +00496 <font class="comment">// First try to link vertices to other.</font> +00497 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>.size();i++) +00498 { +00499 sint cur= <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].CurrentVertex; +00500 sint vertto= <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].NeighborVertex; +00501 sint zoneto= <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].NeighborZoneId; +00502 <a class="code" href="debug_8h.html#a6">nlassert</a>(cur<<a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>); +00503 +00504 <font class="keywordflow">if</font>(loadedZones.find(zoneto)!=loadedZones.end()) +00505 { +00506 <a class="code" href="classNL3D_1_1CZone.html#a0">CZone</a> *zone; +00507 zone= (*loadedZones.find(zoneto)).second; +00508 <a class="code" href="debug_8h.html#a6">nlassert</a>(zone!=<font class="keyword">this</font>); +00509 <font class="comment">// insert the zone in the neigborood (if not done...).</font> +00510 neighborZones[zoneto]= zone; +00511 <font class="comment">// Doesn't matter if BaseVertices is already linked to an other zone... </font> +00512 <font class="comment">// This should be the same pointer in this case...</font> +00513 <a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[cur]= zone->getBaseVertex(vertto); +00514 } +00515 } +00516 <font class="comment">// Else, create unbounded vertices.</font> +00517 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>.size();i++) +00518 { +00519 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[i]==NULL) +00520 { +00521 <a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[i]= <font class="keyword">new</font> CTessBaseVertex; +00522 } +00523 } +00524 +00525 +00526 <font class="comment">// compile() the patchs.</font> +00527 <font class="comment">//======================</font> +00528 <font class="keywordflow">for</font>(j=0;j<(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();j++) +00529 { +00530 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00531 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[j]; +00532 CTessVertex *baseVertices[4]; +00533 +00534 baseVertices[0]= &(<a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[pc.BaseVertices[0]]->Vert); +00535 baseVertices[1]= &(<a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[pc.BaseVertices[1]]->Vert); +00536 baseVertices[2]= &(<a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[pc.BaseVertices[2]]->Vert); +00537 baseVertices[3]= &(<a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>[pc.BaseVertices[3]]->Vert); +00538 pa.compile(<font class="keyword">this</font>, j, pa.OrderS, pa.OrderT, baseVertices, pc.ErrorSize); +00539 }; +00540 +00541 <font class="comment">// bind() the patchs. (after all compiled).</font> +00542 <font class="comment">//===================</font> +00543 <font class="keywordflow">for</font>(j=0;j<(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();j++) +00544 { +00545 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00546 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[j]; +00547 +00548 <font class="comment">// bind the patch. This is the original bind, not a rebind.</font> +00549 <a class="code" href="classNL3D_1_1CZone.html#f2">bindPatch</a>(loadedZones, pa, pc, <font class="keyword">false</font>); +00550 } +00551 +00552 +00553 <font class="comment">// rebindBorder() on neighbor zones.</font> +00554 <font class="comment">//==================================</font> +00555 <a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> zoneIt; +00556 <font class="comment">// Traverse the neighborood.</font> +00557 <font class="keywordflow">for</font>(zoneIt= neighborZones.begin(); zoneIt!=neighborZones.end(); zoneIt++) +00558 { +00559 (*zoneIt).second->rebindBorder(loadedZones); +00560 } +00561 +00562 <font class="comment">// End!!</font> +00563 <a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>= <font class="keyword">true</font>; +00564 } +00565 +00566 <font class="comment">// ***************************************************************************</font> +<a name="l00567"></a><a class="code" href="classNL3D_1_1CZone.html#a9">00567</a> <font class="keywordtype">void</font> CZone::release(<a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> &loadedZones) +00568 { +00569 sint i,j; +00570 +00571 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>) +00572 <font class="keywordflow">return</font>; +00573 +00574 <font class="comment">// detach this zone to loadedZones.</font> +00575 <font class="comment">//=================================</font> +00576 <a class="code" href="debug_8h.html#a6">nlassert</a>(loadedZones.find(<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>)!=loadedZones.end()); +00577 loadedZones.erase(<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>); +00578 <font class="comment">// It doesn't server to unbindPatch(), since patch is not binded to neigbors.</font> +00579 +00580 +00581 <font class="comment">// unbind() the patchs.</font> +00582 <font class="comment">//=====================</font> +00583 <font class="keywordflow">for</font>(j=0;j<(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();j++) +00584 { +00585 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00586 <a class="code" href="classNL3D_1_1CZone.html#f1">unbindPatch</a>(pa); +00587 } +00588 +00589 +00590 <font class="comment">// rebindBorder() on neighbor zones.</font> +00591 <font class="comment">//==================================</font> +00592 <font class="comment">// Build the nieghborood.</font> +00593 <a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> neighborZones; +00594 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>.size();i++) +00595 { +00596 sint cur= <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].CurrentVertex; +00597 sint zoneto= <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].NeighborZoneId; +00598 <a class="code" href="debug_8h.html#a6">nlassert</a>(cur<<a class="code" href="classNL3D_1_1CZone.html#o6">NumVertices</a>); +00599 +00600 <font class="keywordflow">if</font>(loadedZones.find(zoneto)!=loadedZones.end()) +00601 { +00602 <a class="code" href="classNL3D_1_1CZone.html#a0">CZone</a> *zone; +00603 zone= (*loadedZones.find(zoneto)).second; +00604 <a class="code" href="debug_8h.html#a6">nlassert</a>(zone!=<font class="keyword">this</font>); +00605 <font class="comment">// insert the zone in the neigborood (if not done...).</font> +00606 neighborZones[zoneto]= zone; +00607 } +00608 } +00609 <font class="comment">// rebind borders.</font> +00610 <a class="code" href="namespaceNL3D.html#a313">ItZoneMap</a> zoneIt; +00611 <font class="comment">// Traverse the neighborood.</font> +00612 <font class="keywordflow">for</font>(zoneIt= neighborZones.begin(); zoneIt!=neighborZones.end(); zoneIt++) +00613 { +00614 <font class="comment">// Since </font> +00615 (*zoneIt).second->rebindBorder(loadedZones); +00616 } +00617 +00618 +00619 <font class="comment">// release() the patchs.</font> +00620 <font class="comment">//======================</font> +00621 <font class="comment">// unbind() need compiled neigbor patchs, so do the release after all unbind (so after rebindBorder() too...).</font> +00622 <font class="keywordflow">for</font>(j=0;j<(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();j++) +00623 { +00624 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00625 pa.release(); +00626 } +00627 +00628 +00629 <font class="comment">// destroy/unlink the base vertices (internal..), according to present neigbor zones.</font> +00630 <font class="comment">//=================================</font> +00631 <font class="comment">// Just release the smartptrs (easy!!). Do it after patchs released...</font> +00632 <a class="code" href="classNL3D_1_1CZone.html#o7">BaseVertices</a>.clear(); +00633 +00634 +00635 <font class="comment">// End!!</font> +00636 <a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>= <font class="keyword">false</font>; +00637 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>= NULL; +00638 <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>= <a class="code" href="classNL3D_1_1CZone.html#u5u3">ClipOut</a>; +00639 } +00640 +00641 +00642 <font class="comment">// ***************************************************************************</font> +00643 <font class="comment">// ***************************************************************************</font> +00644 <font class="comment">// Private part.</font> +00645 <font class="comment">// ***************************************************************************</font> +00646 <font class="comment">// ***************************************************************************</font> +00647 +00648 +00649 <font class="comment">// ***************************************************************************</font> +<a name="l00650"></a><a class="code" href="classNL3D_1_1CZone.html#c0">00650</a> <font class="keywordtype">void</font> CZone::rebindBorder(<a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> &loadedZones) +00651 { +00652 sint j; +00653 +00654 <font class="comment">// rebind patchs which are on border.</font> +00655 <font class="keywordflow">for</font>(j=0;j<(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();j++) +00656 { +00657 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +00658 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[j]; +00659 +00660 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#c3">patchOnBorder</a>(pc)) +00661 { +00662 <font class="comment">// rebind the patch. This is a rebind.</font> +00663 <a class="code" href="classNL3D_1_1CZone.html#f2">bindPatch</a>(loadedZones, pa, pc, <font class="keyword">true</font>); +00664 } +00665 } +00666 } +00667 +00668 <font class="comment">// ***************************************************************************</font> +<a name="l00669"></a><a class="code" href="classNL3D_1_1CZone.html#f0">00669</a> CPatch *CZone::getZonePatch(<a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> &loadedZones, sint zoneId, sint patch) +00670 { +00671 <font class="preprocessor">#ifdef NL3D_DEBUG_DONT_BIND_PATCH</font> +00672 <font class="preprocessor"></font> <font class="keywordflow">return</font> NULL; +00673 <font class="preprocessor">#endif</font> +00674 <font class="preprocessor"></font> <font class="keywordflow">if</font>(loadedZones.find(zoneId)==loadedZones.end()) +00675 <font class="keywordflow">return</font> NULL; +00676 <font class="keywordflow">else</font> +00677 <font class="keywordflow">return</font> (loadedZones[zoneId])->getPatch(patch); +00678 } +00679 +00680 +00681 <font class="comment">// ***************************************************************************</font> +<a name="l00682"></a><a class="code" href="classNL3D_1_1CZone.html#c5">00682</a> <font class="keywordtype">void</font> CZone::buildBindInfo(uint patchId, uint edge, CZone *neighborZone, CPatch::CBindInfo &paBind) +00683 { +00684 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId < <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()); +00685 <a class="code" href="debug_8h.html#a6">nlassert</a>(neighborZone); +00686 +00687 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[patchId]; +00688 +00689 +00690 <font class="comment">// Get the bind info of this patch to his neighbor on "edge".</font> +00691 CPatchInfo::CBindInfo &pcBind= pc.BindEdges[edge]; +00692 <a class="code" href="debug_8h.html#a6">nlassert</a>(pcBind.NPatchs==0 || pcBind.NPatchs==1 || pcBind.NPatchs==2 || pcBind.NPatchs==4 || pcBind.NPatchs==5); +00693 +00694 +00695 <font class="comment">// copy zone ptr.</font> +00696 paBind.Zone= neighborZone; +00697 +00698 +00699 <font class="comment">// Special case of a small patch connected to a bigger.</font> +00700 <font class="keywordflow">if</font>(pcBind.NPatchs==5) +00701 { +00702 paBind.NPatchs= 1; +00703 paBind.Next[0]= neighborZone->getPatch(pcBind.Next[0]); +00704 paBind.Edge[0]= pcBind.Edge[0]; +00705 +00706 <font class="comment">// Get the twin bindInfo of pcBind.</font> +00707 <font class="keyword">const</font> CPatchInfo::CBindInfo &pcBindNeighbor= +00708 neighborZone->getPatchConnect(pcBind.Next[0])->BindEdges[pcBind.Edge[0]]; +00709 <font class="comment">// must have a multiple bind. </font> +00710 <a class="code" href="debug_8h.html#a6">nlassert</a>(pcBindNeighbor.NPatchs == 2 || pcBindNeighbor.NPatchs == 4); +00711 +00712 <font class="comment">// number of bind is stored on the twin bindInfo.</font> +00713 paBind.MultipleBindNum= pcBindNeighbor.NPatchs; +00714 +00715 <font class="comment">// Search our patchId on neighbor;</font> +00716 paBind.MultipleBindId= 255; +00717 <font class="keywordflow">for</font>(sint i=0; i<paBind.MultipleBindNum; i++) +00718 { +00719 <font class="keywordflow">if</font>(pcBindNeighbor.Next[i]==patchId) +00720 paBind.MultipleBindId= i; +00721 } +00722 <a class="code" href="debug_8h.html#a6">nlassert</a>(paBind.MultipleBindId!= 255); +00723 } +00724 <font class="keywordflow">else</font> +00725 { +00726 paBind.MultipleBindNum= 0; +00727 paBind.NPatchs= pcBind.NPatchs; +00728 <font class="keywordflow">for</font>(sint i=0;i<paBind.NPatchs; i++) +00729 { +00730 paBind.Next[i]= neighborZone->getPatch(pcBind.Next[i]); +00731 paBind.Edge[i]= pcBind.Edge[i]; +00732 } +00733 } +00734 +00735 +00736 } +00737 +00738 +00739 <font class="comment">// ***************************************************************************</font> +<a name="l00740"></a><a class="code" href="classNL3D_1_1CZone.html#f2">00740</a> <font class="keywordtype">void</font> CZone::bindPatch(<a class="code" href="namespaceNL3D.html#a312">TZoneMap</a> &loadedZones, CPatch &pa, CPatchConnect &pc, <font class="keywordtype">bool</font> rebind) +00741 { +00742 CPatch::CBindInfo edges[4]; +00743 +00744 <font class="comment">// Fill all edges.</font> +00745 <font class="keywordflow">for</font>(sint i=0;i<4;i++) +00746 { +00747 CPatchInfo::CBindInfo &pcBind= pc.BindEdges[i]; +00748 CPatch::CBindInfo &paBind= edges[i]; +00749 +00750 <a class="code" href="debug_8h.html#a6">nlassert</a>(pcBind.NPatchs==0 || pcBind.NPatchs==1 || pcBind.NPatchs==2 || pcBind.NPatchs==4 || pcBind.NPatchs==5); +00751 paBind.NPatchs= pcBind.NPatchs; +00752 +00753 +00754 <font class="comment">// Find the zone.</font> +00755 TZoneMap::iterator itZoneMap; +00756 <font class="comment">// If no neighbor, or if zone neighbor not loaded.</font> +00757 <font class="keywordflow">if</font>( paBind.NPatchs==0 || (itZoneMap=loadedZones.find(pcBind.ZoneId)) == loadedZones.end() ) +00758 paBind.Zone= NULL; +00759 <font class="keywordflow">else</font> +00760 paBind.Zone= itZoneMap->second; +00761 +00762 +00763 <font class="comment">// Special case of a small patch connected to a bigger.</font> +00764 <font class="keywordflow">if</font>(paBind.NPatchs==5) +00765 { +00766 paBind.Edge[0]= pcBind.Edge[0]; +00767 paBind.Next[0]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[0]); +00768 <font class="comment">// If not loaded, don't bind to this edge.</font> +00769 <font class="keywordflow">if</font>(!paBind.Next[0]) +00770 paBind.NPatchs=0; +00771 <font class="keywordflow">else</font> +00772 { +00773 <font class="comment">// Get the BindInfo on me stored in our neighbor bigger CPatch</font> +00774 CPatch::CBindInfo nbOnMe; +00775 paBind.Next[0]->getBindNeighbor(paBind.Edge[0], nbOnMe); +00776 <font class="comment">// if this patch has not already been binded on me, nbOnMe.Zone==NULL</font> +00777 <font class="keywordflow">if</font>( nbOnMe.Zone == NULL ) +00778 { +00779 <font class="comment">// Simple case: do nothing: don't need to rebind() to the bigger patch since </font> +00780 <font class="comment">// himself is not bound</font> +00781 paBind.NPatchs=0; +00782 paBind.Zone= NULL; +00783 } +00784 <font class="keywordflow">else</font> +00785 { +00786 <font class="comment">// pa.bind() will do the job.</font> +00787 <font class="comment">// Leave it flagged with NPatchs==5.</font> +00788 <font class="keywordflow">continue</font>; +00789 } +00790 } +00791 } +00792 +00793 +00794 <font class="comment">// Bind 1/1 and 1/2,1/4</font> +00795 <font class="keywordflow">if</font>(paBind.NPatchs>=1) +00796 { +00797 paBind.Edge[0]= pcBind.Edge[0]; +00798 paBind.Next[0]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[0]); +00799 <font class="comment">// If not loaded, don't bind to this edge.</font> +00800 <font class="keywordflow">if</font>(!paBind.Next[0]) +00801 paBind.NPatchs=0; +00802 } +00803 <font class="keywordflow">if</font>(paBind.NPatchs>=2) +00804 { +00805 paBind.Edge[1]= pcBind.Edge[1]; +00806 paBind.Next[1]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[1]); +00807 <font class="comment">// If not loaded, don't bind to this edge.</font> +00808 <font class="keywordflow">if</font>(!paBind.Next[1]) +00809 paBind.NPatchs=0; +00810 } +00811 <font class="keywordflow">if</font>(paBind.NPatchs>=4) +00812 { +00813 paBind.Edge[2]= pcBind.Edge[2]; +00814 paBind.Edge[3]= pcBind.Edge[3]; +00815 paBind.Next[2]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[2]); +00816 paBind.Next[3]= CZone::getZonePatch(loadedZones, pcBind.ZoneId, pcBind.Next[3]); +00817 <font class="comment">// If not loaded, don't bind to this edge.</font> +00818 <font class="keywordflow">if</font>(!paBind.Next[2] || !paBind.Next[3]) +00819 paBind.NPatchs=0; +00820 } +00821 } +00822 +00823 <font class="comment">// First, unbind.</font> +00824 pa.unbind(); +00825 +00826 <font class="comment">// Then bind.</font> +00827 pa.bind(edges, rebind); +00828 } +00829 +00830 +00831 <font class="comment">// ***************************************************************************</font> +<a name="l00832"></a><a class="code" href="classNL3D_1_1CZone.html#f1">00832</a> <font class="keywordtype">void</font> CZone::unbindPatch(CPatch &pa) +00833 { +00834 <font class="comment">/*</font> +00835 <font class="comment"> Remind: the old version with CPatch::unbindFrom*() doesn't work because of CZone::release(). This function</font> +00836 <font class="comment"> first erase the zone from loadedZones...</font> +00837 <font class="comment"> Not matter here. We use CPatch::unbind() which should do all the good job correctly (unbind pa from ohters</font> +00838 <font class="comment"> , and unbind others from pa at same time).</font> +00839 <font class="comment"> */</font> +00840 +00841 pa.unbind(); +00842 } +00843 +00844 +00845 <font class="comment">// ***************************************************************************</font> +<a name="l00846"></a><a class="code" href="classNL3D_1_1CZone.html#c3">00846</a> <font class="keywordtype">bool</font> CZone::patchOnBorder(<font class="keyword">const</font> CPatchConnect &pc)<font class="keyword"> const</font> +00847 <font class="keyword"></font>{ +00848 <font class="comment">// If only one of neighbor patch is not of this zone, we are on a border.</font> +00849 +00850 <font class="comment">// Test all edges.</font> +00851 <font class="keywordflow">for</font>(sint i=0;i<4;i++) +00852 { +00853 <font class="keyword">const</font> CPatchInfo::CBindInfo &pcBind= pc.BindEdges[i]; +00854 +00855 <a class="code" href="debug_8h.html#a6">nlassert</a>(pcBind.NPatchs==0 || pcBind.NPatchs==1 || pcBind.NPatchs==2 || pcBind.NPatchs==4 || pcBind.NPatchs==5); +00856 <font class="keywordflow">if</font>(pcBind.NPatchs>=1) +00857 { +00858 <font class="keywordflow">if</font>(pcBind.ZoneId != <a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>) +00859 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00860 } +00861 } +00862 +00863 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00864 } +00865 +00866 +00867 <font class="comment">// ***************************************************************************</font> +00868 <font class="comment">// ***************************************************************************</font> +00869 <font class="comment">// Render part.</font> +00870 <font class="comment">// ***************************************************************************</font> +00871 <font class="comment">// ***************************************************************************</font> +00872 +00873 +00874 <font class="comment">// ***************************************************************************</font> +<a name="l00875"></a><a class="code" href="classNL3D_1_1CZone.html#a16">00875</a> <font class="keywordtype">void</font> CZone::clip(<font class="keyword">const</font> std::vector<CPlane> &pyramid) +00876 { +00877 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +00878 +00879 <font class="comment">// bkup old ClipResult. NB: by default, it is ClipOut (no VB created).</font> +00880 sint oldClipResult= <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>; +00881 +00882 <font class="comment">// Compute ClipResult.</font> +00883 <font class="comment">//-------------------</font> +00884 <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>= <a class="code" href="classNL3D_1_1CZone.html#u5u2">ClipIn</a>; +00885 <font class="keywordflow">for</font>(sint i=0;i<(sint)pyramid.size();i++) +00886 { +00887 <font class="comment">// If entirely out.</font> +00888 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>.clipBack(pyramid[i])) +00889 { +00890 <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>= <a class="code" href="classNL3D_1_1CZone.html#u5u3">ClipOut</a>; +00891 <font class="comment">// If out of only one plane, out of all.</font> +00892 <font class="keywordflow">break</font>; +00893 } +00894 <font class="comment">// If partially IN (ie not entirely out, and not entirely IN)</font> +00895 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o3">ZoneBB</a>.clipFront(pyramid[i])) +00896 { +00897 <font class="comment">// Force ClipResult to be ClipSide, and not ClipIn.</font> +00898 <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>=<a class="code" href="classNL3D_1_1CZone.html#u5u4">ClipSide</a>; +00899 } +00900 } +00901 +00902 +00903 <font class="comment">// Easy Clip :)</font> +00904 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()==0) +00905 { +00906 <a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>= <a class="code" href="classNL3D_1_1CZone.html#u5u3">ClipOut</a>; +00907 <font class="comment">// don't need to go below...</font> +00908 <font class="keywordflow">return</font>; +00909 } +00910 +00911 +00912 <font class="comment">// Clip By Patch Pass.</font> +00913 <font class="comment">//--------------------</font> +00914 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>==<a class="code" href="classNL3D_1_1CZone.html#u5u3">ClipOut</a>) +00915 { +00916 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +00917 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +00918 { +00919 <font class="comment">// The patch is entirely clipped, and so on for Render.</font> +00920 pPatch->forceClip(); +00921 pPatch->forceRenderClip(); +00922 } +00923 } +00924 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>==<a class="code" href="classNL3D_1_1CZone.html#u5u2">ClipIn</a>) +00925 { +00926 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +00927 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +00928 { +00929 <font class="comment">// The patch is entirely unclipped, and so on for Render.</font> +00930 pPatch->forceNoClip(); +00931 pPatch->forceNoRenderClip(); +00932 } +00933 } +00934 <font class="keywordflow">else</font> +00935 { +00936 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +00937 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +00938 { +00939 pPatch->clip(pyramid); +00940 } +00941 } +00942 +00943 +00944 <font class="comment">// delete / reallocate / fill VBuffers.</font> +00945 <font class="comment">//-------------------</font> +00946 <font class="comment">// If there is a change in the Clip of the zone, or if patchs may have change (ie ClipSide is undetermined).</font> +00947 <font class="keywordflow">if</font>(oldClipResult!=<a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a> || oldClipResult==<a class="code" href="classNL3D_1_1CZone.html#u5u4">ClipSide</a>) +00948 { +00949 <font class="comment">// Then, we must test by patch.</font> +00950 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +00951 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +00952 { +00953 <font class="comment">// For all patchs, we may delete or allocate / Fill VBs.</font> +00954 pPatch->updateClipPatchVB(); +00955 } +00956 +00957 } +00958 +00959 } +00960 +00961 +00962 <font class="comment">// ***************************************************************************</font> +00963 <font class="comment">// DebugYoyo.</font> +00964 <font class="comment">// Code for Debug test Only.. Do not erase it, may be used later :)</font> +00965 <font class="comment">/*</font> +00966 <font class="comment">static void cleanTess(CTessFace *face)</font> +00967 <font class="comment">{</font> +00968 <font class="comment"> if(!face->isLeaf())</font> +00969 <font class="comment"> {</font> +00970 <font class="comment"> cleanTess(face->SonLeft);</font> +00971 <font class="comment"> cleanTess(face->SonRight);</font> +00972 <font class="comment"> }</font> +00973 <font class="comment"> // If has father, clean it.</font> +00974 <font class="comment"> if(face->Father)</font> +00975 <font class="comment"> {</font> +00976 <font class="comment"> CTessFace *face1=face->Father;</font> +00977 <font class="comment"> CTessFace *face2=face->Father->FBase;</font> +00978 <font class="comment"> face1->FLeft= face1->SonLeft->FBase;</font> +00979 <font class="comment"> face1->FRight= face1->SonRight->FBase;</font> +00980 <font class="comment"> if(face2!=NULL)</font> +00981 <font class="comment"> {</font> +00982 <font class="comment"> face2->FLeft= face2->SonLeft->FBase;</font> +00983 <font class="comment"> face2->FRight= face2->SonRight->FBase;</font> +00984 <font class="comment"> }</font> +00985 <font class="comment"> }</font> +00986 <font class="comment">}</font> +00987 <font class="comment">static void testTess(CTessFace *face)</font> +00988 <font class="comment">{</font> +00989 <font class="comment"> if(!face->isLeaf())</font> +00990 <font class="comment"> {</font> +00991 <font class="comment"> testTess(face->SonLeft);</font> +00992 <font class="comment"> testTess(face->SonRight);</font> +00993 <font class="comment"> }</font> +00994 <font class="comment"> // Test validity.</font> +00995 <font class="comment"> nlassert(!face->FBase || face->FBase->Patch!=(CPatch*)0xdddddddd);</font> +00996 <font class="comment"> nlassert(!face->FLeft || face->FLeft->Patch!=(CPatch*)0xdddddddd);</font> +00997 <font class="comment"> nlassert(!face->FRight || face->FRight->Patch!=(CPatch*)0xdddddddd);</font> +00998 <font class="comment">}</font> +00999 <font class="comment">static void checkTess()</font> +01000 <font class="comment">{</font> +01001 <font class="comment"> // This test should be inserted at begin of CZone::refine().</font> +01002 <font class="comment"> // And it needs hacking public/private.</font> +01003 <font class="comment"> CPatch *pPatch;</font> +01004 <font class="comment"> sint n;</font> +01005 <font class="comment"> pPatch= &(*Patchs.begin());</font> +01006 <font class="comment"> for(n=(sint)Patchs.size();n>0;n--, pPatch++)</font> +01007 <font class="comment"> {</font> +01008 <font class="comment"> cleanTess(pPatch->Son0);</font> +01009 <font class="comment"> cleanTess(pPatch->Son1);</font> +01010 <font class="comment"> }</font> +01011 <font class="comment"> pPatch= &(*Patchs.begin());</font> +01012 <font class="comment"> for(n=(sint)Patchs.size();n>0;n--, pPatch++)</font> +01013 <font class="comment"> {</font> +01014 <font class="comment"> testTess(pPatch->Son0);</font> +01015 <font class="comment"> testTess(pPatch->Son1);</font> +01016 <font class="comment"> }</font> +01017 <font class="comment">}</font> +01018 <font class="comment">*/</font> +01019 +01020 +01021 <font class="comment">// ***************************************************************************</font> +<a name="l01022"></a><a class="code" href="classNL3D_1_1CZone.html#a21">01022</a> <font class="keywordtype">void</font> CZone::excludePatchFromRefineAll(uint patch, <font class="keywordtype">bool</font> exclude) +01023 { +01024 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +01025 <a class="code" href="debug_8h.html#a6">nlassert</a>(patch<<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()); +01026 +01027 <font class="keywordflow">if</font>(patch>=<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()) +01028 <font class="keywordflow">return</font>; +01029 +01030 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[patch].ExcludeFromRefineAll= exclude; +01031 } +01032 +01033 +01034 <font class="comment">// ***************************************************************************</font> +<a name="l01035"></a><a class="code" href="classNL3D_1_1CZone.html#a20">01035</a> <font class="keywordtype">void</font> CZone::refineAll() +01036 { +01037 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +01038 +01039 <font class="comment">// Fuck stlport....</font> +01040 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()==0) +01041 <font class="keywordflow">return</font>; +01042 +01043 <font class="comment">// Do a dummy clip.</font> +01044 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01045 sint n; +01046 <font class="keywordflow">for</font>(n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01047 { +01048 pPatch->forceNoClip(); +01049 <font class="comment">// DO NOT do a forceNoRenderClip(), to avoid big allocation of Near/Far VB vertices in driver.</font> +01050 } +01051 <font class="comment">// DO NOT modify ClipResult, to avoid big allocation of Near/Far VB vertices in driver.</font> +01052 +01053 +01054 <font class="comment">// refine ALL patchs (even those which may be invisible).</font> +01055 pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01056 <font class="keywordflow">for</font>(n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01057 { +01058 <font class="comment">// For Pacs construction: may exclude some patch from refineAll (for speed improvement).</font> +01059 <font class="keywordflow">if</font>(!pPatch->ExcludeFromRefineAll) +01060 pPatch->refineAll(); +01061 } +01062 +01063 } +01064 +01065 +01066 <font class="comment">// ***************************************************************************</font> +<a name="l01067"></a><a class="code" href="classNL3D_1_1CZone.html#a22">01067</a> <font class="keywordtype">void</font> CZone::averageTesselationVertices() +01068 { +01069 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +01070 +01071 <font class="comment">// Fuck stlport....</font> +01072 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()==0) +01073 <font class="keywordflow">return</font>; +01074 +01075 <font class="comment">// averageTesselationVertices of ALL patchs.</font> +01076 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01077 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01078 { +01079 pPatch->averageTesselationVertices(); +01080 } +01081 } +01082 +01083 +01084 <font class="comment">// ***************************************************************************</font> +<a name="l01085"></a><a class="code" href="classNL3D_1_1CZone.html#a17">01085</a> <font class="keywordtype">void</font> CZone::preRender() +01086 { +01087 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +01088 +01089 <font class="comment">// Must be 2^X-1.</font> +01090 <font class="keyword">static</font> <font class="keyword">const</font> sint updateFarRefineFreq= 15; +01091 <font class="comment">// Take the renderDate here.</font> +01092 sint curDateMod= CLandscapeGlobals::CurrentRenderDate & updateFarRefineFreq; +01093 +01094 <font class="comment">// If no patchs, do nothing.</font> +01095 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.empty()) +01096 <font class="keywordflow">return</font>; +01097 +01098 <font class="comment">/* If patchs invisible, must still update their Far Textures,</font> +01099 <font class="comment"> else, there may be slowdown when we turn the head.</font> +01100 <font class="comment"> */</font> +01101 +01102 +01103 <font class="comment">// If all the zone is invisible.</font> +01104 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>==<a class="code" href="classNL3D_1_1CZone.html#u5u3">ClipOut</a>) +01105 { +01106 <font class="comment">// No patchs are visible, but maybe update the far textures.</font> +01107 <font class="keywordflow">if</font>( curDateMod==(<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a> & updateFarRefineFreq) ) +01108 { +01109 <font class="comment">// updateTextureFarOnly for all patchs.</font> +01110 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01111 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01112 pPatch->updateTextureFarOnly(); +01113 } +01114 } +01115 <font class="comment">// else If some patchs only are visible.</font> +01116 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o12">ClipResult</a>==<a class="code" href="classNL3D_1_1CZone.html#u5u4">ClipSide</a>) +01117 { +01118 <font class="comment">// PreRender Pass, or updateTextureFarOnly(), according to RenderClipped state.</font> +01119 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01120 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01121 { +01122 <font class="comment">// If the patch is visible</font> +01123 <font class="keywordflow">if</font>(!pPatch->isRenderClipped()) +01124 { +01125 <font class="comment">// Then preRender it.</font> +01126 pPatch->preRender(); +01127 } +01128 <font class="keywordflow">else</font> +01129 { +01130 <font class="comment">// else maybe updateFar it.</font> +01131 <font class="comment">// ZoneId+n for better repartition.</font> +01132 <font class="keywordflow">if</font>( curDateMod==((<a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>+n) & updateFarRefineFreq) ) +01133 pPatch->updateTextureFarOnly(); +01134 } +01135 } +01136 } +01137 <font class="keywordflow">else</font> <font class="comment">// ClipResult==ClipIn</font> +01138 { +01139 <font class="comment">// PreRender Pass for All</font> +01140 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01141 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01142 pPatch->preRender(); +01143 } +01144 +01145 } +01146 +01147 +01148 <font class="comment">// ***************************************************************************</font> +<a name="l01149"></a><a class="code" href="classNL3D_1_1CZone.html#a18">01149</a> <font class="keywordtype">void</font> CZone::resetRenderFarAndDeleteVBFV() +01150 { +01151 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch=0; +01152 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()>0) +01153 pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01154 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01155 { +01156 <font class="comment">// If patch is visible</font> +01157 <font class="keywordflow">if</font>(!pPatch->RenderClipped) +01158 { +01159 <font class="comment">// release VertexBuffer, and FaceBuffer</font> +01160 pPatch->deleteVBAndFaceVector(); +01161 <font class="comment">// Flag.</font> +01162 pPatch->RenderClipped= <font class="keyword">true</font>; +01163 } +01164 +01165 pPatch->resetRenderFar(); +01166 } +01167 } +01168 +01169 +01170 <font class="comment">// ***************************************************************************</font> +<a name="l01171"></a><a class="code" href="classNL3D_1_1CZone.html#a19">01171</a> <font class="keywordtype">void</font> CZone::forceMergeAtTileLevel() +01172 { +01173 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *pPatch=0; +01174 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()>0) +01175 pPatch= &(*<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.begin()); +01176 <font class="keywordflow">for</font>(sint n=(sint)<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size();n>0;n--, pPatch++) +01177 { +01178 pPatch->forceMergeAtTileLevel(); +01179 } +01180 } +01181 +01182 +01183 <font class="comment">// ***************************************************************************</font> +01184 <font class="comment">// ***************************************************************************</font> +01185 <font class="comment">// Misc part.</font> +01186 <font class="comment">// ***************************************************************************</font> +01187 <font class="comment">// ***************************************************************************</font> +01188 +01189 +01190 <font class="comment">// ***************************************************************************</font> +<a name="l01191"></a><a class="code" href="classNL3D_1_1CZone.html#a11">01191</a> <font class="keywordtype">void</font> CZone::changePatchTextureAndColor (sint numPatch, <font class="keyword">const</font> std::vector<CTileElement> *tiles, <font class="keyword">const</font> std::vector<CTileColor> *colors) +01192 { +01193 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch>=0); +01194 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch<<a class="code" href="classNL3D_1_1CZone.html#a27">getNumPatchs</a>()); +01195 +01196 +01197 <font class="comment">// Update the patch texture.</font> +01198 <font class="keywordflow">if</font> (tiles) +01199 { +01200 <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].Tiles.size() == tiles->size() ); +01201 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].Tiles = *tiles; +01202 } +01203 +01204 <font class="comment">// Update the patch colors.</font> +01205 <font class="keywordflow">if</font> (colors) +01206 { +01207 <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].TileColors.size() == colors->size() ); +01208 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].TileColors = *colors; +01209 } +01210 +01211 <font class="keywordflow">if</font> (Compiled) +01212 { +01213 <font class="comment">// If the patch is visible, then we must LockBuffers, because new VertexVB may be created.</font> +01214 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].RenderClipped) +01215 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>->updateGlobalsAndLockBuffers(CVector::Null); +01216 +01217 <font class="comment">// Recompute UVs for new setup of Tiles.</font> +01218 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].deleteTileUvs(); +01219 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].recreateTileUvs(); +01220 +01221 <font class="comment">// unlockBuffers() if necessary.</font> +01222 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].RenderClipped) +01223 { +01224 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>->unlockBuffers(); +01225 <font class="comment">// This patch is visible, and TileFaces have been deleted / added.</font> +01226 <font class="comment">// So must update TessBlock.</font> +01227 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>->updateTessBlocksFaceVector(); +01228 } +01229 } +01230 } +01231 +01232 +01233 <font class="comment">// ***************************************************************************</font> +<a name="l01234"></a><a class="code" href="classNL3D_1_1CZone.html#a12">01234</a> <font class="keywordtype">void</font> CZone::refreshTesselationGeometry(sint numPatch) +01235 { +01236 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch>=0); +01237 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch<<a class="code" href="classNL3D_1_1CZone.html#a27">getNumPatchs</a>()); +01238 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZone.html#o2">Compiled</a>); +01239 +01240 <font class="comment">// At next render, we must re-fill the entire unclipped VB, so change are taken into account.</font> +01241 <a class="code" href="classNL3D_1_1CZone.html#o0">Landscape</a>->_RenderMustRefillVB= <font class="keyword">true</font>; +01242 +01243 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].refreshTesselationGeometry(); +01244 } +01245 +01246 +01247 <font class="comment">// ***************************************************************************</font> +<a name="l01248"></a><a class="code" href="classNL3D_1_1CZone.html#a13">01248</a> <font class="keyword">const</font> std::vector<CTileElement> &CZone::getPatchTexture(sint numPatch)<font class="keyword"> const</font> +01249 <font class="keyword"></font>{ +01250 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch>=0); +01251 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch<<a class="code" href="classNL3D_1_1CZone.html#a27">getNumPatchs</a>()); +01252 +01253 <font class="comment">// Update the patch texture.</font> +01254 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].Tiles; +01255 } +01256 +01257 +01258 <font class="comment">// ***************************************************************************</font> +<a name="l01259"></a><a class="code" href="classNL3D_1_1CZone.html#a14">01259</a> <font class="keyword">const</font> std::vector<CTileColor> &CZone::getPatchColor(sint numPatch)<font class="keyword"> const</font> +01260 <font class="keyword"></font>{ +01261 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch>=0); +01262 <a class="code" href="debug_8h.html#a6">nlassert</a>(numPatch<<a class="code" href="classNL3D_1_1CZone.html#a27">getNumPatchs</a>()); +01263 +01264 <font class="comment">// Update the patch texture.</font> +01265 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[numPatch].TileColors; +01266 } +01267 +01268 +01269 <font class="comment">// ***************************************************************************</font> +<a name="l01270"></a><a class="code" href="classNL3D_1_1CZone.html#a7">01270</a> <font class="keywordtype">void</font> CZone::debugBinds(FILE *f) +01271 { +01272 fprintf(f, <font class="stringliteral">"*****************************\n"</font>); +01273 fprintf(f, <font class="stringliteral">"ZoneId: %d. NPatchs:%d\n"</font>, <a class="code" href="classNL3D_1_1CZone.html#o1">ZoneId</a>, <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>.size()); +01274 sint i; +01275 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>.size();i++) +01276 { +01277 CPatchConnect &pc= <a class="code" href="classNL3D_1_1CZone.html#o10">PatchConnects</a>[i]; +01278 fprintf(f, <font class="stringliteral">"patch%d:\n"</font>, i); +01279 <font class="keywordflow">for</font>(sint j=0;j<4;j++) +01280 { +01281 CPatchInfo::CBindInfo &bd= pc.BindEdges[j]; +01282 fprintf(f, <font class="stringliteral">" edge%d: Zone:%d. NPatchs:%d. "</font>, j, bd.ZoneId, bd.NPatchs); +01283 <font class="keywordflow">for</font>(sint k=0;k<bd.NPatchs;k++) +01284 { +01285 fprintf(f, <font class="stringliteral">"p%de%d - "</font>, bd.Next[k], bd.Edge[k]); +01286 } +01287 fprintf(f, <font class="stringliteral">"\n"</font>); +01288 } +01289 } +01290 +01291 fprintf(f,<font class="stringliteral">"Vertices :\n"</font>); +01292 <font class="keywordflow">for</font>(i=0;i<(sint)<a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>.size();i++) +01293 { +01294 fprintf(f,<font class="stringliteral">"current : %d -> (zone %d) vertex %d\n"</font>,<a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].CurrentVertex, +01295 <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].NeighborZoneId, +01296 <a class="code" href="classNL3D_1_1CZone.html#o8">BorderVertices</a>[i].NeighborVertex); +01297 } +01298 } +01299 +01300 +01301 <font class="comment">// ***************************************************************************</font> +<a name="l01302"></a><a class="code" href="classNL3D_1_1CZone.html#a31">01302</a> <font class="keywordtype">void</font> CZone::applyHeightField(<font class="keyword">const</font> CLandscape &landScape) +01303 { +01304 sint i,j; +01305 vector<CBezierPatch> patchs; +01306 +01307 <font class="comment">// no patch, do nothing.</font> +01308 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()==0) +01309 <font class="keywordflow">return</font>; +01310 +01311 <font class="comment">// 0. Unpack patchs to Bezier Patchs.</font> +01312 <font class="comment">//===================================</font> +01313 patchs.resize(<a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size()); +01314 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +01315 { +01316 CBezierPatch &p= patchs[j]; +01317 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +01318 +01319 <font class="comment">// re-Build the uncompressed bezier patch.</font> +01320 <font class="keywordflow">for</font>(i=0;i<4;i++) +01321 pa.Vertices[i].unpack(p.Vertices[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +01322 <font class="keywordflow">for</font>(i=0;i<8;i++) +01323 pa.Tangents[i].unpack(p.Tangents[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +01324 <font class="keywordflow">for</font>(i=0;i<4;i++) +01325 pa.Interiors[i].unpack(p.Interiors[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +01326 } +01327 +01328 <font class="comment">// 1. apply heightfield on bezier patchs.</font> +01329 <font class="comment">//===================================</font> +01330 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +01331 { +01332 CBezierPatch &p= patchs[j]; +01333 +01334 <font class="comment">// apply delta.</font> +01335 <font class="keywordflow">for</font>(i=0;i<4;i++) +01336 p.Vertices[i]+= landScape.getHeightFieldDeltaZ(p.Vertices[i].x, p.Vertices[i].y); +01337 <font class="keywordflow">for</font>(i=0;i<8;i++) +01338 p.Tangents[i]+= landScape.getHeightFieldDeltaZ(p.Tangents[i].x, p.Tangents[i].y); +01339 <font class="keywordflow">for</font>(i=0;i<4;i++) +01340 p.Interiors[i]+= landScape.getHeightFieldDeltaZ(p.Interiors[i].x, p.Interiors[i].y); +01341 } +01342 +01343 +01344 <font class="comment">// 2. Re-compute Patch Scale/Bias, and Zone BBox.</font> +01345 <font class="comment">//===================================</font> +01346 CAABBox bb; +01347 bb.setCenter(patchs[0].Vertices[0]); +01348 bb.setHalfSize(CVector::Null); +01349 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +01350 { +01351 <font class="comment">// extend bbox.</font> +01352 <font class="keyword">const</font> CBezierPatch &p= patchs[j]; +01353 <font class="keywordflow">for</font>(i=0;i<4;i++) +01354 bb.extend(p.Vertices[i]); +01355 <font class="keywordflow">for</font>(i=0;i<8;i++) +01356 bb.extend(p.Tangents[i]); +01357 <font class="keywordflow">for</font>(i=0;i<4;i++) +01358 bb.extend(p.Interiors[i]); +01359 } +01360 <font class="comment">// Compute BBox, and Patch Scale Bias, according to Noise.</font> +01361 <a class="code" href="classNL3D_1_1CZone.html#c4">computeBBScaleBias</a>(bb); +01362 +01363 +01364 <font class="comment">// 3. Re-pack patchs.</font> +01365 <font class="comment">//===================================</font> +01366 <font class="keywordflow">for</font>(j=0;j<(sint)patchs.size();j++) +01367 { +01368 CBezierPatch &p= patchs[j]; +01369 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> &pa= <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[j]; +01370 +01371 <font class="comment">// Build the packed patch.</font> +01372 <font class="keywordflow">for</font>(i=0;i<4;i++) +01373 pa.Vertices[i].pack(p.Vertices[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +01374 <font class="keywordflow">for</font>(i=0;i<8;i++) +01375 pa.Tangents[i].pack(p.Tangents[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +01376 <font class="keywordflow">for</font>(i=0;i<4;i++) +01377 pa.Interiors[i].pack(p.Interiors[i], <a class="code" href="classNL3D_1_1CZone.html#o4">PatchBias</a>, <a class="code" href="classNL3D_1_1CZone.html#o5">PatchScale</a>); +01378 } +01379 } +01380 +01381 <font class="comment">// ***************************************************************************</font> +<a name="l01382"></a><a class="code" href="classNL3D_1_1CZone.html#a32">01382</a> <font class="keywordtype">void</font> CZone::setupColorsFromTileFlags(<font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> colors[4]) +01383 { +01384 <font class="keywordflow">for</font> (uint k = 0; k < <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>.size(); ++k) +01385 { +01386 <a class="code" href="classNL3D_1_1CZone.html#o9">Patchs</a>[k].setupColorsFromTileFlags(colors); +01387 } +01388 } +01389 +01390 +01391 <font class="comment">// ***************************************************************************</font> +<a name="l01392"></a><a class="code" href="classNL3D_1_1CZone.html#a33">01392</a> <font class="keywordtype">void</font> CZone::copyTilesFlags(sint destPatchId, <font class="keyword">const</font> CPatch *srcPatch) +01393 { +01394 <a class="code" href="classNL3D_1_1CZone.html#l2">CPatch</a> *destPatch = <a class="code" href="classNL3D_1_1CZone.html#a29">getPatch</a>(destPatchId); +01395 +01396 destPatch->copyTileFlagsFromPatch(srcPatch); +01397 } +01398 +01399 +01400 <font class="comment">// ***************************************************************************</font> +01401 <font class="keywordtype">bool</font> CPatchInfo::getNeighborTile (uint patchId, uint edge, sint position, uint &patchOut, sint &sOut, sint &tOut, +01402 <font class="keyword">const</font> vector<CPatchInfo> &patchInfos)<font class="keyword"> const</font> +01403 <font class="keyword"></font>{ +01404 <a class="code" href="debug_8h.html#a6">nlassert</a> (edge<4); +01405 +01406 <font class="comment">// S or T ?</font> +01407 uint length = (edge&1) ? OrderS : OrderT; +01408 <a class="code" href="debug_8h.html#a6">nlassert</a> ((uint)position<length); +01409 +01410 <font class="comment">// What kind of case ?</font> +01411 <font class="keywordflow">switch</font> (BindEdges[edge].NPatchs) +01412 { +01413 <font class="keywordflow">case</font> 1: +01414 <font class="keywordflow">case</font> 2: +01415 <font class="keywordflow">case</font> 4: +01416 { +01417 <font class="comment">// Get neighbor index and position in neighbor</font> +01418 uint neighborLength = (length / BindEdges[edge].NPatchs); +01419 uint neighbor = position / neighborLength; +01420 uint neighborPosition = neighborLength - (position % neighborLength) - 1; +01421 uint neighborEdge = BindEdges[edge].Edge[neighbor]; +01422 +01423 <font class="comment">// Patch id</font> +01424 patchOut = BindEdges[edge].Next[neighbor]; +01425 +01426 <font class="comment">// Check neighbor</font> +01427 uint neighborRealLength = (neighborEdge&1) ? patchInfos[patchOut].OrderS : patchInfos[patchOut].OrderT; +01428 <font class="keywordflow">if</font> (neighborRealLength == neighborLength) +01429 { +01430 <font class="comment">// Get final coordinate</font> +01431 <font class="keywordflow">switch</font> (neighborEdge) +01432 { +01433 <font class="keywordflow">case</font> 0: +01434 sOut = 0; +01435 tOut = neighborPosition; +01436 <font class="keywordflow">break</font>; +01437 <font class="keywordflow">case</font> 1: +01438 sOut = neighborPosition; +01439 tOut = patchInfos[patchOut].OrderT-1; +01440 <font class="keywordflow">break</font>; +01441 <font class="keywordflow">case</font> 2: +01442 sOut = patchInfos[patchOut].OrderS-1; +01443 tOut = patchInfos[patchOut].OrderT-neighborPosition-1; +01444 <font class="keywordflow">break</font>; +01445 <font class="keywordflow">case</font> 3: +01446 sOut = patchInfos[patchOut].OrderS-neighborPosition-1; +01447 tOut = 0; +01448 <font class="keywordflow">break</font>; +01449 } +01450 +01451 <font class="comment">// Ok todo remove</font> +01452 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01453 } +01454 } +01455 <font class="keywordflow">break</font>; +01456 +01457 <font class="keywordflow">case</font> 5: +01458 { +01459 <font class="comment">// Find in the neighbor where we are</font> +01460 patchOut = BindEdges[edge].Next[0]; +01461 uint neighborEdge = BindEdges[edge].Edge[0]; +01462 uint neighborEdgeCount = patchInfos[patchOut].BindEdges[neighborEdge].NPatchs; +01463 +01464 <font class="comment">// Check neighbor</font> +01465 uint neighborRealLength = (neighborEdge&1) ? patchInfos[patchOut].OrderS : patchInfos[patchOut].OrderT; +01466 +01467 <font class="comment">// Good length ?</font> +01468 <font class="keywordflow">if</font> ((neighborRealLength / neighborEdgeCount) == length) +01469 { +01470 <font class="comment">// Find us in the neighbor</font> +01471 uint neighborPosition; +01472 <font class="keywordflow">for</font> (neighborPosition=0; neighborPosition<neighborEdgeCount; neighborPosition++) +01473 { +01474 <font class="comment">// Found ?</font> +01475 <font class="keywordflow">if</font> (patchInfos[patchOut].BindEdges[neighborEdge].Next[neighborPosition] == patchId) +01476 <font class="keywordflow">break</font>; +01477 } +01478 +01479 <font class="comment">// Must be found</font> +01480 <a class="code" href="debug_8h.html#a6">nlassert</a> (neighborPosition!=neighborEdgeCount); +01481 neighborPosition = (neighborPosition + 1) * (neighborRealLength / neighborEdgeCount) - position - 1; +01482 +01483 <font class="comment">// Get final coordinate</font> +01484 <font class="keywordflow">switch</font> (neighborEdge) +01485 { +01486 <font class="keywordflow">case</font> 0: +01487 sOut = 0; +01488 tOut = neighborPosition; +01489 <font class="keywordflow">break</font>; +01490 <font class="keywordflow">case</font> 1: +01491 sOut = neighborPosition; +01492 tOut = patchInfos[patchOut].OrderT-1; +01493 <font class="keywordflow">break</font>; +01494 <font class="keywordflow">case</font> 2: +01495 sOut = patchInfos[patchOut].OrderS-1; +01496 tOut = patchInfos[patchOut].OrderT-neighborPosition-1; +01497 <font class="keywordflow">break</font>; +01498 <font class="keywordflow">case</font> 3: +01499 sOut = patchInfos[patchOut].OrderS-neighborPosition-1; +01500 tOut = 0; +01501 <font class="keywordflow">break</font>; +01502 } +01503 +01504 <font class="comment">// Ok</font> +01505 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01506 } +01507 } +01508 <font class="keywordflow">break</font>; +01509 } +01510 +01511 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01512 } +01513 +01514 +01515 <font class="comment">// ***************************************************************************</font> +01516 +<a name="l01517"></a><a class="code" href="structNL3D_1_1CPatchInfo.html#d1">01517</a> <font class="keywordtype">bool</font> CPatchInfo::getTileSymmetryRotate (<font class="keyword">const</font> CTileBank &bank, uint tile, <font class="keywordtype">bool</font> &symmetry, uint &rotate) +01518 { +01519 <font class="comment">// Need check the tile ?</font> +01520 <font class="keywordflow">if</font> ( (symmetry || (rotate != 0)) && (tile != 0xffffffff) ) +01521 { +01522 <font class="comment">// Tile exist ?</font> +01523 <font class="keywordflow">if</font> (tile < (uint)bank.getTileCount()) +01524 { +01525 <font class="comment">// Get xref</font> +01526 <font class="keywordtype">int</font> tileSet; +01527 <font class="keywordtype">int</font> number; +01528 CTileBank::TTileType <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>; +01529 +01530 <font class="comment">// Get tile xref</font> +01531 bank.getTileXRef ((<font class="keywordtype">int</font>)tile, tileSet, number, <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>); +01532 +01533 <font class="comment">// Is it an oriented tile ?</font> +01534 <font class="keywordflow">if</font> (bank.getTileSet (tileSet)->getOriented()) +01535 { +01536 <font class="comment">// New rotation value</font> +01537 rotate = 0; +01538 } +01539 +01540 <font class="comment">// Ok</font> +01541 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01542 } +01543 +01544 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01545 } +01546 <font class="keywordflow">else</font> +01547 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01548 } +01549 +01550 <font class="comment">// ***************************************************************************</font> +01551 +<a name="l01552"></a><a class="code" href="structNL3D_1_1CPatchInfo.html#d2">01552</a> <font class="keywordtype">bool</font> CPatchInfo::transformTile (<font class="keyword">const</font> CTileBank &bank, uint &tile, uint &tileRotation, <font class="keywordtype">bool</font> symmetry, uint rotate, <font class="keywordtype">bool</font> goofy) +01553 { +01554 <font class="comment">// Tile exist ?</font> +01555 <font class="keywordflow">if</font> ( (rotate!=0) || symmetry ) +01556 { +01557 <font class="keywordflow">if</font> (tile < (uint)bank.getTileCount()) +01558 { +01559 <font class="comment">// Get xref</font> +01560 <font class="keywordtype">int</font> tileSet; +01561 <font class="keywordtype">int</font> number; +01562 CTileBank::TTileType <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>; +01563 +01564 <font class="comment">// Get tile xref</font> +01565 bank.getTileXRef ((<font class="keywordtype">int</font>)tile, tileSet, number, <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>); +01566 +01567 <font class="comment">// Transition ?</font> +01568 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a> == CTileBank::transition) +01569 { +01570 <font class="comment">// Rotation for transition</font> +01571 uint transRotate = rotate; +01572 +01573 <font class="comment">// Number should be ok</font> +01574 <a class="code" href="debug_8h.html#a6">nlassert</a> (number>=0); +01575 <a class="code" href="debug_8h.html#a6">nlassert</a> (number<CTileSet::count); +01576 +01577 <font class="comment">// Tlie set number</font> +01578 <font class="keyword">const</font> CTileSet *pTileSet = bank.getTileSet (tileSet); +01579 +01580 <font class="comment">// Get border desc</font> +01581 CTileSet::TFlagBorder oriented[4] = +01582 { +01583 pTileSet->getOrientedBorder (CTileSet::left, CTileSet::getEdgeType ((CTileSet::TTransition)number, CTileSet::left)), +01584 pTileSet->getOrientedBorder (CTileSet::bottom, CTileSet::getEdgeType ((CTileSet::TTransition)number, CTileSet::bottom)), +01585 pTileSet->getOrientedBorder (CTileSet::right, CTileSet::getEdgeType ((CTileSet::TTransition)number, CTileSet::right)), +01586 pTileSet->getOrientedBorder (CTileSet::top, CTileSet::getEdgeType ((CTileSet::TTransition)number, CTileSet::top)) +01587 }; +01588 +01589 <font class="comment">// Symmetry ?</font> +01590 <font class="keywordflow">if</font> (symmetry) +01591 { +01592 <font class="keywordflow">if</font> ( (tileRotation & 1) ^ goofy ) +01593 { +01594 CTileSet::TFlagBorder tmp = oriented[1]; +01595 oriented[1] = CTileSet::getInvertBorder (oriented[3]); +01596 oriented[3] = CTileSet::getInvertBorder (tmp); +01597 oriented[2] = CTileSet::getInvertBorder (oriented[2]); +01598 oriented[0] = CTileSet::getInvertBorder (oriented[0]); +01599 } +01600 <font class="keywordflow">else</font> +01601 { +01602 CTileSet::TFlagBorder tmp = oriented[0]; +01603 oriented[0] = CTileSet::getInvertBorder (oriented[2]); +01604 oriented[2] = CTileSet::getInvertBorder (tmp); +01605 oriented[1] = CTileSet::getInvertBorder (oriented[1]); +01606 oriented[3] = CTileSet::getInvertBorder (oriented[3]); +01607 } +01608 } +01609 +01610 <font class="comment">// Rotation</font> +01611 CTileSet::TFlagBorder edges[4]; +01612 edges[0] = pTileSet->getOrientedBorder (CTileSet::left, oriented[(0 + transRotate )&3]); +01613 edges[1] = pTileSet->getOrientedBorder (CTileSet::bottom, oriented[(1 + transRotate )&3]); +01614 edges[2] = pTileSet->getOrientedBorder (CTileSet::right, oriented[(2 + transRotate )&3]); +01615 edges[3] = pTileSet->getOrientedBorder (CTileSet::top, oriented[(3 + transRotate )&3]); +01616 +01617 <font class="comment">// Get the good tile number</font> +01618 CTileSet::TTransition transition = pTileSet->getTransitionTile (edges[3], edges[1], edges[0], edges[2]); +01619 <a class="code" href="debug_8h.html#a6">nlassert</a> ((CTileSet::TTransition)transition != CTileSet::notfound); +01620 tile = (uint)(pTileSet->getTransition (transition)->getTile ()); +01621 } +01622 +01623 <font class="comment">// Transform rotation: invert rotation</font> +01624 tileRotation += rotate; +01625 +01626 <font class="comment">// If goofy, add +2</font> +01627 <font class="keywordflow">if</font> (goofy && symmetry) +01628 tileRotation += 2; +01629 +01630 <font class="comment">// Mask the rotation</font> +01631 tileRotation &= 3; +01632 } +01633 <font class="keywordflow">else</font> +01634 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01635 } +01636 +01637 <font class="comment">// Ok</font> +01638 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01639 } +01640 +01641 <font class="comment">// ***************************************************************************</font> +01642 +<a name="l01643"></a><a class="code" href="structNL3D_1_1CPatchInfo.html#d3">01643</a> <font class="keywordtype">void</font> CPatchInfo::transform256Case (<font class="keyword">const</font> CTileBank &bank, uint8 &case256, uint tileRotation, <font class="keywordtype">bool</font> symmetry, uint rotate, <font class="keywordtype">bool</font> goofy) +01644 { +01645 <font class="comment">// Tile exist ?</font> +01646 <font class="keywordflow">if</font> ( (rotate!=0) || symmetry ) +01647 { +01648 <font class="comment">// Symmetry ?</font> +01649 <font class="keywordflow">if</font> (symmetry) +01650 { +01651 <font class="comment">// Take the symmetry</font> +01652 uint symArray[4] = {3, 2, 1, 0}; +01653 case256 = symArray[case256]; +01654 +01655 <font class="keywordflow">if</font> (goofy && ((tileRotation & 1) ==0)) +01656 case256 += 2; +01657 <font class="keywordflow">if</font> ((!goofy) && (tileRotation & 1)) +01658 case256 += 2; +01659 } +01660 +01661 <font class="comment">// Rotation ?</font> +01662 case256 -= rotate; +01663 case256 &= 3; +01664 } +01665 } +01666 +01667 <font class="comment">// ***************************************************************************</font> +01668 +<a name="l01669"></a><a class="code" href="structNL3D_1_1CPatchInfo.html#d0">01669</a> <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a371">CPatchInfo::transform</a> (std::vector<CPatchInfo> &patchInfo, <a class="code" href="classNL3D_1_1CZoneSymmetrisation.html">NL3D::CZoneSymmetrisation</a> &zoneSymmetry, <font class="keyword">const</font> <a class="code" href="classNL3D_1_1CTileBank.html">NL3D::CTileBank</a> &bank, <font class="keywordtype">bool</font> symmetry, uint rotate, <font class="keywordtype">float</font> snapCell, <font class="keywordtype">float</font> weldThreshold, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &toOriginalSpace) +01670 { +01671 uint patchCount = patchInfo.size (); +01672 uint i; +01673 +01674 <font class="comment">// --- Export tile info Symmetry of the bind info.</font> +01675 <font class="comment">// --- Parse each patch and each edge</font> +01676 +01677 <font class="comment">// For each patches</font> +01678 <a class="code" href="classNL3D_1_1CZoneSymmetrisation_1_1CError.html">NL3D::CZoneSymmetrisation::CError</a> error; +01679 +01680 <font class="comment">// Build the structure</font> +01681 <font class="keywordflow">if</font> (!zoneSymmetry.<a class="code" href="classNL3D_1_1CZoneSymmetrisation.html#a5">build</a> (patchInfo, snapCell, weldThreshold, bank, error, toOriginalSpace)) +01682 { +01683 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01684 } +01685 +01686 <font class="comment">// Symmetry ?</font> +01687 <font class="keywordflow">if</font> (symmetry) +01688 { +01689 <font class="keywordflow">for</font>(i=0 ; i<patchCount; i++) +01690 { +01691 <font class="comment">// Ref on the current patch</font> +01692 <a class="code" href="structNL3D_1_1CPatchInfo.html#a3">CPatchInfo</a> &pi = patchInfo[i]; +01693 +01694 <font class="comment">// --- Symmetry vertex indexes</font> +01695 +01696 <font class="comment">// Vertices</font> +01697 CVector tmp = pi.Patch.Vertices[0]; +01698 pi.Patch.Vertices[0] = pi.Patch.Vertices[3]; +01699 pi.Patch.Vertices[3] = tmp; +01700 tmp = pi.Patch.Vertices[1]; +01701 pi.Patch.Vertices[1] = pi.Patch.Vertices[2]; +01702 pi.Patch.Vertices[2] = tmp; +01703 +01704 <font class="comment">// Tangents</font> +01705 tmp = pi.Patch.Tangents[0]; +01706 pi.Patch.Tangents[0] = pi.Patch.Tangents[5]; +01707 pi.Patch.Tangents[5] = tmp; +01708 tmp = pi.Patch.Tangents[1]; +01709 pi.Patch.Tangents[1] = pi.Patch.Tangents[4]; +01710 pi.Patch.Tangents[4] = tmp; +01711 tmp = pi.Patch.Tangents[2]; +01712 pi.Patch.Tangents[2] = pi.Patch.Tangents[3]; +01713 pi.Patch.Tangents[3] = tmp; +01714 tmp = pi.Patch.Tangents[6]; +01715 pi.Patch.Tangents[6] = pi.Patch.Tangents[7]; +01716 pi.Patch.Tangents[7] = tmp; +01717 +01718 <font class="comment">// Interior</font> +01719 tmp = pi.Patch.Interiors[0]; +01720 pi.Patch.Interiors[0] = pi.Patch.Interiors[3]; +01721 pi.Patch.Interiors[3] = tmp; +01722 tmp = pi.Patch.Interiors[1]; +01723 pi.Patch.Interiors[1] = pi.Patch.Interiors[2]; +01724 pi.Patch.Interiors[2] = tmp; +01725 +01726 <font class="comment">// ** Symmetries tile colors</font> +01727 +01728 uint u,<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>; +01729 uint countU = pi.OrderS/2+1; +01730 uint countV = pi.OrderT+1; +01731 <font class="keywordflow">for</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a><countV; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>++) +01732 <font class="keywordflow">for</font> (u=0; u<countU; u++) +01733 { +01734 <font class="comment">// Store it in the tile info</font> +01735 uint index0 = u+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*(pi.OrderS+1); +01736 uint index1 = (pi.OrderS-u)+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*(pi.OrderS+1); +01737 +01738 <font class="comment">// XChg</font> +01739 uint16 tmp = pi.TileColors[index0].Color565; +01740 pi.TileColors[index0].Color565 = pi.TileColors[index1].Color565; +01741 pi.TileColors[index1].Color565 = tmp; +01742 } +01743 +01744 <font class="comment">// Smooth flags</font> +01745 uint backupFlag = pi.Flags; +01746 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> edge=0; edge<4; edge+=2) +01747 { +01748 <font class="comment">// Clear smooth flags</font> +01749 pi.Flags &= (1<<edge); +01750 +01751 <font class="comment">// Symmetry edge</font> +01752 uint symEdge = ((edge+2)&3); +01753 +01754 <font class="comment">// Copy the flag</font> +01755 pi.Flags |= (((backupFlag>>symEdge)&1)<<edge); +01756 } +01757 } +01758 +01759 <font class="comment">// --- Symmetry of the bind info.</font> +01760 <font class="comment">// --- Parse each patch and each edge</font> +01761 <font class="comment">// For each patches</font> +01762 <font class="keywordflow">for</font> (i=0 ; i<patchCount; i++) +01763 { +01764 <font class="comment">// Ref on the patch info</font> +01765 <a class="code" href="structNL3D_1_1CPatchInfo.html#a3">CPatchInfo</a> &pi = patchInfo[i]; +01766 +01767 <font class="comment">// Xchg left and right</font> +01768 swap (pi.BindEdges[0], pi.BindEdges[2]); +01769 swap (pi.BaseVertices[0], pi.BaseVertices[3]); +01770 swap (pi.BaseVertices[1], pi.BaseVertices[2]); +01771 +01772 <font class="comment">// Flip edges</font> +01773 <font class="keywordflow">for</font> (uint edge=0; edge<4; edge++) +01774 { +01775 <font class="comment">// Ref on the patch info</font> +01776 CPatchInfo::CBindInfo &bindEdge = pi.BindEdges[edge]; +01777 +01778 uint next; +01779 <font class="comment">// Look if it is a bind ?</font> +01780 <font class="keywordflow">if</font> ( (bindEdge.NPatchs>1) && (bindEdge.NPatchs!=5) ) +01781 { +01782 <font class="keywordflow">for</font> (next=0; next<(uint)bindEdge.NPatchs/2; next++) +01783 { +01784 swap (bindEdge.Next[bindEdge.NPatchs - next - 1], bindEdge.Next[next]); +01785 swap (bindEdge.Edge[bindEdge.NPatchs - next - 1], bindEdge.Edge[next]); +01786 } +01787 } +01788 +01789 <font class="comment">// Look if we are binded on a reversed edge</font> +01790 uint bindCount = (bindEdge.NPatchs==5) ? 1 : bindEdge.NPatchs; +01791 <font class="keywordflow">for</font> (next=0; next<bindCount; next++) +01792 { +01793 <font class="comment">// Left or right ?</font> +01794 <font class="keywordflow">if</font> ( (bindEdge.Edge[next] & 1) == 0) +01795 { +01796 <font class="comment">// Invert</font> +01797 bindEdge.Edge[next] += 2; +01798 bindEdge.Edge[next] &= 3; +01799 } +01800 } +01801 } +01802 } +01803 } +01804 +01805 <font class="comment">// For each patches</font> +01806 <font class="keywordflow">for</font> (i=0 ; i<patchCount; i++) +01807 { +01808 <font class="comment">// Tile infos</font> +01809 <a class="code" href="structNL3D_1_1CPatchInfo.html#a3">CPatchInfo</a> &pi = patchInfo[i]; +01810 +01811 <font class="comment">// Backup tiles</font> +01812 std::vector<CTileElement> tiles = pi.Tiles; +01813 +01814 <font class="keywordtype">int</font> u,<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>; +01815 <font class="keywordflow">for</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a><pi.OrderT; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>++) +01816 <font class="keywordflow">for</font> (u=0; u<pi.OrderS; u++) +01817 { +01818 <font class="comment">// U tile</font> +01819 <font class="keywordtype">int</font> uSymmetry = symmetry ? (pi.OrderS-u-1) : u; +01820 +01821 <font class="comment">// Destination tile</font> +01822 CTileElement &element = pi.Tiles[u+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*pi.OrderS]; +01823 +01824 <font class="comment">// Copy the orginal symmetrical element</font> +01825 element = tiles[uSymmetry+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*pi.OrderS]; +01826 +01827 <font class="comment">// For each layer</font> +01828 <font class="keywordflow">for</font> (<font class="keywordtype">int</font> <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>=0; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a><3; <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>++) +01829 { +01830 <font class="comment">// Empty ?</font> +01831 <font class="keywordflow">if</font> (element.Tile[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>] != 0xffff) +01832 { +01833 <font class="comment">// Get the tile index</font> +01834 uint tile = element.Tile[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>]; +01835 uint tileRotation = element.getTileOrient (<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>); +01836 +01837 <font class="comment">// Get rot and symmetry for this tile</font> +01838 uint tileRotate = rotate; +01839 <font class="keywordtype">bool</font> tileSymmetry = symmetry; +01840 <font class="keywordtype">bool</font> goofy = symmetry && (zoneSymmetry.<a class="code" href="classNL3D_1_1CZoneSymmetrisation.html#a1">getTileState</a> (i, uSymmetry+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*pi.OrderS, <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>) == CZoneSymmetrisation::Goofy); +01841 +01842 <font class="comment">// Transform the transfo</font> +01843 <font class="keywordflow">if</font> (<a class="code" href="structNL3D_1_1CPatchInfo.html#d1">getTileSymmetryRotate</a> (bank, tile, tileSymmetry, tileRotate)) +01844 { +01845 <font class="comment">// Transform the tile</font> +01846 <font class="keywordflow">if</font> (!<a class="code" href="structNL3D_1_1CPatchInfo.html#d2">transformTile</a> (bank, tile, tileRotation, tileSymmetry, (4-tileRotate)&3, goofy)) +01847 { +01848 <font class="comment">// Info</font> +01849 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Error getting symmetrical / rotated zone tile."</font>); +01850 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01851 } +01852 } +01853 <font class="keywordflow">else</font> +01854 { +01855 <font class="comment">// Info</font> +01856 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Error getting symmetrical / rotated zone tile."</font>); +01857 <font class="keywordflow">return</font> <font class="keyword">false</font>; +01858 } +01859 +01860 <font class="comment">// Set the tile</font> +01861 element.Tile[<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>] = tile; +01862 element.setTileOrient (<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>, (uint8)tileRotation); +01863 } +01864 } +01865 +01866 <font class="comment">// Empty ?</font> +01867 <font class="keywordflow">if</font> (element.Tile[0]!=0xffff) +01868 { +01869 <font class="comment">// Get 256 info</font> +01870 <font class="keywordtype">bool</font> is256x256; +01871 uint8 uvOff; +01872 element.getTile256Info (is256x256, uvOff); +01873 +01874 <font class="comment">// 256 ?</font> +01875 <font class="keywordflow">if</font> (is256x256) +01876 { +01877 <font class="comment">// Get rot and symmetry for this tile</font> +01878 uint tileRotate = rotate; +01879 <font class="keywordtype">bool</font> tileSymmetry = symmetry; +01880 uint tileRotation = tiles[uSymmetry+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*pi.OrderS].getTileOrient (0); +01881 <font class="keywordtype">bool</font> goofy = symmetry && (zoneSymmetry.<a class="code" href="classNL3D_1_1CZoneSymmetrisation.html#a1">getTileState</a> (i, uSymmetry+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>*pi.OrderS, 0) == CZoneSymmetrisation::Goofy); +01882 +01883 <font class="comment">// Transform the transfo</font> +01884 <a class="code" href="structNL3D_1_1CPatchInfo.html#d1">getTileSymmetryRotate</a> (bank, element.Tile[0], tileSymmetry, tileRotate); +01885 +01886 <font class="comment">// Transform the case</font> +01887 <a class="code" href="structNL3D_1_1CPatchInfo.html#d3">transform256Case</a> (bank, uvOff, tileRotation, tileSymmetry, (4-tileRotate)&3, goofy); +01888 +01889 element.setTile256Info (<font class="keyword">true</font>, uvOff); +01890 } +01891 } +01892 } +01893 } +01894 +01895 <font class="comment">// Ok</font> +01896 <font class="keywordflow">return</font> <font class="keyword">true</font>; +01897 } +01898 +01899 <font class="comment">// ***************************************************************************</font> +01900 +01901 } <font class="comment">// NL3D</font> +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </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> |