diff options
Diffstat (limited to '')
-rw-r--r-- | docs/doxygen/nel/patch_8cpp-source.html | 2328 |
1 files changed, 2328 insertions, 0 deletions
diff --git a/docs/doxygen/nel/patch_8cpp-source.html b/docs/doxygen/nel/patch_8cpp-source.html new file mode 100644 index 00000000..913b78f9 --- /dev/null +++ b/docs/doxygen/nel/patch_8cpp-source.html @@ -0,0 +1,2328 @@ +<!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>patch.cpp</h1><a href="patch_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 +00029 <font class="preprocessor">#include "<a class="code" href="patch_8h.html">3d/patch.h</a>"</font> +00030 <font class="preprocessor">#include "<a class="code" href="tessellation_8h.html">3d/tessellation.h</a>"</font> +00031 <font class="preprocessor">#include "<a class="code" href="bezier__patch_8h.html">3d/bezier_patch.h</a>"</font> +00032 <font class="preprocessor">#include "<a class="code" href="src_23d_2zone_8h.html">3d/zone.h</a>"</font> +00033 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font> +00034 <font class="preprocessor">#include "<a class="code" href="vector_8h.html">nel/misc/vector.h</a>"</font> +00035 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font> +00036 <font class="preprocessor">#include "<a class="code" href="patchuv__locator_8h.html">3d/patchuv_locator.h</a>"</font> +00037 <font class="preprocessor">#include "<a class="code" href="vegetable__manager_8h.html">3d/vegetable_manager.h</a>"</font> +00038 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font> +00039 <font class="preprocessor">#include "<a class="code" href="light__influence__interpolator_8h.html">3d/light_influence_interpolator.h</a>"</font> +00040 <font class="preprocessor">#include "<a class="code" href="patchdlm__context_8h.html">3d/patchdlm_context.h</a>"</font> +00041 +00042 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00043 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00044 +00045 +00046 <font class="keyword">namespace </font>NL3D +00047 { +00048 +00049 +00050 <font class="comment">// ***************************************************************************</font> +<a name="l00051"></a><a class="code" href="classNL3D_1_1CPatch.html#r1">00051</a> CBezierPatch CPatch::CachePatch; +<a name="l00052"></a><a class="code" href="classNL3D_1_1CPatch.html#r2">00052</a> <font class="keyword">const</font> CPatch *CPatch::LastPatch= NULL; +<a name="l00053"></a><a class="code" href="classNL3D_1_1CPatch.html#r0">00053</a> uint32 CPatch::_Version=7; +00054 +00055 +00056 <font class="comment">// ***************************************************************************</font> +<a name="l00057"></a><a class="code" href="classNL3D_1_1CPatch.html#a0">00057</a> CPatch::CPatch() +00058 { +00059 <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>= NULL; +00060 <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>=0; +00061 <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>=0; +00062 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>=NULL; +00063 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>=NULL; +00064 <a class="code" href="classNL3D_1_1CPatch.html#z678_2">TessBlockRefCount</a>=0; +00065 <a class="code" href="classNL3D_1_1CPatch.html#o25">Clipped</a>=<font class="keyword">false</font>; +00066 <a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>= <font class="keyword">true</font>; +00067 <a class="code" href="classNL3D_1_1CPatch.html#o27">OldRenderClipped</a>= <font class="keyword">true</font>; +00068 <a class="code" href="classNL3D_1_1CPatch.html#z678_3">NumRenderableFaces</a>= 0; +00069 +00070 <font class="comment">// for Pacs process. By default, false.</font> +00071 <a class="code" href="classNL3D_1_1CPatch.html#o4">ExcludeFromRefineAll</a>= <font class="keyword">false</font>; +00072 +00073 <font class="comment">// Init Passes.</font> +00074 <font class="comment">// DO NOT FILL Patch here, because of operator= problem. do it in compile().</font> +00075 <font class="comment">// By default, RdrPasses are NULL.</font> +00076 +00077 <font class="comment">// To force computation of texture info on next preRender().</font> +00078 <a class="code" href="classNL3D_1_1CPatch.html#o14">Far0</a>= -1; +00079 <a class="code" href="classNL3D_1_1CPatch.html#o15">Far1</a>= -1; +00080 +00081 <font class="comment">// Default: not binded.</font> +00082 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[0]= NULL; +00083 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[1]= NULL; +00084 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[2]= NULL; +00085 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[3]= NULL; +00086 <a class="code" href="classNL3D_1_1CPatch.html#z668_2">NoiseRotation</a>= 0; +00087 <font class="comment">// No smooth by default.</font> +00088 <a class="code" href="classNL3D_1_1CPatch.html#z668_3">_CornerSmoothFlag</a>= 0; +00089 +00090 <font class="comment">// MasterBlock never clipped.</font> +00091 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.resetClip(); +00092 +00093 <font class="comment">// Init UL circular list to NULL (not compiled)</font> +00094 <a class="code" href="classNL3D_1_1CPatch.html#z687_0">_ULNearPrec</a>= NULL; +00095 <a class="code" href="classNL3D_1_1CPatch.html#z687_1">_ULNearNext</a>= NULL; +00096 +00097 <font class="comment">// Dynamic LightMap</font> +00098 <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>= NULL; +00099 <a class="code" href="classNL3D_1_1CPatch.html#z688_3">_DLMContextRefCount</a>= 0; +00100 } +00101 <font class="comment">// ***************************************************************************</font> +<a name="l00102"></a><a class="code" href="classNL3D_1_1CPatch.html#a1">00102</a> CPatch::~CPatch() +00103 { +00104 <a class="code" href="classNL3D_1_1CPatch.html#a3">release</a>(); +00105 } +00106 +00107 <font class="comment">// ***************************************************************************</font> +<a name="l00108"></a><a class="code" href="classNL3D_1_1CPatch.html#a3">00108</a> <font class="keywordtype">void</font> CPatch::release() +00109 { +00110 <font class="keywordflow">if</font>(Zone) +00111 { +00112 <font class="comment">// First, delete the VB if the zone was removed while the patch is visible.</font> +00113 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>) +00114 { +00115 <font class="comment">// release VertexBuffer.</font> +00116 <a class="code" href="classNL3D_1_1CPatch.html#z673_0">deleteVBAndFaceVector</a>(); +00117 +00118 <font class="comment">// Flag.</font> +00119 <a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>= <font class="keyword">true</font>; +00120 } +00121 +00122 <font class="comment">// THIS PATCH MSUT BE UNBOUND FIRST!!!!!</font> +00123 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a> && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +00124 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->isLeaf() && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->isLeaf()); +00125 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FLeft == NULL); +00126 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FRight == NULL); +00127 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FLeft == NULL); +00128 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FRight == NULL); +00129 +00130 <font class="comment">// Free renderPass of landscape, and maybe force computation of texture info on next preRender().</font> +00131 <font class="comment">// Must do it here, before deletion of Zone, OrderS/T etc...</font> +00132 <a class="code" href="classNL3D_1_1CPatch.html#a28">resetRenderFar</a>(); +00133 +00134 <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->deleteTessFace(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>); +00135 <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->deleteTessFace(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +00136 <font class="comment">// Vertices are smartptr/deleted in zone.</font> +00137 } +00138 +00139 <font class="comment">// Flag the fact that this patch can't be rendered.</font> +00140 <a class="code" href="classNL3D_1_1CPatch.html#o28">Pass0</a>.Patch= NULL; +00141 <a class="code" href="classNL3D_1_1CPatch.html#o29">Pass1</a>.Patch= NULL; +00142 <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>=0; +00143 <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>=0; +00144 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>=NULL; +00145 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>=NULL; +00146 <a class="code" href="classNL3D_1_1CPatch.html#z680_2">clearTessBlocks</a>(); +00147 <a class="code" href="classNL3D_1_1CPatch.html#z680_1">resetMasterBlock</a>(); +00148 <a class="code" href="classNL3D_1_1CPatch.html#o25">Clipped</a>=<font class="keyword">false</font>; +00149 <a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>= <font class="keyword">true</font>; +00150 <a class="code" href="classNL3D_1_1CPatch.html#o27">OldRenderClipped</a>= <font class="keyword">true</font>; +00151 +00152 <font class="comment">// the pathc is uncompiled. must do it after clearTessBlocks(), because may use it </font> +00153 <font class="comment">// for vegetable manager, and for updateLighting</font> +00154 <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>= NULL; +00155 +00156 <font class="comment">// uncompile: reset UpdateLighting circular list to NULL.</font> +00157 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#z687_0">_ULNearPrec</a>!= NULL) +00158 { +00159 <font class="comment">// verify the patch is correctly unlinked from any ciruclar list.</font> +00160 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#z687_0">_ULNearPrec</a>==<font class="keyword">this</font> && <a class="code" href="classNL3D_1_1CPatch.html#z687_1">_ULNearNext</a>==<font class="keyword">this</font>); +00161 } +00162 <a class="code" href="classNL3D_1_1CPatch.html#z687_0">_ULNearPrec</a>= NULL; +00163 <a class="code" href="classNL3D_1_1CPatch.html#z687_1">_ULNearNext</a>= NULL; +00164 +00165 <font class="comment">// DynamciLightMap: release the _DLMContext if still exist.</font> +00166 <font class="keywordflow">if</font>(_DLMContext) +00167 <font class="keyword">delete</font> <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>; +00168 <font class="comment">// reset</font> +00169 <a class="code" href="classNL3D_1_1CPatch.html#z688_2">_DLMContext</a>= NULL; +00170 <a class="code" href="classNL3D_1_1CPatch.html#z688_3">_DLMContextRefCount</a>= 0; +00171 } +00172 +00173 +00174 <font class="comment">// ***************************************************************************</font> +<a name="l00175"></a><a class="code" href="classNL3D_1_1CPatch.html#a45">00175</a> CBezierPatch *CPatch::unpackIntoCache()<font class="keyword"> const</font> +00176 <font class="keyword"></font>{ +00177 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#r2">LastPatch</a>!=<font class="keyword">this</font>) +00178 { +00179 <a class="code" href="classNL3D_1_1CPatch.html#a33">unpack</a>(<a class="code" href="classNL3D_1_1CPatch.html#r1">CachePatch</a>); +00180 <a class="code" href="classNL3D_1_1CPatch.html#r2">LastPatch</a>=<font class="keyword">this</font>; +00181 } +00182 <font class="keywordflow">return</font> &<a class="code" href="classNL3D_1_1CPatch.html#r1">CachePatch</a>; +00183 } +00184 <font class="comment">// ***************************************************************************</font> +<a name="l00185"></a><a class="code" href="classNL3D_1_1CPatch.html#a33">00185</a> <font class="keywordtype">void</font> CPatch::unpack(CBezierPatch &p)<font class="keyword"> const</font> +00186 <font class="keyword"></font>{ +00187 sint i; +00188 <font class="keyword">const</font> CVector &bias= <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->getPatchBias(); +00189 <font class="keywordtype">float</font> scale= <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->getPatchScale(); +00190 +00191 <font class="keywordflow">for</font>(i=0;i<4;i++) +00192 <a class="code" href="classNL3D_1_1CPatch.html#m0">Vertices</a>[i].unpack(p.Vertices[i], bias, scale); +00193 <font class="keywordflow">for</font>(i=0;i<8;i++) +00194 <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[i].unpack(p.Tangents[i], bias, scale); +00195 <font class="keywordflow">for</font>(i=0;i<4;i++) +00196 <a class="code" href="classNL3D_1_1CPatch.html#m2">Interiors</a>[i].unpack(p.Interiors[i], bias, scale); +00197 } +00198 <font class="comment">// ***************************************************************************</font> +<a name="l00199"></a><a class="code" href="classNL3D_1_1CPatch.html#c3">00199</a> <font class="keywordtype">void</font> CPatch::computeDefaultErrorSize() +00200 { +00201 CBezierPatch &p= *<a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>(); +00202 CVector &v0= p.Vertices[0]; +00203 CVector &v1= p.Vertices[1]; +00204 CVector &v2= p.Vertices[2]; +00205 +00206 <font class="comment">// \todo yoyo: TODO_NOISE: modulate this value with tangents (roundiness of patch), and with the displacement map.</font> +00207 <a class="code" href="classNL3D_1_1CPatch.html#o8">ErrorSize</a>= ((v1 - v0)^(v2 - v0)).norm(); +00208 +00209 } +00210 +00211 +00212 +00213 <font class="comment">// ***************************************************************************</font> +<a name="l00214"></a><a class="code" href="classNL3D_1_1CPatch.html#z683_0">00214</a> <font class="keywordtype">void</font> CPatch::buildBBoxFromBezierPatch(<font class="keyword">const</font> CBezierPatch &p, CAABBox &ret)<font class="keyword"> const</font> +00215 <font class="keyword"></font>{ +00216 <font class="comment">// Because of the structure of CAABBox, extend() is not fast enough for us. first compute bmin, bmax,</font> +00217 <font class="comment">// then compute the bbox.</font> +00218 CVector bmin= p.Vertices[0]; +00219 CVector bmax= bmin; +00220 +00221 sint i; +00222 <font class="keywordflow">for</font>(i=0;i<4;i++) +00223 { +00224 bmin.minof(bmin, p.Vertices[i]); +00225 bmax.maxof(bmax, p.Vertices[i]); +00226 } +00227 <font class="keywordflow">for</font>(i=0;i<8;i++) +00228 { +00229 bmin.minof(bmin, p.Tangents[i]); +00230 bmax.maxof(bmax, p.Tangents[i]); +00231 } +00232 <font class="keywordflow">for</font>(i=0;i<4;i++) +00233 { +00234 bmin.minof(bmin, p.Interiors[i]); +00235 bmax.maxof(bmax, p.Interiors[i]); +00236 } +00237 +00238 <font class="comment">// Modulate with the maximum displacement map (usefull for patch clipping).</font> +00239 <font class="keyword">static</font> CVector vectorNoiseMax(<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>); +00240 bmin-= vectorNoiseMax; +00241 bmax+= vectorNoiseMax; +00242 <font class="comment">// NB: this is not very optimal, since the BBox may be very too big. eg: patch 16mx16m => bbox 18mx18m.</font> +00243 <font class="comment">// But remind that tessblocks do not use this BBox, and are computed with the real geometry.</font> +00244 +00245 ret.setMinMax(bmin, bmax); +00246 } +00247 +00248 +00249 <font class="comment">// ***************************************************************************</font> +<a name="l00250"></a><a class="code" href="classNL3D_1_1CPatch.html#a14">00250</a> CAABBox CPatch::buildBBox()<font class="keyword"> const</font> +00251 <font class="keyword"></font>{ +00252 CBezierPatch &p= *<a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>(); +00253 +00254 <font class="comment">// Compute Bounding Box. (easiest way...)</font> +00255 CAABBox ret; +00256 <a class="code" href="classNL3D_1_1CPatch.html#z683_0">buildBBoxFromBezierPatch</a>(p, ret); +00257 +00258 <font class="keywordflow">return</font> ret; +00259 } +00260 +00261 +00262 <font class="comment">// ***************************************************************************</font> +<a name="l00263"></a><a class="code" href="classNL3D_1_1CPatch.html#z670_0">00263</a> <font class="keywordtype">void</font> CPatch::addTrianglesInBBox(CPatchIdent paId, <font class="keyword">const</font> CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tileTessLevel)<font class="keyword"> const</font> +00264 <font class="keyword"></font>{ +00265 CBezierPatch &bpatch= *<a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>(); +00266 +00267 <font class="comment">// call with the whole root patch.</font> +00268 <a class="code" href="classNL3D_1_1CPatch.html#z683_1">addTrianglesInBBoxRecurs</a>(paId, bbox, triangles, tileTessLevel, bpatch, 0, <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>, 0, <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>); +00269 } +00270 +00271 +00272 <font class="comment">// ***************************************************************************</font> +<a name="l00273"></a><a class="code" href="classNL3D_1_1CPatch.html#z683_1">00273</a> <font class="keywordtype">void</font> CPatch::addTrianglesInBBoxRecurs(CPatchIdent paId, <font class="keyword">const</font> CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tessLevel, +00274 <font class="keyword">const</font> CBezierPatch &pa, uint8 s0, uint8 s1, uint8 t0, uint8 t1)<font class="keyword"> const</font> +00275 <font class="keyword"></font>{ +00276 uint8 lenS=s1-s0, lenT=t1-t0; +00277 <a class="code" href="debug_8h.html#a6">nlassert</a>(lenS>0); +00278 <a class="code" href="debug_8h.html#a6">nlassert</a>(lenT>0); +00279 +00280 <font class="comment">// compute and compare bbox of the subdivision patch against request bbox.</font> +00281 <font class="comment">//========================</font> +00282 <font class="comment">// NB: this compute includes possible noise.</font> +00283 CAABBox paBBox; +00284 <a class="code" href="classNL3D_1_1CPatch.html#z683_0">buildBBoxFromBezierPatch</a>(pa, paBBox); +00285 <font class="comment">// if do not intersect, stop here.</font> +00286 <font class="keywordflow">if</font>( !paBBox.intersect(bbox) ) +00287 <font class="keywordflow">return</font>; +00288 <font class="comment">// else if at tile level, then just computeTriangles.</font> +00289 <font class="comment">//========================</font> +00290 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( lenS==1 && lenT==1 ) +00291 { +00292 <a class="code" href="classNL3D_1_1CPatch.html#z683_2">addTileTrianglesInBBox</a>(paId, bbox, triangles, tessLevel, s0, t0); +00293 } +00294 <font class="comment">// else subdiv and reccurs.</font> +00295 <font class="comment">//========================</font> +00296 <font class="keywordflow">else</font> +00297 { +00298 <font class="comment">// Subdivide along the bigger side.</font> +00299 <font class="keywordflow">if</font>(lenS>lenT) +00300 { +00301 <font class="comment">// subdivide.</font> +00302 CBezierPatch left, right; +00303 pa.subdivideS(left, right); +00304 uint8 sMiddle= (uint8)( ((uint)s0+(uint)s1) /2 ); +00305 <font class="comment">// recurs left.</font> +00306 <a class="code" href="classNL3D_1_1CPatch.html#z683_1">addTrianglesInBBoxRecurs</a>(paId, bbox, triangles, tessLevel, left, s0, sMiddle, t0, t1); +00307 <font class="comment">// recurs right.</font> +00308 <a class="code" href="classNL3D_1_1CPatch.html#z683_1">addTrianglesInBBoxRecurs</a>(paId, bbox, triangles, tessLevel, right, sMiddle, s1, t0, t1); +00309 } +00310 <font class="keywordflow">else</font> +00311 { +00312 <font class="comment">// subdivide.</font> +00313 CBezierPatch top, bottom; +00314 pa.subdivideT(top, bottom); +00315 uint8 tMiddle= (uint8)( ((uint)t0+(uint)t1) /2 ); +00316 <font class="comment">// recurs top.</font> +00317 <a class="code" href="classNL3D_1_1CPatch.html#z683_1">addTrianglesInBBoxRecurs</a>(paId, bbox, triangles, tessLevel, top, s0, s1, t0, tMiddle); +00318 <font class="comment">// recurs bottom.</font> +00319 <a class="code" href="classNL3D_1_1CPatch.html#z683_1">addTrianglesInBBoxRecurs</a>(paId, bbox, triangles, tessLevel, bottom, s0, s1, tMiddle, t1); +00320 } +00321 } +00322 +00323 +00324 } +00325 +00326 +00327 <font class="comment">// ***************************************************************************</font> +<a name="l00328"></a><a class="code" href="classNL3D_1_1CPatch.html#z683_2">00328</a> <font class="keywordtype">void</font> CPatch::addTileTrianglesInBBox(CPatchIdent paId, <font class="keyword">const</font> CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tessLevel, uint8 s0, uint8 t0)<font class="keyword"> const</font> +00329 <font class="keyword"></font>{ +00330 <a class="code" href="debug_8h.html#a6">nlassert</a>(s0<<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>); +00331 <a class="code" href="debug_8h.html#a6">nlassert</a>(t0<<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>); +00332 <a class="code" href="debug_8h.html#a6">nlassert</a>(tessLevel<=2); +00333 uint tessLen= 1<<tessLevel; +00334 +00335 <font class="comment">// some preca.</font> +00336 <font class="keywordtype">float</font> startS0= (float)s0 / (float)(OrderS); +00337 <font class="keywordtype">float</font> startT0= (float)t0 / (float)(OrderT); +00338 <font class="keywordtype">float</font> ds= 1.0f/(float)(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>*tessLen); +00339 <font class="keywordtype">float</font> dt= 1.0f/(float)(<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>*tessLen); +00340 +00341 <font class="comment">// Parse all quads.</font> +00342 uint sl,tl; +00343 <font class="keywordflow">for</font>(tl=0; tl<tessLen; tl++) +00344 { +00345 <font class="keywordtype">float</font> fs0, fs1, ft0, ft1; +00346 <font class="comment">// compute t patch coordinates.</font> +00347 ft0= startT0 + (float)tl * dt ; +00348 ft1= ft0 + dt; +00349 <font class="keywordflow">for</font>(sl=0; sl<tessLen; sl++) +00350 { +00351 <font class="comment">// compute s patch coordinates.</font> +00352 fs0= startS0 + (float)sl * ds ; +00353 fs1= fs0 + ds; +00354 +00355 <font class="comment">// Compute Quad vectors (in CCW).</font> +00356 CVector p0, p1, p2, p3; +00357 CUV uv0, uv1, uv2, uv3; +00358 uv0.U= fs0; uv0.V= ft0; +00359 uv1.U= fs0; uv1.V= ft1; +00360 uv2.U= fs1; uv2.V= ft1; +00361 uv3.U= fs1; uv3.V= ft0; +00362 <font class="comment">// evaluate patch (with noise). (NB: because of cache, patch decompression cost nothing).</font> +00363 p0= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(uv0.U, uv0.V); +00364 p1= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(uv1.U, uv1.V); +00365 p2= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(uv2.U, uv2.V); +00366 p3= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(uv3.U, uv3.V); +00367 +00368 <font class="comment">// build the bbox of this quad, and test with request bbox.</font> +00369 CAABBox quadBBox; +00370 quadBBox.setCenter(p0); +00371 quadBBox.extend(p1); +00372 quadBBox.extend(p2); +00373 quadBBox.extend(p3); +00374 +00375 <font class="comment">// insert only if intersect with the bbox.</font> +00376 <font class="keywordflow">if</font>(quadBBox.intersect(bbox)) +00377 { +00378 <font class="comment">// build triangles (in CCW).</font> +00379 CTrianglePatch tri; +00380 tri.PatchId= paId; +00381 +00382 <font class="comment">// first tri.</font> +00383 tri.V0= p0; tri.V1= p1; tri.V2= p2; +00384 tri.Uv0= uv0; tri.Uv1= uv1; tri.Uv2= uv2; +00385 triangles.push_back(tri); +00386 +00387 <font class="comment">// second tri.</font> +00388 tri.V0= p2; tri.V1= p3; tri.V2= p0; +00389 tri.Uv0= uv2; tri.Uv1= uv3; tri.Uv2= uv0; +00390 triangles.push_back(tri); +00391 +00392 <font class="comment">// NB: this is not the same tesselation than in tesselation.cpp.</font> +00393 <font class="comment">// But this looks like Ben's NLPACS::CLocalRetriever tesselation.</font> +00394 } +00395 } +00396 } +00397 +00398 } +00399 +00400 +00401 +00402 <font class="comment">// ***************************************************************************</font> +<a name="l00403"></a><a class="code" href="classNL3D_1_1CPatchQuadBlock.html#a0">00403</a> <font class="keywordtype">void</font> CPatchQuadBlock::buildTileTriangles(uint8 quadId, CTrianglePatch triangles[2])<font class="keyword"> const</font> +00404 <font class="keyword"></font>{ +00405 <font class="comment">// copute coordinate of the tile we want.</font> +00406 uint sd0= quadId&(<a class="code" href="patch_8h.html#a9">NL_PATCH_BLOCK_MAX_QUAD</a>-1); +00407 uint td0= quadId/(NL_PATCH_BLOCK_MAX_QUAD); +00408 uint sd1= sd0+1; +00409 uint td1= td0+1; +00410 uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.S0+sd0; +00411 uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.T0+td0; +00412 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><<a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.S1); +00413 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><<a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.T1); +00414 +00415 <font class="comment">// Compute UV coord.</font> +00416 <font class="keywordtype">float</font> fs0= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> / (float)(<a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.OrderS); +00417 <font class="keywordtype">float</font> ft0= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a> / (float)(<a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.OrderT); +00418 <font class="keywordtype">float</font> fs1= (float)(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1) / (float)(<a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.OrderS); +00419 <font class="keywordtype">float</font> ft1= (float)(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+1) / (float)(<a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.OrderT); +00420 CUV uv0, uv1, uv2, uv3; +00421 uv0.U= fs0; uv0.V= ft0; +00422 uv1.U= fs0; uv1.V= ft1; +00423 uv2.U= fs1; uv2.V= ft1; +00424 uv3.U= fs1; uv3.V= ft0; +00425 +00426 <font class="comment">// get vertex coord.</font> +00427 <font class="keyword">const</font> CVector &p0= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m1">Vertices</a>[sd0 + td0*<a class="code" href="patch_8h.html#a10">NL_PATCH_BLOCK_MAX_VERTEX</a>]; +00428 <font class="keyword">const</font> CVector &p1= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m1">Vertices</a>[sd0 + td1*<a class="code" href="patch_8h.html#a10">NL_PATCH_BLOCK_MAX_VERTEX</a>]; +00429 <font class="keyword">const</font> CVector &p2= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m1">Vertices</a>[sd1 + td1*<a class="code" href="patch_8h.html#a10">NL_PATCH_BLOCK_MAX_VERTEX</a>]; +00430 <font class="keyword">const</font> CVector &p3= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m1">Vertices</a>[sd1 + td0*<a class="code" href="patch_8h.html#a10">NL_PATCH_BLOCK_MAX_VERTEX</a>]; +00431 +00432 <font class="comment">// build triangles.</font> +00433 <font class="comment">// first tri.</font> +00434 { +00435 CTrianglePatch &tri= triangles[0]; +00436 tri.PatchId= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.PatchId; +00437 tri.V0= p0; tri.V1= p1; tri.V2= p2; +00438 tri.Uv0= uv0; tri.Uv1= uv1; tri.Uv2= uv2; +00439 } +00440 +00441 <font class="comment">// second tri.</font> +00442 { +00443 CTrianglePatch &tri= triangles[1]; +00444 tri.PatchId= <a class="code" href="classNL3D_1_1CPatchQuadBlock.html#m0">PatchBlockId</a>.PatchId; +00445 tri.V0= p2; tri.V1= p3; tri.V2= p0; +00446 tri.Uv0= uv2; tri.Uv1= uv3; tri.Uv2= uv0; +00447 } +00448 +00449 } +00450 +00451 +00452 <font class="comment">// ***************************************************************************</font> +<a name="l00453"></a><a class="code" href="classNL3D_1_1CPatch.html#z670_1">00453</a> <font class="keywordtype">void</font> CPatch::fillPatchQuadBlock(CPatchQuadBlock &quadBlock) <font class="keyword">const</font> +00454 { +00455 CPatchBlockIdent &pbId= quadBlock.PatchBlockId; +00456 uint lenS= pbId.S1-pbId.S0; +00457 uint lenT= pbId.T1-pbId.T0; +00458 <a class="code" href="debug_8h.html#a6">nlassert</a>( pbId.OrderS==OrderS ); +00459 <a class="code" href="debug_8h.html#a6">nlassert</a>( pbId.OrderT==OrderT ); +00460 <a class="code" href="debug_8h.html#a6">nlassert</a>( pbId.S1<=OrderS ); +00461 <a class="code" href="debug_8h.html#a6">nlassert</a>( pbId.T1<=OrderT ); +00462 <a class="code" href="debug_8h.html#a6">nlassert</a>( pbId.S0<pbId.S1 ); +00463 <a class="code" href="debug_8h.html#a6">nlassert</a>( pbId.T0<pbId.T1 ); +00464 <a class="code" href="debug_8h.html#a6">nlassert</a>( lenS<=<a class="code" href="patch_8h.html#a9">NL_PATCH_BLOCK_MAX_QUAD</a> ); +00465 <a class="code" href="debug_8h.html#a6">nlassert</a>( lenT<=<a class="code" href="patch_8h.html#a9">NL_PATCH_BLOCK_MAX_QUAD</a> ); +00466 +00467 <font class="comment">// Fill vertices.</font> +00468 uint s0= pbId.S0; +00469 uint t0= pbId.T0; +00470 <font class="comment">// some preca.</font> +00471 <font class="keywordtype">float</font> startS0= (float)s0 / (float)(OrderS); +00472 <font class="keywordtype">float</font> startT0= (float)t0 / (float)(OrderT); +00473 <font class="keywordtype">float</font> ds= 1.0f/(float)(OrderS); +00474 <font class="keywordtype">float</font> dt= 1.0f/(float)(OrderT); +00475 +00476 <font class="comment">// Parse all quads vertices corner.</font> +00477 uint sl,tl; +00478 <font class="keywordflow">for</font>(tl=0; tl<lenT+1; tl++) +00479 { +00480 <font class="keywordtype">float</font> fs, ft; +00481 <font class="comment">// compute t patch coordinates.</font> +00482 ft= startT0 + (float)tl * dt ; +00483 <font class="keywordflow">for</font>(sl=0; sl<lenS+1; sl++) +00484 { +00485 <font class="comment">// compute s patch coordinates.</font> +00486 fs= startS0 + (float)sl * ds ; +00487 +00488 <font class="comment">// Must use computeContinousVertex, to ensure continous coordinate on patch edges</font> +00489 quadBlock.Vertices[sl + tl*<a class="code" href="patch_8h.html#a10">NL_PATCH_BLOCK_MAX_VERTEX</a>]= computeContinousVertex(fs, ft); +00490 } +00491 } +00492 +00493 } +00494 +00495 +00496 <font class="comment">// ***************************************************************************</font> +<a name="l00497"></a><a class="code" href="classNL3D_1_1CPatch.html#z670_2">00497</a> <font class="keywordtype">void</font> CPatch::addPatchBlocksInBBox(CPatchIdent paId, <font class="keyword">const</font> CAABBox &bbox, std::vector<CPatchBlockIdent> &paBlockIds)<font class="keyword"> const</font> +00498 <font class="keyword"></font>{ +00499 CBezierPatch &bpatch= *<a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>(); +00500 +00501 <font class="comment">// call with the whole root patch.</font> +00502 <a class="code" href="classNL3D_1_1CPatch.html#z683_3">addPatchBlocksInBBoxRecurs</a>(paId, bbox, paBlockIds, bpatch, 0, <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>, 0, <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>); +00503 } +00504 +00505 +00506 <font class="comment">// ***************************************************************************</font> +<a name="l00507"></a><a class="code" href="classNL3D_1_1CPatch.html#z683_3">00507</a> <font class="keywordtype">void</font> CPatch::addPatchBlocksInBBoxRecurs(CPatchIdent paId, <font class="keyword">const</font> CAABBox &bbox, std::vector<CPatchBlockIdent> &paBlockIds, +00508 <font class="keyword">const</font> CBezierPatch &pa, uint8 s0, uint8 s1, uint8 t0, uint8 t1)<font class="keyword"> const</font> +00509 <font class="keyword"></font>{ +00510 uint8 lenS=s1-s0, lenT=t1-t0; +00511 <a class="code" href="debug_8h.html#a6">nlassert</a>(lenS>0); +00512 <a class="code" href="debug_8h.html#a6">nlassert</a>(lenT>0); +00513 +00514 <font class="comment">// compute and compare bbox of the subdivision patch against request bbox.</font> +00515 <font class="comment">//========================</font> +00516 <font class="comment">// NB: this compute includes possible noise.</font> +00517 CAABBox paBBox; +00518 <a class="code" href="classNL3D_1_1CPatch.html#z683_0">buildBBoxFromBezierPatch</a>(pa, paBBox); +00519 <font class="comment">// if do not intersect, stop here.</font> +00520 <font class="keywordflow">if</font>( !paBBox.intersect(bbox) ) +00521 <font class="keywordflow">return</font>; +00522 <font class="comment">// else if at CPatchQuadBlock tile level, then just add this Id.</font> +00523 <font class="comment">//========================</font> +00524 <font class="keywordflow">else</font> <font class="keywordflow">if</font>( lenS<=<a class="code" href="patch_8h.html#a9">NL_PATCH_BLOCK_MAX_QUAD</a> && lenT<=<a class="code" href="patch_8h.html#a9">NL_PATCH_BLOCK_MAX_QUAD</a> ) +00525 { +00526 <font class="comment">// Add this PatchBlock desctiptor to the list.</font> +00527 CPatchBlockIdent pbId; +00528 <font class="comment">// Fill struct from this and result of recursion.</font> +00529 pbId.PatchId= paId; +00530 pbId.OrderS= <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>; +00531 pbId.OrderT= <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>; +00532 pbId.S0= s0; +00533 pbId.S1= s1; +00534 pbId.T0= t0; +00535 pbId.T1= t1; +00536 <font class="comment">// Add to list.</font> +00537 paBlockIds.push_back(pbId); +00538 } +00539 <font class="comment">// else subdiv and reccurs.</font> +00540 <font class="comment">//========================</font> +00541 <font class="keywordflow">else</font> +00542 { +00543 <font class="comment">// Subdivide along the bigger side.</font> +00544 <font class="keywordflow">if</font>(lenS>lenT) +00545 { +00546 <font class="comment">// subdivide.</font> +00547 CBezierPatch left, right; +00548 pa.subdivideS(left, right); +00549 uint8 sMiddle= (uint8)( ((uint)s0+(uint)s1) /2 ); +00550 <font class="comment">// recurs left.</font> +00551 <a class="code" href="classNL3D_1_1CPatch.html#z683_3">addPatchBlocksInBBoxRecurs</a>(paId, bbox, paBlockIds, left, s0, sMiddle, t0, t1); +00552 <font class="comment">// recurs right.</font> +00553 <a class="code" href="classNL3D_1_1CPatch.html#z683_3">addPatchBlocksInBBoxRecurs</a>(paId, bbox, paBlockIds, right, sMiddle, s1, t0, t1); +00554 } +00555 <font class="keywordflow">else</font> +00556 { +00557 <font class="comment">// subdivide.</font> +00558 CBezierPatch top, bottom; +00559 pa.subdivideT(top, bottom); +00560 uint8 tMiddle= (uint8)( ((uint)t0+(uint)t1) /2 ); +00561 <font class="comment">// recurs top.</font> +00562 <a class="code" href="classNL3D_1_1CPatch.html#z683_3">addPatchBlocksInBBoxRecurs</a>(paId, bbox, paBlockIds, top, s0, s1, t0, tMiddle); +00563 <font class="comment">// recurs bottom.</font> +00564 <a class="code" href="classNL3D_1_1CPatch.html#z683_3">addPatchBlocksInBBoxRecurs</a>(paId, bbox, paBlockIds, bottom, s0, s1, tMiddle, t1); +00565 } +00566 } +00567 +00568 } +00569 +00570 +00571 <font class="comment">// ***************************************************************************</font> +<a name="l00572"></a><a class="code" href="classNL3D_1_1CPatch.html#z670_3">00572</a> CVector CPatch::getTesselatedPos(CUV uv)<font class="keyword"> const</font> +00573 <font class="keyword"></font>{ +00574 <font class="comment">// clamp values.</font> +00575 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(uv.U, 0, 1); +00576 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(uv.V, 0, 1); +00577 <font class="comment">// recurs down the 2 sons.</font> +00578 CVector ret= CVector::Null; +00579 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->getTesselatedPos(uv, <font class="keyword">true</font>, ret); +00580 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->getTesselatedPos(uv, <font class="keyword">true</font>, ret); +00581 +00582 <font class="keywordflow">return</font> ret; +00583 } +00584 +00585 +00586 <font class="comment">// ***************************************************************************</font> +00587 <font class="comment">// ***************************************************************************</font> +00588 <font class="comment">// RENDER LIST.</font> +00589 <font class="comment">// ***************************************************************************</font> +00590 <font class="comment">// ***************************************************************************</font> +00591 +00592 +00593 <font class="comment">// ***************************************************************************</font> +<a name="l00594"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_3">00594</a> <font class="keywordtype">void</font> CPatch::addRefTessBlocks() +00595 { +00596 uint i; +00597 +00598 <a class="code" href="classNL3D_1_1CPatch.html#z678_2">TessBlockRefCount</a>++; +00599 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>.size()==0) +00600 { +00601 <font class="comment">// Allocate the tessblocks.</font> +00602 <font class="comment">//==========</font> +00603 +00604 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="tess__block_8h.html#a1">NL3D_TESSBLOCK_TILESIZE</a>==4); +00605 <font class="comment">// A tessblock is 2*2 tiles.</font> +00606 sint os= <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>>1; +00607 sint ot= <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>>>1; +00608 <a class="code" href="debug_8h.html#a6">nlassert</a>(os>0); +00609 <a class="code" href="debug_8h.html#a6">nlassert</a>(ot>0); +00610 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>.resize(os*ot); +00611 <font class="comment">// init all tessBlocks with the Patch ptr.</font> +00612 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>.size(); i++) +00613 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[i].init(<font class="keyword">this</font>); +00614 +00615 +00616 +00617 <font class="comment">// Vegetable management</font> +00618 <font class="comment">//==========</font> +00619 CVegetableManager *vegetableManager= <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->_VegetableManager; +00620 +00621 <font class="comment">// Create ClipBlocks.</font> +00622 uint nTbPerCb= <a class="code" href="patch_8h.html#a13">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK</a>; +00623 uint wCB= (os + nTbPerCb-1) >> <a class="code" href="patch_8h.html#a12">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT</a>; +00624 uint hCB= (ot + nTbPerCb-1) >> <a class="code" href="patch_8h.html#a12">NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT</a>; +00625 <a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>.resize(wCB * hCB); +00626 <font class="comment">// allocate ClipBlocks</font> +00627 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>.size(); i++) +00628 { +00629 <a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>[i]= vegetableManager->createClipBlock(); +00630 } +00631 +00632 +00633 <font class="comment">// updateLighting management.</font> +00634 <font class="comment">//==========</font> +00635 <font class="comment">// append patch for Near updateLighting, since TessBlock lightmap may/will exist.</font> +00636 <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->linkPatchToNearUL(<font class="keyword">this</font>); +00637 } +00638 } +00639 +00640 <font class="comment">// ***************************************************************************</font> +<a name="l00641"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_4">00641</a> <font class="keywordtype">void</font> CPatch::decRefTessBlocks() +00642 { +00643 <a class="code" href="classNL3D_1_1CPatch.html#z678_2">TessBlockRefCount</a>--; +00644 <font class="comment">// If no loinger need the tessblocks, delete them.</font> +00645 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#z678_2">TessBlockRefCount</a>==0) +00646 <a class="code" href="classNL3D_1_1CPatch.html#z680_2">clearTessBlocks</a>(); +00647 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_2">TessBlockRefCount</a>>=0); +00648 } +00649 +00650 +00651 <font class="comment">// ***************************************************************************</font> +<a name="l00652"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_2">00652</a> <font class="keywordtype">void</font> CPatch::clearTessBlocks() +00653 { +00654 uint i; +00655 +00656 <font class="comment">// Vegetable management</font> +00657 <font class="comment">//==========</font> +00658 <font class="comment">// if compiled.</font> +00659 <font class="keywordflow">if</font>(Zone) +00660 { +00661 CVegetableManager *vegetableManager= <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->_VegetableManager; +00662 +00663 <font class="comment">// delete still existing vegetable Igs.</font> +00664 <a class="code" href="classNL3D_1_1CPatch.html#z674_0">deleteAllVegetableIgs</a>(); +00665 +00666 <font class="comment">// delete ClipBlocks.</font> +00667 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>.size(); i++) +00668 { +00669 vegetableManager->deleteClipBlock(<a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>[i]); +00670 } +00671 <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CPatch.html#z679_0">VegetableClipBlocks</a>); +00672 } +00673 +00674 +00675 <font class="comment">// updateLighting management.</font> +00676 <font class="comment">//==========</font> +00677 <font class="keywordflow">if</font>(Zone) +00678 { +00679 <font class="comment">// remove patch from Near updateLighting, since no more TessBlock lightmap can exist.</font> +00680 <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->unlinkPatchFromNearUL(<font class="keyword">this</font>); +00681 } +00682 +00683 +00684 <font class="comment">// Delete TessBlocks</font> +00685 <font class="comment">//==========</font> +00686 <a class="code" href="classNL3D_1_1CPatch.html#z678_2">TessBlockRefCount</a>=0; +00687 <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>); +00688 } +00689 +00690 +00691 <font class="comment">// ***************************************************************************</font> +<a name="l00692"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_1">00692</a> <font class="keywordtype">void</font> CPatch::resetMasterBlock() +00693 { +00694 <font class="comment">// We should be not visible so FaceVector no more exist.</font> +00695 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>); +00696 +00697 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FarVertexList.clear(); +00698 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FarFaceList.clear(); +00699 <a class="code" href="classNL3D_1_1CPatch.html#z678_3">NumRenderableFaces</a>= 0; +00700 <font class="comment">// no tiles should be here!!</font> +00701 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.NearVertexList.size()==0); +00702 } +00703 +00704 <font class="comment">// ***************************************************************************</font> +<a name="l00705"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_5">00705</a> uint CPatch::getNumTessBlock(CTessFace *face) +00706 { +00707 <font class="comment">// To which tessBlocks link the face?</font> +00708 <font class="comment">// compute an approx middle of the face.</font> +00709 CParamCoord edgeMid(face->PVLeft, face->PVRight); +00710 CParamCoord middle(edgeMid, face->PVBase); +00711 <font class="comment">// Coordinate of the tessblock (2*2 a tile!! so the >>1).</font> +00712 uint ts= ((uint)middle.S * (uint)(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>>1)) / 0x8000; +00713 uint tt= ((uint)middle.T * (uint)(<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>>>1)) / 0x8000; +00714 uint numtb= tt*(uint)(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>>1) + ts; +00715 +00716 <font class="keywordflow">return</font> numtb; +00717 } +00718 +00719 +00720 <font class="comment">// ***************************************************************************</font> +<a name="l00721"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_6">00721</a> <font class="keywordtype">void</font> CPatch::getNumTessBlock(CParamCoord pc, TFarVertType &<a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>, uint &numtb) +00722 { +00723 uint tboS= (uint)(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>>1); +00724 uint tboT= (uint)(<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>>>1); +00725 +00726 <font class="comment">// Coordinate of the tessblock (2*2 a tile!! so the >>1).</font> +00727 uint ts= ((uint)pc.S * tboS) / 0x8000; +00728 uint tt= ((uint)pc.T * tboT) / 0x8000; +00729 numtb= tt*tboS + ts; +00730 +00731 <font class="keywordtype">bool</font> edgeS= (ts*0x8000) == ((uint)pc.S * tboS); +00732 <font class="keywordtype">bool</font> edgeT= (tt*0x8000) == ((uint)pc.T * tboT); +00733 +00734 <font class="comment">// Does this vertex lies on a corner of a TessBlock?</font> +00735 <font class="keywordflow">if</font>(edgeS && edgeT) +00736 <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>= <a class="code" href="classNL3D_1_1CPatch.html#z680_0u0">FVMasterBlock</a>; +00737 <font class="comment">// Does this vertex lies on a edge of a TessBlock?</font> +00738 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(edgeS || edgeT) +00739 <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>= <a class="code" href="classNL3D_1_1CPatch.html#z680_0u2">FVTessBlockEdge</a>; +00740 <font class="comment">// Else it lies exclusively IN a TessBlock.</font> +00741 <font class="keywordflow">else</font> +00742 <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>= <a class="code" href="classNL3D_1_1CPatch.html#z680_0u1">FVTessBlock</a>; +00743 +00744 } +00745 +00746 +00747 +00748 <font class="comment">// ***************************************************************************</font> +<a name="l00749"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_12">00749</a> <font class="keywordtype">void</font> CPatch::extendTessBlockWithEndPos(CTessFace *face) +00750 { +00751 <font class="keywordflow">if</font>(face->Level>=<a class="code" href="classNL3D_1_1CPatch.html#o5">TessBlockLimitLevel</a>) +00752 { +00753 <font class="comment">// get the tessBlock of the face.</font> +00754 uint numtb= <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(face); +00755 +00756 <font class="comment">// Must enlarge the BSphere of the tesblock!!</font> +00757 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereFirst(face->VBase->EndPos); +00758 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VLeft->EndPos); +00759 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VRight->EndPos); +00760 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereCompile(); +00761 } +00762 } +00763 +00764 +00765 <font class="comment">// ***************************************************************************</font> +<a name="l00766"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_7">00766</a> <font class="keywordtype">void</font> CPatch::dirtTessBlockFaceVector(CTessBlock &tb) +00767 { +00768 <font class="comment">// If patch is visible, block's faceVector should exist, but are no more valid.</font> +00769 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>) +00770 { +00771 <font class="comment">// If this tessBlock not already notified to modification.</font> +00772 <font class="keywordflow">if</font>(!tb.isInModifyList()) +00773 { +00774 <font class="comment">// Then append, and delete all FaceVector.</font> +00775 <font class="comment">// NB: delete FaceVector now, because the TessBlock himself may disapear soon.</font> +00776 tb.appendToModifyListAndDeleteFaceVector(<a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->_TessBlockModificationRoot, <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->_FaceVectorManager); +00777 } +00778 } +00779 } +00780 +00781 +00782 <font class="comment">// ***************************************************************************</font> +<a name="l00783"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_8">00783</a> <font class="keywordtype">void</font> CPatch::appendFaceToRenderList(CTessFace *face) +00784 { +00785 <font class="comment">// Update the number of renderable Faces</font> +00786 <a class="code" href="classNL3D_1_1CPatch.html#z678_3">NumRenderableFaces</a>++; +00787 +00788 <font class="comment">// Update Gnal render.</font> +00789 <font class="comment">//====================</font> +00790 <font class="keywordflow">if</font>(face->Level<<a class="code" href="classNL3D_1_1CPatch.html#o5">TessBlockLimitLevel</a>) +00791 { +00792 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FarFaceList.append(face); +00793 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FaceTileMaterialRefCount++; +00794 +00795 <font class="comment">// The facelist is modified, so we must update the faceVector, if visible.</font> +00796 <a class="code" href="classNL3D_1_1CPatch.html#z680_7">dirtTessBlockFaceVector</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>); +00797 } +00798 <font class="keywordflow">else</font> +00799 { +00800 <font class="comment">// Alloc if necessary the TessBlocks.</font> +00801 <a class="code" href="classNL3D_1_1CPatch.html#z680_3">addRefTessBlocks</a>(); +00802 +00803 <font class="comment">// link the face to the good tessblock.</font> +00804 uint numtb= <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(face); +00805 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FarFaceList.append(face); +00806 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FaceTileMaterialRefCount++; +00807 +00808 <font class="comment">// The facelist is modified, so we must update the faceVector, if visible.</font> +00809 <a class="code" href="classNL3D_1_1CPatch.html#z680_7">dirtTessBlockFaceVector</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb]); +00810 +00811 <font class="comment">// Must enlarge the BSphere of the tesblock!!</font> +00812 <font class="comment">// We must do it on a per-face approach, because of tessblocks 's corners which are outside of tessblocks.</font> +00813 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereFirst(face->VBase->EndPos); +00814 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VLeft->EndPos); +00815 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VRight->EndPos); +00816 <font class="comment">// I think this should be done too on StartPos, for geomorph (rare??...) problems.</font> +00817 <font class="comment">// \todo yoyo: is this necessary???</font> +00818 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VBase->StartPos); +00819 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VLeft->StartPos); +00820 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereAdd(face->VRight->StartPos); +00821 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].extendSphereCompile(); +00822 +00823 +00824 <font class="comment">// Update Tile render (no need to do it if face not at least at tessblock level).</font> +00825 <a class="code" href="classNL3D_1_1CPatch.html#z680_10">appendFaceToTileRenderList</a>(face); +00826 } +00827 } +00828 +00829 +00830 <font class="comment">// ***************************************************************************</font> +<a name="l00831"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_9">00831</a> <font class="keywordtype">void</font> CPatch::removeFaceFromRenderList(CTessFace *face) +00832 { +00833 <font class="comment">// Update the number of renderable Faces</font> +00834 <a class="code" href="classNL3D_1_1CPatch.html#z678_3">NumRenderableFaces</a>--; +00835 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_3">NumRenderableFaces</a>>=0); +00836 +00837 <font class="comment">// Update Gnal render.</font> +00838 <font class="comment">//====================</font> +00839 <font class="keywordflow">if</font>(face->Level<<a class="code" href="classNL3D_1_1CPatch.html#o5">TessBlockLimitLevel</a>) +00840 { +00841 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FarFaceList.remove(face); +00842 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FaceTileMaterialRefCount--; +00843 +00844 <font class="comment">// The facelist is modified, so we must update the faceVector, if visible.</font> +00845 <a class="code" href="classNL3D_1_1CPatch.html#z680_7">dirtTessBlockFaceVector</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>); +00846 } +00847 <font class="keywordflow">else</font> +00848 { +00849 <font class="comment">// link the face to the good tessblock.</font> +00850 uint numtb= <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(face); +00851 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FarFaceList.remove(face); +00852 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FaceTileMaterialRefCount--; +00853 +00854 <font class="comment">// The facelist is modified, so we must update the faceVector, if visible.</font> +00855 <a class="code" href="classNL3D_1_1CPatch.html#z680_7">dirtTessBlockFaceVector</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb]); +00856 +00857 <font class="comment">// Update Tile render (no need to do it if face not at least at tessblock level).</font> +00858 <a class="code" href="classNL3D_1_1CPatch.html#z680_11">removeFaceFromTileRenderList</a>(face); +00859 +00860 <font class="comment">// Destroy if necessary the TessBlocks.</font> +00861 <a class="code" href="classNL3D_1_1CPatch.html#z680_4">decRefTessBlocks</a>(); +00862 } +00863 } +00864 +00865 +00866 <font class="comment">// ***************************************************************************</font> +<a name="l00867"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_10">00867</a> <font class="keywordtype">void</font> CPatch::appendFaceToTileRenderList(CTessFace *face) +00868 { +00869 <font class="keywordflow">if</font>(face->TileMaterial) +00870 { +00871 <font class="comment">// For all valid faces, update their links.</font> +00872 <font class="comment">// Do not do this for lightmap, since it use same face from RGB0 pass.</font> +00873 <font class="keywordflow">for</font>(sint i=0;i<<a class="code" href="landscape__def_8h.html#a1">NL3D_MAX_TILE_FACE</a>;i++) +00874 { +00875 CPatchRdrPass *tilePass= face->TileMaterial->Pass[i].PatchRdrPass; +00876 <font class="comment">// If tile i enabled.</font> +00877 <font class="keywordflow">if</font>(tilePass) +00878 { +00879 <font class="comment">// a face should have created for this pass.</font> +00880 <a class="code" href="debug_8h.html#a6">nlassert</a>(face->TileFaces[i]); +00881 face->TileMaterial->TileFaceList[i].append(face->TileFaces[i]); +00882 } +00883 } +00884 +00885 <font class="comment">// The facelist is modified, so we must update the faceVector, if visible.</font> +00886 uint numtb= <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(face); +00887 <a class="code" href="classNL3D_1_1CPatch.html#z680_7">dirtTessBlockFaceVector</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb]); +00888 } +00889 } +00890 +00891 +00892 <font class="comment">// ***************************************************************************</font> +<a name="l00893"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_11">00893</a> <font class="keywordtype">void</font> CPatch::removeFaceFromTileRenderList(CTessFace *face) +00894 { +00895 <font class="keywordflow">if</font>(face->TileMaterial) +00896 { +00897 <font class="comment">// For all valid faces, update their links.</font> +00898 <font class="comment">// Do not do this for lightmap, since it use same face from RGB0 pass.</font> +00899 <font class="keywordflow">for</font>(sint i=0;i<<a class="code" href="landscape__def_8h.html#a1">NL3D_MAX_TILE_FACE</a>;i++) +00900 { +00901 CPatchRdrPass *tilePass= face->TileMaterial->Pass[i].PatchRdrPass; +00902 <font class="comment">// If tile i enabled.</font> +00903 <font class="keywordflow">if</font>(tilePass) +00904 { +00905 <font class="comment">// a face should have created for this pass.</font> +00906 <a class="code" href="debug_8h.html#a6">nlassert</a>(face->TileFaces[i]); +00907 face->TileMaterial->TileFaceList[i].remove(face->TileFaces[i]); +00908 } +00909 } +00910 +00911 <font class="comment">// The facelist is modified, so we must update the faceVector, if visible.</font> +00912 uint numtb= <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(face); +00913 <a class="code" href="classNL3D_1_1CPatch.html#z680_7">dirtTessBlockFaceVector</a>(<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb]); +00914 } +00915 } +00916 +00917 +00918 <font class="comment">// ***************************************************************************</font> +<a name="l00919"></a><a class="code" href="classNL3D_1_1CPatch.html#c35">00919</a> <font class="keywordtype">void</font> CPatch::computeTbTm(uint &numtb, uint &numtm, uint ts, uint tt) +00920 { +00921 sint is= ts&1; +00922 sint it= tt&1; +00923 ts>>=1; +00924 tt>>=1; +00925 +00926 numtb= tt*(uint)(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>>1) + ts; +00927 numtm= it*2+is; +00928 } +00929 +00930 +00931 <font class="comment">// ***************************************************************************</font> +<a name="l00932"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_13">00932</a> <font class="keywordtype">void</font> CPatch::appendTileMaterialToRenderList(CTileMaterial *tm) +00933 { +00934 <a class="code" href="debug_8h.html#a6">nlassert</a>(tm); +00935 +00936 <font class="comment">// Alloc if necessary the TessBlocks.</font> +00937 <a class="code" href="classNL3D_1_1CPatch.html#z680_3">addRefTessBlocks</a>(); +00938 +00939 uint numtb, numtm; +00940 <a class="code" href="classNL3D_1_1CPatch.html#c35">computeTbTm</a>(numtb, numtm, tm->TileS, tm->TileT); +00941 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].RdrTileRoot[numtm]= tm; +00942 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FaceTileMaterialRefCount++; +00943 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].TileMaterialRefCount++; +00944 <font class="comment">// The master block contains the whole patch TileMaterialRefCount</font> +00945 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.TileMaterialRefCount++; +00946 +00947 <font class="comment">// DynamicLighting. When in near, must compute the context, to have good UVs.</font> +00948 <font class="comment">//==========</font> +00949 <font class="comment">// inc ref to the context, creating it if needed.</font> +00950 <a class="code" href="classNL3D_1_1CPatch.html#z688_0">addRefDLMContext</a>(); +00951 <font class="comment">// NB: do it before creating the vegetableBlock, because vegetables use DLM Uvs.</font> +00952 +00953 <font class="comment">// if was no tiles before in this tessBlock, create a Vegetable block.</font> +00954 <font class="comment">//==========</font> +00955 <font class="comment">// one Tile <=> was 0 before</font> +00956 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].TileMaterialRefCount == 1 && <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->isVegetableActive() ) +00957 { +00958 <a class="code" href="classNL3D_1_1CPatch.html#z686_0">createVegetableBlock</a>(numtb, tm->TileS, tm->TileT); +00959 } +00960 +00961 } +00962 <font class="comment">// ***************************************************************************</font> +<a name="l00963"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_14">00963</a> <font class="keywordtype">void</font> CPatch::removeTileMaterialFromRenderList(CTileMaterial *tm) +00964 { +00965 <a class="code" href="debug_8h.html#a6">nlassert</a>(tm); +00966 +00967 uint numtb, numtm; +00968 <a class="code" href="classNL3D_1_1CPatch.html#c35">computeTbTm</a>(numtb, numtm, tm->TileS, tm->TileT); +00969 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].RdrTileRoot[numtm]= NULL; +00970 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FaceTileMaterialRefCount--; +00971 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].TileMaterialRefCount--; +00972 <font class="comment">// The master block contains the whole patch TileMaterialRefCount</font> +00973 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.TileMaterialRefCount--; +00974 +00975 <font class="comment">// if no more tiles in this tessBlock, delete the vegetable Block.</font> +00976 <font class="comment">//==========</font> +00977 <font class="comment">// if no more tiles in this tessBlock</font> +00978 <font class="keywordflow">if</font>( <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].TileMaterialRefCount==0 ) +00979 { +00980 <font class="comment">// release the vegetableBlock (if any)</font> +00981 <a class="code" href="classNL3D_1_1CPatch.html#z686_1">releaseVegetableBlock</a>(numtb); +00982 } +00983 +00984 <font class="comment">// Destroy if necessary the TessBlocks.</font> +00985 <a class="code" href="classNL3D_1_1CPatch.html#z680_4">decRefTessBlocks</a>(); +00986 +00987 <font class="comment">// DynamicLighting. When in near, must compute the context, to have good UVs.</font> +00988 <font class="comment">//==========</font> +00989 <font class="comment">// dec ref the context, deleting it if needed.</font> +00990 <a class="code" href="classNL3D_1_1CPatch.html#z688_1">decRefDLMContext</a>(); +00991 } +00992 +00993 +00994 <font class="comment">// ***************************************************************************</font> +<a name="l00995"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_15">00995</a> <font class="keywordtype">void</font> CPatch::appendFarVertexToRenderList(CTessFarVertex *fv) +00996 { +00997 <a class="code" href="classNL3D_1_1CPatch.html#z680_0">TFarVertType</a> <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>; +00998 uint numtb; +00999 <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(fv->PCoord, <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>, numtb); +01000 +01001 +01002 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>==<a class="code" href="classNL3D_1_1CPatch.html#z680_0u0">FVMasterBlock</a> || <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>==<a class="code" href="classNL3D_1_1CPatch.html#z680_0u2">FVTessBlockEdge</a>) +01003 { +01004 fv->OwnerBlock= &<a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>; +01005 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FarVertexList.append(fv); +01006 } +01007 <font class="keywordflow">else</font> +01008 { +01009 <font class="comment">// Alloc if necessary the TessBlocks.</font> +01010 <a class="code" href="classNL3D_1_1CPatch.html#z680_3">addRefTessBlocks</a>(); +01011 +01012 fv->OwnerBlock= &<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb]; +01013 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FarVertexList.append(fv); +01014 } +01015 } +01016 <font class="comment">// ***************************************************************************</font> +<a name="l01017"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_16">01017</a> <font class="keywordtype">void</font> CPatch::removeFarVertexFromRenderList(CTessFarVertex *fv) +01018 { +01019 <a class="code" href="classNL3D_1_1CPatch.html#z680_0">TFarVertType</a> <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>; +01020 uint numtb; +01021 <a class="code" href="classNL3D_1_1CPatch.html#z680_5">getNumTessBlock</a>(fv->PCoord, <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>, numtb); +01022 +01023 +01024 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>==<a class="code" href="classNL3D_1_1CPatch.html#z680_0u0">FVMasterBlock</a> || <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>==<a class="code" href="classNL3D_1_1CPatch.html#z680_0u2">FVTessBlockEdge</a>) +01025 { +01026 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.FarVertexList.remove(fv); +01027 fv->OwnerBlock= NULL; +01028 } +01029 <font class="keywordflow">else</font> +01030 { +01031 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].FarVertexList.remove(fv); +01032 fv->OwnerBlock= NULL; +01033 +01034 <font class="comment">// Destroy if necessary the TessBlocks.</font> +01035 <a class="code" href="classNL3D_1_1CPatch.html#z680_4">decRefTessBlocks</a>(); +01036 } +01037 } +01038 +01039 +01040 <font class="comment">// ***************************************************************************</font> +<a name="l01041"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_17">01041</a> <font class="keywordtype">void</font> CPatch::appendNearVertexToRenderList(CTileMaterial *tileMat, CTessNearVertex *nv) +01042 { +01043 <a class="code" href="debug_8h.html#a6">nlassert</a>(tileMat); +01044 +01045 <font class="comment">// Alloc if necessary the TessBlocks.</font> +01046 <a class="code" href="classNL3D_1_1CPatch.html#z680_3">addRefTessBlocks</a>(); +01047 +01048 uint numtb, numtm; +01049 <a class="code" href="classNL3D_1_1CPatch.html#c35">computeTbTm</a>(numtb, numtm, tileMat->TileS, tileMat->TileT); +01050 nv->OwnerBlock= &<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb]; +01051 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].NearVertexList.append(nv); +01052 } +01053 <font class="comment">// ***************************************************************************</font> +<a name="l01054"></a><a class="code" href="classNL3D_1_1CPatch.html#z680_18">01054</a> <font class="keywordtype">void</font> CPatch::removeNearVertexFromRenderList(CTileMaterial *tileMat, CTessNearVertex *nv) +01055 { +01056 <a class="code" href="debug_8h.html#a6">nlassert</a>(tileMat); +01057 +01058 uint numtb, numtm; +01059 <a class="code" href="classNL3D_1_1CPatch.html#c35">computeTbTm</a>(numtb, numtm, tileMat->TileS, tileMat->TileT); +01060 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[numtb].NearVertexList.remove(nv); +01061 nv->OwnerBlock= NULL; +01062 +01063 <font class="comment">// Destroy if necessary the TessBlocks.</font> +01064 <a class="code" href="classNL3D_1_1CPatch.html#z680_4">decRefTessBlocks</a>(); +01065 } +01066 +01067 +01068 +01069 <font class="comment">// ***************************************************************************</font> +01070 <font class="comment">// ***************************************************************************</font> +01071 <font class="comment">// BASIC BUILD.</font> +01072 <font class="comment">// ***************************************************************************</font> +01073 <font class="comment">// ***************************************************************************</font> +01074 +01075 +01076 +01077 +01078 <font class="comment">// ***************************************************************************</font> +<a name="l01079"></a><a class="code" href="classNL3D_1_1CPatch.html#c4">01079</a> <font class="keywordtype">void</font> CPatch::makeRoots() +01080 { +01081 CTessVertex *a= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]; +01082 CTessVertex *b= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]; +01083 CTessVertex *c= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]; +01084 CTessVertex *d= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]; +01085 +01086 <font class="comment">// Set positions.</font> +01087 a->Pos= a->StartPos= a->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,0); +01088 b->Pos= b->StartPos= b->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,1); +01089 c->Pos= c->StartPos= c->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,1); +01090 d->Pos= d->StartPos= d->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,0); +01091 +01092 <font class="comment">// Init Far vetices.</font> +01093 CTessFarVertex *fa= &<a class="code" href="classNL3D_1_1CPatch.html#o12">BaseFarVertices</a>[0]; +01094 CTessFarVertex *fb= &<a class="code" href="classNL3D_1_1CPatch.html#o12">BaseFarVertices</a>[1]; +01095 CTessFarVertex *fc= &<a class="code" href="classNL3D_1_1CPatch.html#o12">BaseFarVertices</a>[2]; +01096 CTessFarVertex *fd= &<a class="code" href="classNL3D_1_1CPatch.html#o12">BaseFarVertices</a>[3]; +01097 fa->Src= a; +01098 fa->PCoord.setST(0,0); +01099 fb->Src= b; +01100 fb->PCoord.setST(0,1); +01101 fc->Src= c; +01102 fc->PCoord.setST(1,1); +01103 fd->Src= d; +01104 fd->PCoord.setST(1,0); +01105 +01106 <font class="comment">// We don't have to fill the Far vertices VB here, because this patch is still not visible.</font> +01107 <font class="comment">// NB: we can't because we don't have any driver here.</font> +01108 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>==<font class="keyword">true</font>); +01109 +01110 +01111 <font class="comment">// Make Roots.</font> +01112 <font class="comment">/*</font> +01113 <font class="comment"> Tesselation layout. For Square Face, and if OrderS>=OrderT.</font> +01114 <font class="comment"></font> +01115 <font class="comment"> A-------D</font> +01116 <font class="comment"> |\ Son1 |</font> +01117 <font class="comment"> | \ |</font> +01118 <font class="comment"> | \ |</font> +01119 <font class="comment"> | Son0 \|</font> +01120 <font class="comment"> B-------C</font> +01121 <font class="comment"></font> +01122 <font class="comment"> For rectangles whith OrderT>OrderS. It is VERY IMPORTANT, for splitRectangular() reasons.</font> +01123 <font class="comment"></font> +01124 <font class="comment"> A-------D</font> +01125 <font class="comment"> | Son0 /|</font> +01126 <font class="comment"> | / |</font> +01127 <font class="comment"> | / |</font> +01128 <font class="comment"> |/ Son1 |</font> +01129 <font class="comment"> B-------C</font> +01130 <font class="comment"></font> +01131 <font class="comment"> */</font> +01132 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>==NULL); +01133 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>==NULL); +01134 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>= <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->newTessFace(); +01135 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>= <a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->newTessFace(); +01136 +01137 <font class="comment">// Son0.</font> +01138 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->Patch= <font class="keyword">this</font>; +01139 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->Level= 0; +01140 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>=<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) +01141 { +01142 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VBase= b; +01143 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VLeft= c; +01144 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VRight= a; +01145 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVBase= fb; +01146 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVLeft= fc; +01147 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVRight= fa; +01148 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->PVBase.setST(0, 1); +01149 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->PVLeft.setST(1, 1); +01150 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->PVRight.setST(0, 0); +01151 } +01152 <font class="keywordflow">else</font> +01153 { +01154 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VBase= a; +01155 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VLeft= b; +01156 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VRight= d; +01157 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVBase= fa; +01158 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVLeft= fb; +01159 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVRight= fd; +01160 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->PVBase.setST(0, 0); +01161 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->PVLeft.setST(0, 1); +01162 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->PVRight.setST(1, 0); +01163 } +01164 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FBase= <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>; +01165 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FLeft= NULL; +01166 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FRight= NULL; +01167 <font class="comment">// No tile info.</font> +01168 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->Size= <a class="code" href="classNL3D_1_1CPatch.html#o8">ErrorSize</a>/2; +01169 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->computeSplitPoint(); +01170 +01171 <font class="comment">// Son1.</font> +01172 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->Patch= <font class="keyword">this</font>; +01173 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->Level= 0; +01174 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>=<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) +01175 { +01176 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VBase= d; +01177 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VLeft= a; +01178 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VRight= c; +01179 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVBase= fd; +01180 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVLeft= fa; +01181 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVRight= fc; +01182 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->PVBase.setST(1, 0); +01183 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->PVLeft.setST(0, 0); +01184 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->PVRight.setST(1, 1); +01185 } +01186 <font class="keywordflow">else</font> +01187 { +01188 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VBase= c; +01189 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VLeft= d; +01190 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VRight= b; +01191 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVBase= fc; +01192 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVLeft= fd; +01193 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVRight= fb; +01194 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->PVBase.setST(1, 1); +01195 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->PVLeft.setST(1, 0); +01196 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->PVRight.setST(0, 1); +01197 } +01198 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FBase= <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>; +01199 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FLeft= NULL; +01200 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FRight= NULL; +01201 <font class="comment">// No tile info.</font> +01202 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->Size= <a class="code" href="classNL3D_1_1CPatch.html#o8">ErrorSize</a>/2; +01203 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->computeSplitPoint(); +01204 +01205 +01206 <font class="comment">// Prepare the render list...</font> +01207 <a class="code" href="classNL3D_1_1CPatch.html#z680_2">clearTessBlocks</a>(); +01208 <a class="code" href="classNL3D_1_1CPatch.html#z680_1">resetMasterBlock</a>(); +01209 <a class="code" href="classNL3D_1_1CPatch.html#z680_15">appendFarVertexToRenderList</a>(fa); +01210 <a class="code" href="classNL3D_1_1CPatch.html#z680_15">appendFarVertexToRenderList</a>(fb); +01211 <a class="code" href="classNL3D_1_1CPatch.html#z680_15">appendFarVertexToRenderList</a>(fc); +01212 <a class="code" href="classNL3D_1_1CPatch.html#z680_15">appendFarVertexToRenderList</a>(fd); +01213 <a class="code" href="classNL3D_1_1CPatch.html#z680_8">appendFaceToRenderList</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>); +01214 <a class="code" href="classNL3D_1_1CPatch.html#z680_8">appendFaceToRenderList</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01215 +01216 <font class="comment">// Usefull for geomorph: Init 2 root faces MaxNearLimit, and MaxFaceSize</font> +01217 <font class="comment">// NB: since no geomorph is made on endpoints (StartPos==EndPos) of patchs, this is not usefull.</font> +01218 <font class="comment">// but it is important to ensure the VP or software geomorph won't crash with bad float values.</font> +01219 <font class="comment">// Init MaxFaceSize.</font> +01220 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VBase->MaxFaceSize= 1; +01221 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VLeft->MaxFaceSize= 1; +01222 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VRight->MaxFaceSize= 1; +01223 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VBase->MaxFaceSize= 1; +01224 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VLeft->MaxFaceSize= 1; +01225 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VRight->MaxFaceSize= 1; +01226 <font class="comment">// Init MaxNearLimit.</font> +01227 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VBase->MaxNearLimit= 1; +01228 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VLeft->MaxNearLimit= 1; +01229 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VRight->MaxNearLimit= 1; +01230 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VBase->MaxNearLimit= 1; +01231 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VLeft->MaxNearLimit= 1; +01232 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VRight->MaxNearLimit= 1; +01233 +01234 } +01235 +01236 +01237 <font class="comment">// ***************************************************************************</font> +<a name="l01238"></a><a class="code" href="classNL3D_1_1CPatch.html#a2">01238</a> <font class="keywordtype">void</font> CPatch::compile(CZone *<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>, uint patchId, uint8 orderS, uint8 orderT, CTessVertex *baseVertices[4], <font class="keywordtype">float</font> errorSize) +01239 { +01240 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>); +01241 <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a>; +01242 +01243 <font class="comment">// For updateLighting, get the correct pointer now.</font> +01244 <font class="comment">// Init UL circular list to me</font> +01245 <a class="code" href="classNL3D_1_1CPatch.html#z687_0">_ULNearPrec</a>= <font class="keyword">this</font>; +01246 <a class="code" href="classNL3D_1_1CPatch.html#z687_1">_ULNearNext</a>= <font class="keyword">this</font>; +01247 +01248 +01249 <font class="comment">// Once the patch is inserted and compiled in a zone, it is ready to be rendered.</font> +01250 <font class="comment">// So now fill the Patch info in render pass.</font> +01251 <a class="code" href="classNL3D_1_1CPatch.html#o28">Pass0</a>.Patch= <font class="keyword">this</font>; +01252 <a class="code" href="classNL3D_1_1CPatch.html#o29">Pass1</a>.Patch= <font class="keyword">this</font>; +01253 +01254 <font class="comment">// init also the MasterBlock.</font> +01255 <a class="code" href="classNL3D_1_1CPatch.html#z678_0">MasterBlock</a>.init(<font class="keyword">this</font>); +01256 +01257 <font class="comment">// only 65536 patch per zone allowed.</font> +01258 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchId<0x10000); +01259 <a class="code" href="classNL3D_1_1CPatch.html#o1">PatchId</a>= (uint16)patchId; +01260 +01261 <font class="keywordflow">if</font>(errorSize==0) +01262 <a class="code" href="classNL3D_1_1CPatch.html#c3">computeDefaultErrorSize</a>(); +01263 <font class="keywordflow">else</font> +01264 <a class="code" href="classNL3D_1_1CPatch.html#o8">ErrorSize</a>= errorSize; +01265 +01266 <a class="code" href="debug_8h.html#a6">nlassert</a>(orderS==2 || orderS==4 || orderS==8 || orderS==16); +01267 <a class="code" href="debug_8h.html#a6">nlassert</a>(orderT==2 || orderT==4 || orderT==8 || orderT==16); +01268 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>==orderS); +01269 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>==orderT); +01270 +01271 <font class="comment">// Compile additional infos.</font> +01272 sint ps= <a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a>(orderS) , pt= <a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a>(orderT); +01273 sint pmin= <a class="code" href="bit__set_8cpp.html#a0">min</a>(ps,pt); +01274 sint pmax= max(ps,pt); +01275 <font class="comment">// Rectangular patch OK.</font> +01276 <font class="comment">// Work, since patch 1xX are illegal. => The TileLimitLevel is at least 2 level distant from the time where</font> +01277 <font class="comment">// the rectangular patch is said "un-rectangular-ed" (tesselation looks like square). Hence, there is no problem</font> +01278 <font class="comment">// with rectangular UV geomorph (well don't bother me, make a draw :) ).</font> +01279 <a class="code" href="classNL3D_1_1CPatch.html#o6">TileLimitLevel</a>= pmin*2 + pmax-pmin; +01280 <font class="comment">// A TessBlock is a 2*2 tile. This simple formula works because patch 1xX are illegal.</font> +01281 <a class="code" href="classNL3D_1_1CPatch.html#o5">TessBlockLimitLevel</a>= <a class="code" href="classNL3D_1_1CPatch.html#o6">TileLimitLevel</a>-2; +01282 <font class="comment">// This tell us when the tess face is "un-rectangular-ed" (to say a square). Before, it is a "rectangular" face, </font> +01283 <font class="comment">// which has a strange fxxxxxg split.</font> +01284 <font class="comment">// If patch is square, then SquareLimitLevel=0 (ok!!).</font> +01285 <a class="code" href="classNL3D_1_1CPatch.html#o7">SquareLimitLevel</a>= pmax-pmin; +01286 +01287 <font class="comment">// Buil the BSPhere.</font> +01288 CAABBox bb= <a class="code" href="classNL3D_1_1CPatch.html#a14">buildBBox</a>(); +01289 <a class="code" href="classNL3D_1_1CPatch.html#o13">BSphere</a>.Center= bb.getCenter(); +01290 <a class="code" href="classNL3D_1_1CPatch.html#o13">BSphere</a>.Radius= bb.getRadius(); +01291 +01292 <font class="comment">// Bind vertices, to zone base vertices.</font> +01293 <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]= baseVertices[0]; +01294 <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]= baseVertices[1]; +01295 <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]= baseVertices[2]; +01296 <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]= baseVertices[3]; +01297 +01298 <font class="comment">// build Sons.</font> +01299 <a class="code" href="classNL3D_1_1CPatch.html#c4">makeRoots</a>(); +01300 } +01301 <font class="comment">// ***************************************************************************</font> +<a name="l01302"></a><a class="code" href="classNL3D_1_1CPatch.html#a16">01302</a> CVector CPatch::computeVertex(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)<font class="keyword"> const</font> +01303 <font class="keyword"></font>{ +01304 <font class="comment">// \todo yoyo: TODO_UVCORRECT: use UV correction.</font> +01305 +01306 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#a4">getLandscape</a>()->getNoiseMode()) +01307 { +01308 <font class="comment">// compute displacement map to disturb result.</font> +01309 CVector displace; +01310 <a class="code" href="classNL3D_1_1CPatch.html#z685_10">computeNoise</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, displace); +01311 +01312 <font class="comment">// return patch(s,t) + dispalcement result.</font> +01313 <font class="comment">// unpack. Do it after computeNoise(), because this last may change the cache.</font> +01314 CBezierPatch *patch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>(); +01315 <font class="keywordflow">return</font> patch->eval(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) + displace; +01316 } +01317 <font class="keywordflow">else</font> +01318 { +01319 <font class="comment">// unpack and return patch(s,t).</font> +01320 CBezierPatch *patch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>(); +01321 <font class="keywordflow">return</font> patch->eval(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>); +01322 } +01323 } +01324 +01325 +01326 <font class="comment">// ***************************************************************************</font> +<a name="l01327"></a><a class="code" href="classNL3D_1_1CPatch.html#a17">01327</a> CVector CPatch::computeContinousVertex(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)<font class="keyword"> const</font> +01328 <font class="keyword"></font>{ +01329 <font class="comment">// must be compiled</font> +01330 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>); +01331 +01332 <font class="comment">// Test is on a edge/corner of the patch</font> +01333 sint edgeIdS= -1; +01334 sint edgeIdT= -1; +01335 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==0) edgeIdS= 0; +01336 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==1) edgeIdS= 2; +01337 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==0) edgeIdT= 3; +01338 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==1) edgeIdT= 1; +01339 +01340 <font class="comment">// test if on a corner</font> +01341 <font class="keywordflow">if</font>(edgeIdS>=0 && edgeIdT>=0) +01342 { +01343 <font class="comment">// return the baseVertex according to edge falgs</font> +01344 <font class="keywordflow">if</font>(edgeIdS==0 && edgeIdT==3) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]->EndPos; +01345 <font class="keywordflow">if</font>(edgeIdS==0 && edgeIdT==1) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]->EndPos; +01346 <font class="keywordflow">if</font>(edgeIdS==2 && edgeIdT==1) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]->EndPos; +01347 <font class="keywordflow">if</font>(edgeIdS==2 && edgeIdT==3) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]->EndPos; +01348 <a class="code" href="debug_8h.html#a12">nlstop</a>; +01349 <font class="comment">// Error, but Avoid warning</font> +01350 <font class="keywordflow">return</font> CVector::Null; +01351 } +01352 <font class="comment">// test if on an edge</font> +01353 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(edgeIdS>=0 || edgeIdT>=0) +01354 { +01355 <font class="comment">// Yes, must compute myslef</font> +01356 CVector vertexOnMe= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>); +01357 +01358 <font class="comment">// Then, must compute my neighbor.</font> +01359 sint edgeId; +01360 <font class="keywordflow">if</font>(edgeIdS>=0) +01361 edgeId= edgeIdS; +01362 <font class="keywordflow">else</font> +01363 edgeId= edgeIdT; +01364 +01365 <font class="comment">// Get my neighbor, if any.</font> +01366 CBindInfo bindInfo; +01367 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edgeId, bindInfo); +01368 <font class="comment">// Fast reject: if no neighbor on the edge, just return my pos.</font> +01369 <font class="keywordflow">if</font>(!bindInfo.Zone) +01370 { +01371 <font class="keywordflow">return</font> vertexOnMe; +01372 } +01373 <font class="comment">// else must get vertex pos of my neighbor, and average.</font> +01374 <font class="keywordflow">else</font> +01375 { +01376 <font class="comment">// use a CPatchUVLocator to get UV in neighbor patch</font> +01377 CPatchUVLocator uvLocator; +01378 uvLocator.build(<font class="keyword">this</font>, edgeId, bindInfo); +01379 +01380 <font class="comment">// UVlocator use OrderS/OrderT coordinate system.</font> +01381 CVector2f stTileIn, stTileOut; +01382 stTileIn.x= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> * <a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(); +01383 stTileIn.y= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a> * <a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>(); +01384 +01385 <font class="comment">// transform coordinate to get into the neigbhor patch</font> +01386 uint pid= uvLocator.selectPatch(stTileIn); +01387 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *nebPatch; +01388 uvLocator.locateUV(stTileIn, pid, nebPatch, stTileOut); +01389 +01390 <font class="comment">// transform neigbhor coord in 0..1 coordinate space.</font> +01391 stTileOut.x/= nebPatch->getOrderS(); +01392 stTileOut.y/= nebPatch->getOrderT(); +01393 +01394 <font class="comment">// and compute vertex. NB: if binded on 2 or 4 patch, it is then possible that stTileOut is on a</font> +01395 <font class="comment">// a corner ( (0,0), (0,1) ...).</font> +01396 <font class="comment">// In this case, we must use the precomputed Vertex pos, for completeness.</font> +01397 <font class="keywordtype">bool</font> onCorner; +01398 CVector vertexOnNeb= nebPatch->computeVertexButCorner(stTileOut.x, stTileOut.y, onCorner); +01399 +01400 <font class="comment">// If the neighbor is on a corner, then use its corner value.</font> +01401 <font class="keywordflow">if</font>(onCorner) +01402 <font class="keywordflow">return</font> vertexOnNeb; +01403 <font class="keywordflow">else</font> +01404 { +01405 <font class="comment">// Average the 2 and return this result.</font> +01406 vertexOnMe+= vertexOnNeb; +01407 vertexOnMe/= 2; +01408 <font class="keywordflow">return</font> vertexOnMe; +01409 } +01410 } +01411 +01412 } +01413 <font class="comment">// else, std case</font> +01414 <font class="keywordflow">else</font> +01415 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>); +01416 } +01417 +01418 +01419 <font class="comment">// ***************************************************************************</font> +<a name="l01420"></a><a class="code" href="classNL3D_1_1CPatch.html#z683_4">01420</a> CVector CPatch::computeVertexButCorner(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <font class="keywordtype">bool</font> &onCorner)<font class="keyword"> const</font> +01421 <font class="keyword"></font>{ +01422 <font class="comment">// must be compiled</font> +01423 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>); +01424 +01425 <font class="comment">// Test is on a edge/corner of the patch</font> +01426 sint edgeIdS= -1; +01427 sint edgeIdT= -1; +01428 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==0) edgeIdS= 0; +01429 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==1) edgeIdS= 2; +01430 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==0) edgeIdT= 3; +01431 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==1) edgeIdT= 1; +01432 +01433 <font class="comment">// test if on a corner</font> +01434 <font class="keywordflow">if</font>(edgeIdS>=0 && edgeIdT>=0) +01435 { +01436 <font class="comment">// indicate that yes, we are on a corner</font> +01437 onCorner= <font class="keyword">true</font>; +01438 <font class="comment">// return the baseVertex according to edge falgs</font> +01439 <font class="keywordflow">if</font>(edgeIdS==0 && edgeIdT==3) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]->EndPos; +01440 <font class="keywordflow">if</font>(edgeIdS==0 && edgeIdT==1) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]->EndPos; +01441 <font class="keywordflow">if</font>(edgeIdS==2 && edgeIdT==1) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]->EndPos; +01442 <font class="keywordflow">if</font>(edgeIdS==2 && edgeIdT==3) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]->EndPos; +01443 <a class="code" href="debug_8h.html#a12">nlstop</a>; +01444 <font class="comment">// Error, but Avoid warning</font> +01445 <font class="keywordflow">return</font> CVector::Null; +01446 } +01447 <font class="comment">// else, std case</font> +01448 <font class="keywordflow">else</font> +01449 { +01450 onCorner= <font class="keyword">false</font>; +01451 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>); +01452 } +01453 } +01454 +01455 +01456 <font class="comment">// ***************************************************************************</font> +<a name="l01457"></a><a class="code" href="classNL3D_1_1CPatch.html#a27">01457</a> <font class="keywordtype">void</font> CPatch::refineAll() +01458 { +01459 <font class="comment">// refineAll.</font> +01460 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>); +01461 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01462 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->refineAll(); +01463 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->refineAll(); +01464 } +01465 +01466 +01467 +01468 <font class="comment">// ***************************************************************************</font> +<a name="l01469"></a><a class="code" href="classNL3D_1_1CPatch.html#a21">01469</a> <font class="keywordtype">void</font> CPatch::averageTesselationVertices() +01470 { +01471 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>); +01472 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01473 +01474 <font class="comment">// Recompute the BaseVertices. This is usefull for Pacs.</font> +01475 <font class="comment">// Because CLandscape::averageTesselationVertices() is made on a strict order for patchs (map of zones, then </font> +01476 <font class="comment">// array of patchs), we are sure to overwrite BaseVertices in this order.</font> +01477 CTessVertex *a= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]; +01478 CTessVertex *b= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]; +01479 CTessVertex *c= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]; +01480 CTessVertex *d= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]; +01481 <font class="comment">// Set positions.</font> +01482 a->Pos= a->StartPos= a->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,0); +01483 b->Pos= b->StartPos= b->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,1); +01484 c->Pos= c->StartPos= c->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,1); +01485 d->Pos= d->StartPos= d->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,0); +01486 +01487 +01488 <font class="comment">// Average the tesselation of sons.</font> +01489 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->averageTesselationVertices(); +01490 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->averageTesselationVertices(); +01491 } +01492 +01493 +01494 <font class="comment">// ***************************************************************************</font> +<a name="l01495"></a><a class="code" href="classNL3D_1_1CPatch.html#a31">01495</a> <font class="keywordtype">void</font> CPatch::refreshTesselationGeometry() +01496 { +01497 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>); +01498 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01499 +01500 <font class="comment">// Recompute the BaseVertices.</font> +01501 CTessVertex *a= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]; +01502 CTessVertex *b= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]; +01503 CTessVertex *c= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]; +01504 CTessVertex *d= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]; +01505 <font class="comment">// Set positions.</font> +01506 a->Pos= a->StartPos= a->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,0); +01507 b->Pos= b->StartPos= b->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,1); +01508 c->Pos= c->StartPos= c->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,1); +01509 d->Pos= d->StartPos= d->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,0); +01510 +01511 +01512 <font class="comment">// refresh the tesselation of sons.</font> +01513 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->refreshTesselationGeometry(); +01514 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->refreshTesselationGeometry(); +01515 } +01516 +01517 +01518 +01519 <font class="comment">// ***************************************************************************</font> +<a name="l01520"></a><a class="code" href="classNL3D_1_1CPatch.html#a26">01520</a> <font class="keywordtype">void</font> CPatch::clip(<font class="keyword">const</font> std::vector<CPlane> &pyramid) +01521 { +01522 <a class="code" href="classNL3D_1_1CPatch.html#o25">Clipped</a>= <font class="keyword">false</font>; +01523 <font class="keywordflow">for</font>(sint i=0;i<(sint)pyramid.size();i++) +01524 { +01525 <font class="comment">// If entirely out.</font> +01526 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CPatch.html#o13">BSphere</a>.clipBack(pyramid[i])) +01527 { +01528 <a class="code" href="classNL3D_1_1CPatch.html#o25">Clipped</a>= <font class="keyword">true</font>; +01529 <font class="keywordflow">break</font>; +01530 } +01531 } +01532 +01533 <font class="comment">// A patch clipped is clipped to render too.</font> +01534 <a class="code" href="classNL3D_1_1CPatch.html#o26">RenderClipped</a>= <a class="code" href="classNL3D_1_1CPatch.html#o25">Clipped</a>; +01535 } +01536 +01537 +01538 <font class="comment">// ***************************************************************************</font> +<a name="l01539"></a><a class="code" href="classNL3D_1_1CPatch.html#a28">01539</a> <font class="keywordtype">void</font> CPatch::resetRenderFar() +01540 { +01541 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CPatch.html#o28">Pass0</a>.PatchRdrPass) +01542 { +01543 <font class="comment">// free the render pass.</font> +01544 <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->Landscape->freeFarRenderPass (<font class="keyword">this</font>, <a class="code" href="classNL3D_1_1CPatch.html#o28">Pass0</a>.PatchRdrPass, <a class="code" href="classNL3D_1_1CPatch.html#o14">Far0</a>); +01545 <a class="code" href="classNL3D_1_1CPatch.html#o28">Pass0</a>.PatchRdrPass= NULL; +01546 } +01547 <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CPatch.html#o29">Pass1</a>.PatchRdrPass) +01548 { +01549 <font class="comment">// free the render pass.</font> +01550 <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->Landscape->freeFarRenderPass (<font class="keyword">this</font>, <a class="code" href="classNL3D_1_1CPatch.html#o29">Pass1</a>.PatchRdrPass, <a class="code" href="classNL3D_1_1CPatch.html#o15">Far1</a>); +01551 <a class="code" href="classNL3D_1_1CPatch.html#o29">Pass1</a>.PatchRdrPass= NULL; +01552 } +01553 +01554 <a class="code" href="classNL3D_1_1CPatch.html#o14">Far0</a>= -1; +01555 <a class="code" href="classNL3D_1_1CPatch.html#o15">Far1</a>= -1; +01556 } +01557 +01558 +01559 <font class="comment">// ***************************************************************************</font> +<a name="l01560"></a><a class="code" href="classNL3D_1_1CPatch.html#a32">01560</a> <font class="keywordtype">void</font> CPatch::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) +01561 { +01562 <font class="comment">/*</font> +01563 <font class="comment"> Version 7:</font> +01564 <font class="comment"> - remove unused information from CTileColor. just keep 565 color</font> +01565 <font class="comment"> Version 6:</font> +01566 <font class="comment"> - default UnderWater flags for tileElements before version 6.</font> +01567 <font class="comment"> Version 5:</font> +01568 <font class="comment"> - TileLightInfluences serialized.</font> +01569 <font class="comment"> Version 4:</font> +01570 <font class="comment"> - Smooth flag serialized</font> +01571 <font class="comment"> Version 3:</font> +01572 <font class="comment"> - NoiseRotation.</font> +01573 <font class="comment"> - NoiseSmooth.</font> +01574 <font class="comment"> Version 2:</font> +01575 <font class="comment"> - Lumels.</font> +01576 <font class="comment"> Version 1:</font> +01577 <font class="comment"> - Tile color.</font> +01578 <font class="comment"> Version 0:</font> +01579 <font class="comment"> - base version.</font> +01580 <font class="comment"> */</font> +01581 uint ver= f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(<a class="code" href="classNL3D_1_1CPatch.html#r0">_Version</a>); +01582 +01583 <font class="comment">// No more compatibility before version 2, because OrderS / OrderT not serialized in preceding version</font> +01584 <font class="comment">// Doens't matter since CZone::serial() do not support it too.</font> +01585 <font class="keywordflow">if</font> (ver<2) +01586 { +01587 <font class="keywordflow">throw</font> EOlderStream(f); +01588 } +01589 +01590 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CPatch.html#m0">Vertices</a>[0], <a class="code" href="classNL3D_1_1CPatch.html#m0">Vertices</a>[1], <a class="code" href="classNL3D_1_1CPatch.html#m0">Vertices</a>[2], <a class="code" href="classNL3D_1_1CPatch.html#m0">Vertices</a>[3], <font class="stringliteral">"VERTICIES"</font>); +01591 +01592 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"TANGENTS"</font>); +01593 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a> (<a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[0], <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[1], <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[2], <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[3]); +01594 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a> (<a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[4], <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[5], <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[6], <a class="code" href="classNL3D_1_1CPatch.html#m1">Tangents</a>[7]); +01595 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +01596 +01597 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CPatch.html#m2">Interiors</a>[0], <a class="code" href="classNL3D_1_1CPatch.html#m2">Interiors</a>[1], <a class="code" href="classNL3D_1_1CPatch.html#m2">Interiors</a>[2], <a class="code" href="classNL3D_1_1CPatch.html#m2">Interiors</a>[3], <font class="stringliteral">"INTERIORS"</font>); +01598 +01599 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"TILES"</font>); +01600 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>); +01601 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +01602 +01603 <font class="keywordflow">if</font>(ver>=1) +01604 { +01605 <font class="comment">// Read/Write TileColors.</font> +01606 <font class="keywordflow">if</font>(ver<=6) +01607 { +01608 <a class="code" href="debug_8h.html#a6">nlassert</a>(f.<a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>()); +01609 +01610 <font class="comment">// read old version of tilesColors (ie with LightX/LightY/LightZ, which are deprecated now)</font> +01611 vector<CTileColorOldPatchVersion6> tmpArray; +01612 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"TILE_COLORS"</font>); +01613 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(tmpArray); +01614 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +01615 +01616 <font class="comment">// then just copy to TileColors.</font> +01617 <a class="code" href="classNL3D_1_1CPatch.html#m5">TileColors</a>.resize(tmpArray.size()); +01618 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#m5">TileColors</a>.size()>0) +01619 { +01620 memcpy(&<a class="code" href="classNL3D_1_1CPatch.html#m5">TileColors</a>[0], &tmpArray[0], <a class="code" href="classNL3D_1_1CPatch.html#m5">TileColors</a>.size()*<font class="keyword">sizeof</font>(CTileColor)); +01621 } +01622 } +01623 <font class="keywordflow">else</font> +01624 { +01625 <font class="comment">// version >=7, just serial array of TileColors (16 bits TileColor only)</font> +01626 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"TILE_COLORS"</font>); +01627 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CPatch.html#m5">TileColors</a>); +01628 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +01629 } +01630 } +01631 <font class="keywordflow">if</font>(ver>=2) +01632 { +01633 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>, <font class="stringliteral">"ORDER_S"</font>); +01634 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>, <font class="stringliteral">"ORDER_T"</font>); +01635 +01636 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"COMPRESSED_LUMELS"</font>); +01637 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CPatch.html#m3">CompressedLumels</a>); +01638 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +01639 } +01640 <font class="comment">// Else cannot create here the TileColors, because we need the OrderS/OrderT information... Done into CZone serial.</font> +01641 <font class="keywordflow">if</font>(ver>=3) +01642 { +01643 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CPatch.html#z668_2">NoiseRotation</a>, <font class="stringliteral">"NOISE_ROTATION"</font>); +01644 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a> (<a class="code" href="classNL3D_1_1CPatch.html#z668_3">_CornerSmoothFlag</a>, <font class="stringliteral">"CORNER_SMOOTH_FLAG"</font>); +01645 } +01646 <font class="keywordflow">else</font> +01647 { +01648 <font class="comment">// No Rotation / not smooth by default.</font> +01649 <a class="code" href="classNL3D_1_1CPatch.html#z668_2">NoiseRotation</a>= 0; +01650 <a class="code" href="classNL3D_1_1CPatch.html#z668_3">_CornerSmoothFlag</a>= 0; +01651 } +01652 <font class="keywordflow">if</font>(ver>=4) +01653 { +01654 f.<a class="code" href="classNLMISC_1_1IStream.html#a34">xmlSerial</a>(<a class="code" href="classNL3D_1_1CPatch.html#o24">Flags</a>, <font class="stringliteral">"FLAGS"</font>); +01655 } +01656 <font class="keywordflow">else</font> +01657 { +01658 <a class="code" href="classNL3D_1_1CPatch.html#o24">Flags</a>=<a class="code" href="patch_8h.html#a5">NL_PATCH_SMOOTH_FLAG_MASK</a>; +01659 } +01660 +01661 <font class="comment">// Serialize TileLightInfluences</font> +01662 <font class="keywordflow">if</font>(ver>=5) +01663 { +01664 f.<a class="code" href="classNLMISC_1_1IStream.html#a38">xmlPush</a> (<font class="stringliteral">"TILE_LIGHT_INFLUENCES"</font>); +01665 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CPatch.html#m6">TileLightInfluences</a>); +01666 f.<a class="code" href="classNLMISC_1_1IStream.html#a41">xmlPop</a> (); +01667 } +01668 <font class="keywordflow">else</font> +01669 { +01670 <font class="keywordflow">if</font>(f.<a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>()) +01671 { +01672 <font class="comment">// Fill default.</font> +01673 <a class="code" href="classNL3D_1_1CPatch.html#z675_0">resetTileLightInfluences</a>(); +01674 } +01675 } +01676 +01677 <font class="comment">// if read a too old version, </font> +01678 <font class="keywordflow">if</font>(ver<6 && f.<a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>()) +01679 { +01680 <font class="comment">// reset tileElements vegetableState to AboveWater.</font> +01681 <font class="keywordflow">for</font>(uint i=0; i<<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>.size(); i++) +01682 { +01683 <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[i].setVegetableState(CTileElement::AboveWater); +01684 } +01685 } +01686 +01687 +01688 } +01689 +01690 +01691 +01692 <font class="comment">// ***************************************************************************</font> +01693 <font class="comment">// ***************************************************************************</font> +01694 <font class="comment">// Bind / UnBind.</font> +01695 <font class="comment">// ***************************************************************************</font> +01696 <font class="comment">// ***************************************************************************</font> +01697 +01698 +01699 +01700 <font class="comment">// ***************************************************************************</font> +<a name="l01701"></a><a class="code" href="classNL3D_1_1CPatch.html#a18">01701</a> <font class="keywordtype">void</font> CPatch::unbind() +01702 { +01703 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a> && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01704 +01705 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->unbind(); +01706 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->unbind(); +01707 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->forceMerge(); +01708 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->forceMerge(); +01709 <font class="comment">// forcemerge should have be completed.</font> +01710 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->isLeaf() && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->isLeaf()); +01711 <font class="comment">// unbind should have be completed.</font> +01712 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FLeft == NULL); +01713 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FRight == NULL); +01714 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FLeft == NULL); +01715 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FRight == NULL); +01716 +01717 +01718 <font class="comment">// unbind Noise.</font> +01719 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[0]= NULL; +01720 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[1]= NULL; +01721 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[2]= NULL; +01722 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[3]= NULL; +01723 +01724 } +01725 +01726 +01727 <font class="comment">// ***************************************************************************</font> +<a name="l01728"></a><a class="code" href="classNL3D_1_1CPatch.html#c5">01728</a> CTessFace *CPatch::getRootFaceForEdge(sint edge)<font class="keyword"> const</font> +01729 <font class="keyword"></font>{ +01730 <a class="code" href="debug_8h.html#a6">nlassert</a>(edge>=0 && edge<=3); +01731 +01732 <font class="comment">// See tessellation rules.</font> +01733 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>=<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) +01734 { +01735 <font class="keywordflow">if</font>(edge==0 || edge==1) +01736 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>; +01737 <font class="keywordflow">else</font> +01738 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>; +01739 } +01740 <font class="keywordflow">else</font> +01741 { +01742 <font class="keywordflow">if</font>(edge==0 || edge==3) +01743 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>; +01744 <font class="keywordflow">else</font> +01745 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>; +01746 } +01747 } +01748 +01749 <font class="comment">// ***************************************************************************</font> +<a name="l01750"></a><a class="code" href="classNL3D_1_1CPatch.html#c6">01750</a> CTessVertex *CPatch::getRootVertexForEdge(sint edge)<font class="keyword"> const</font> +01751 <font class="keyword"></font>{ +01752 <font class="comment">// Return the vertex which is the start of edge.</font> +01753 <a class="code" href="debug_8h.html#a6">nlassert</a>(edge>=0 && edge<=3); +01754 +01755 <font class="comment">// See tessellation rules.</font> +01756 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>=<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) +01757 { +01758 <font class="keywordflow">switch</font>(edge) +01759 { +01760 <font class="keywordflow">case</font> 0: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VRight; +01761 <font class="keywordflow">case</font> 1: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VBase; +01762 <font class="keywordflow">case</font> 2: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VLeft; +01763 <font class="keywordflow">case</font> 3: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VBase; +01764 <font class="keywordflow">default</font>: <font class="keywordflow">return</font> NULL; +01765 } +01766 } +01767 <font class="keywordflow">else</font> +01768 { +01769 <font class="keywordflow">switch</font>(edge) +01770 { +01771 <font class="keywordflow">case</font> 0: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VBase; +01772 <font class="keywordflow">case</font> 1: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VLeft; +01773 <font class="keywordflow">case</font> 2: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->VBase; +01774 <font class="keywordflow">case</font> 3: <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->VRight; +01775 <font class="keywordflow">default</font>: <font class="keywordflow">return</font> NULL; +01776 } +01777 } +01778 } +01779 +01780 +01781 <font class="comment">// ***************************************************************************</font> +<a name="l01782"></a><a class="code" href="classNL3D_1_1CPatch.html#c7">01782</a> <font class="keywordtype">void</font> CPatch::changeEdgeNeighbor(sint edge, CTessFace *to) +01783 { +01784 <a class="code" href="debug_8h.html#a6">nlassert</a>(edge>=0 && edge<=3); +01785 +01786 <font class="comment">// See tessellation rules.</font> +01787 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>>=<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) +01788 { +01789 <font class="keywordflow">switch</font>(edge) +01790 { +01791 <font class="keywordflow">case</font> 0: <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FRight= to; <font class="keywordflow">break</font>; +01792 <font class="keywordflow">case</font> 1: <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FLeft= to; <font class="keywordflow">break</font>; +01793 <font class="keywordflow">case</font> 2: <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FRight= to; <font class="keywordflow">break</font>; +01794 <font class="keywordflow">case</font> 3: <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FLeft= to; <font class="keywordflow">break</font>; +01795 } +01796 } +01797 <font class="keywordflow">else</font> +01798 { +01799 <font class="keywordflow">switch</font>(edge) +01800 { +01801 <font class="keywordflow">case</font> 0: <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FLeft= to; <font class="keywordflow">break</font>; +01802 <font class="keywordflow">case</font> 1: <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FRight= to; <font class="keywordflow">break</font>; +01803 <font class="keywordflow">case</font> 2: <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FLeft= to; <font class="keywordflow">break</font>; +01804 <font class="keywordflow">case</font> 3: <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FRight= to; <font class="keywordflow">break</font>; +01805 } +01806 } +01807 } +01808 +01809 +01810 <font class="comment">// ***************************************************************************</font> +<a name="l01811"></a><a class="code" href="classNL3D_1_1CPatch.html#z684_0">01811</a> CTessFace *CPatch::linkTessFaceWithEdge(<font class="keyword">const</font> CVector2f &uv0, <font class="keyword">const</font> CVector2f &uv1, CTessFace *linkTo) +01812 { +01813 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a> && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01814 <font class="comment">// Try to link with Root Son0</font> +01815 <a class="code" href="classNL3D_1_1CPatch.html#l0">CTessFace</a> *face= <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->linkTessFaceWithEdge(uv0, uv1, linkTo); +01816 <font class="comment">// if Failed Try to link with Root Son1</font> +01817 <font class="keywordflow">if</font>(!face) +01818 face= <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->linkTessFaceWithEdge(uv0, uv1, linkTo); +01819 <font class="keywordflow">return</font> face; +01820 } +01821 +01822 +01823 <font class="comment">// ***************************************************************************</font> +<a name="l01824"></a><a class="code" href="classNL3D_1_1CPatch.html#a19">01824</a> <font class="keywordtype">void</font> CPatch::bind(CBindInfo Edges[4], <font class="keywordtype">bool</font> rebind) +01825 { +01826 <font class="comment">// The multiple Patch Face.</font> +01827 <font class="comment">// By default, Patch==NULL, FLeft, FRight and FBase==NULL so ok!</font> +01828 <font class="keyword">static</font> <a class="code" href="classNL3D_1_1CPatch.html#l0">CTessFace</a> bind1_2[4]; +01829 <font class="keyword">static</font> <a class="code" href="classNL3D_1_1CPatch.html#l0">CTessFace</a> bind1_4[8]; +01830 +01831 +01832 <font class="comment">// THIS PATCH MUST BE UNBOUND FIRST!!!!!</font> +01833 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a> && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +01834 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->isLeaf() && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->isLeaf()); +01835 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FLeft == NULL); +01836 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FRight == NULL); +01837 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FLeft == NULL); +01838 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FRight == NULL); +01839 +01840 +01841 <font class="comment">// bind the Realtime bind info here (before any computeVertex, and before bind too).</font> +01842 sint i; +01843 <font class="keywordflow">for</font>(i=0;i<4;i++) +01844 { +01845 <font class="comment">// just Copy zone (if not NULL).</font> +01846 <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[i]= Edges[i].Zone; +01847 } +01848 +01849 +01850 <font class="keywordflow">if</font>(!rebind) +01851 { +01852 <font class="comment">// Just recompute base vertices.</font> +01853 CTessVertex *a= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[0]; +01854 CTessVertex *b= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[1]; +01855 CTessVertex *c= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[2]; +01856 CTessVertex *d= <a class="code" href="classNL3D_1_1CPatch.html#o11">BaseVertices</a>[3]; +01857 <font class="comment">// Set positions.</font> +01858 a->Pos= a->StartPos= a->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,0); +01859 b->Pos= b->StartPos= b->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(0,1); +01860 c->Pos= c->StartPos= c->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,1); +01861 d->Pos= d->StartPos= d->EndPos= <a class="code" href="classNL3D_1_1CPatch.html#a16">computeVertex</a>(1,0); +01862 <font class="comment">// NB: no propagation problem, since the patch has root only (since has to be unbound!!!)</font> +01863 <font class="comment">// Recompute centers.</font> +01864 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->computeSplitPoint(); +01865 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->computeSplitPoint(); +01866 } +01867 <font class="keywordflow">else</font> +01868 { +01869 <font class="comment">// Keep old Vertices as computed from neighbors, but reFill the 4 FarVertices.</font> +01870 <font class="comment">// NB: don't do it on NearVertices because suppose that Near is Off when a bind occurs (often far away).</font> +01871 <a class="code" href="classNL3D_1_1CPatch.html#c27">checkFillVertexVBFar</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVBase); +01872 <a class="code" href="classNL3D_1_1CPatch.html#c27">checkFillVertexVBFar</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVLeft); +01873 <a class="code" href="classNL3D_1_1CPatch.html#c27">checkFillVertexVBFar</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->FVRight); +01874 <a class="code" href="classNL3D_1_1CPatch.html#c27">checkFillVertexVBFar</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->FVBase); +01875 } +01876 +01877 +01878 <font class="comment">// Bind the roots.</font> +01879 <font class="keywordflow">for</font>(i=0;i<4;i++) +01880 { +01881 CBindInfo &<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>= Edges[i]; +01882 +01883 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==0 || <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==1 || <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==2 || <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==4 || <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==5); +01884 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==1) +01885 { +01886 <font class="comment">// Bind me on Next.</font> +01887 this-><a class="code" href="classNL3D_1_1CPatch.html#c7">changeEdgeNeighbor</a>(i, <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0])); +01888 <font class="comment">// Bind Next on me.</font> +01889 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0], this->getRootFaceForEdge(i)); +01890 } +01891 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==2) +01892 { +01893 <font class="comment">// Setup multiple bind.</font> +01894 this-><a class="code" href="classNL3D_1_1CPatch.html#c7">changeEdgeNeighbor</a>(i, bind1_2+i); +01895 bind1_2[i].FBase= this-><a class="code" href="classNL3D_1_1CPatch.html#c5">getRootFaceForEdge</a>(i); +01896 <font class="comment">// Setup the multiple face.</font> +01897 <font class="comment">// Follow the conventions! Make a draw for understand. Small Patchs are numbered in CCW.</font> +01898 bind1_2[i].SonRight= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0]); +01899 bind1_2[i].SonLeft= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[1]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[1]); +01900 bind1_2[i].VBase= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->getRootVertexForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0]); +01901 <font class="comment">// Set a "flag" to neighbors, so they know what edge is to be bind on me.</font> +01902 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0], &CTessFace::MultipleBindFace); +01903 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[1]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[1], &CTessFace::MultipleBindFace); +01904 } +01905 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==4) +01906 { +01907 <font class="comment">// Setup multiple bind level 0.</font> +01908 this-><a class="code" href="classNL3D_1_1CPatch.html#c7">changeEdgeNeighbor</a>(i, bind1_2+i); +01909 bind1_2[i].FBase= this-><a class="code" href="classNL3D_1_1CPatch.html#c5">getRootFaceForEdge</a>(i); +01910 +01911 <font class="comment">// Setup multiple bind level 1.</font> +01912 <font class="comment">// Follow the conventions! Make a draw for understand. Small Patchs are numbered in CCW.</font> +01913 bind1_2[i].SonRight= bind1_4 + 2*i+0; +01914 bind1_2[i].SonLeft= bind1_4 + 2*i+1; +01915 bind1_2[i].VBase= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[1]->getRootVertexForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[1]); +01916 <font class="comment">// Make first multiple face bind level1.</font> +01917 bind1_4[2*i+0].FBase= &CTessFace::MultipleBindFace; <font class="comment">// to link correctly when the root face will be splitted.</font> +01918 bind1_4[2*i+0].SonRight= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0]); +01919 bind1_4[2*i+0].SonLeft= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[1]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[1]); +01920 bind1_4[2*i+0].VBase= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->getRootVertexForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0]); +01921 <font class="comment">// Make second multiple face bind level1.</font> +01922 bind1_4[2*i+1].FBase= &CTessFace::MultipleBindFace; <font class="comment">// to link correctly when the root face will be splitted.</font> +01923 bind1_4[2*i+1].SonRight= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[2]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[2]); +01924 bind1_4[2*i+1].SonLeft= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[3]->getRootFaceForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[3]); +01925 bind1_4[2*i+1].VBase= <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[2]->getRootVertexForEdge(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[2]); +01926 +01927 <font class="comment">// Set a "flag" to neighbors, so they know what edge is to be bind on me.</font> +01928 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[0]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[0], &CTessFace::MultipleBindFace); +01929 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[1]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[1], &CTessFace::MultipleBindFace); +01930 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[2]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[2], &CTessFace::MultipleBindFace); +01931 <a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Next[3]->changeEdgeNeighbor(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.Edge[3], &CTessFace::MultipleBindFace); +01932 } +01933 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#a19">bind</a>.NPatchs==5) +01934 { +01935 <font class="comment">/* I am binded to a bigger patch and this one has already done the binding on me => </font> +01936 <font class="comment"> It must be correclty tesselated. Note also that bind 1/X are only possible on interior of zone.</font> +01937 <font class="comment"> */</font> +01938 +01939 <font class="comment">// First, make the link with the face to which I must connect.</font> +01940 <font class="comment">// -----------------</font> +01941 +01942 <font class="comment">// Get the coordinate of the current edge of this patch</font> +01943 CVector2f uvi0, uvi1; +01944 <font class="keywordflow">switch</font>(i) +01945 { +01946 <font class="keywordflow">case</font> 0: uvi0.set(0,0); uvi1.set(0,1); <font class="keywordflow">break</font>; +01947 <font class="keywordflow">case</font> 1: uvi0.set(0,1); uvi1.set(1,1); <font class="keywordflow">break</font>; +01948 <font class="keywordflow">case</font> 2: uvi0.set(1,1); uvi1.set(1,0); <font class="keywordflow">break</font>; +01949 <font class="keywordflow">case</font> 3: uvi0.set(1,0); uvi1.set(0,0); <font class="keywordflow">break</font>; +01950 }; +01951 <font class="comment">// mul by OrderS/OrderT for CPatchUVLocator</font> +01952 uvi0.x*= <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>; +01953 uvi0.y*= <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>; +01954 uvi1.x*= <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>; +01955 uvi1.y*= <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>; +01956 <font class="comment">// build a CPatchUVLocator to transpose coorindate ot this edge in coordinate on the bigger Neighbor patch.</font> +01957 CBindInfo bindInfo; +01958 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(i, bindInfo); +01959 <a class="code" href="debug_8h.html#a6">nlassert</a>(bindInfo.Zone!=NULL && bindInfo.NPatchs==1); +01960 CPatchUVLocator puvloc; +01961 puvloc.build(<font class="keyword">this</font>, i, bindInfo); +01962 +01963 <font class="comment">// transpose from this patch coord in neighbor patch coord.</font> +01964 CVector2f uvo0, uvo1; +01965 uint pid; +01966 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchNeighbor; +01967 <font class="comment">// Do it for uvi0</font> +01968 pid= puvloc.selectPatch(uvi0); +01969 puvloc.locateUV(uvi0, pid, patchNeighbor, uvo0); +01970 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchNeighbor == bindInfo.Next[0]); +01971 <font class="comment">// Do it for uvi1</font> +01972 pid= puvloc.selectPatch(uvi1); +01973 puvloc.locateUV(uvi1, pid, patchNeighbor, uvo1); +01974 <a class="code" href="debug_8h.html#a6">nlassert</a>(patchNeighbor == bindInfo.Next[0]); +01975 <font class="comment">// Rescale to have uv in 0,1 basis.</font> +01976 uvo0.x/= patchNeighbor->OrderS; +01977 uvo0.y/= patchNeighbor->OrderT; +01978 uvo1.x/= patchNeighbor->OrderS; +01979 uvo1.y/= patchNeighbor->OrderT; +01980 +01981 <font class="comment">// Now, traverse the tesselation and find the first CTessFace which use this edge.</font> +01982 <a class="code" href="classNL3D_1_1CPatch.html#l0">CTessFace</a> *faceNeighbor; +01983 faceNeighbor= patchNeighbor->linkTessFaceWithEdge(uvo0, uvo1, this->getRootFaceForEdge(i)); +01984 <a class="code" href="debug_8h.html#a6">nlassert</a>(faceNeighbor); +01985 <font class="comment">// Bind me on Next.</font> +01986 this-><a class="code" href="classNL3D_1_1CPatch.html#c7">changeEdgeNeighbor</a>(i, faceNeighbor); +01987 } +01988 +01989 } +01990 +01991 <font class="comment">// Propagate the binds to sons.</font> +01992 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->updateBind(); +01993 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->updateBind(); +01994 +01995 } +01996 +01997 +01998 <font class="comment">// ***************************************************************************</font> +<a name="l01999"></a><a class="code" href="classNL3D_1_1CPatch.html#a20">01999</a> <font class="keywordtype">void</font> CPatch::forceMergeAtTileLevel() +02000 { +02001 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a> && <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +02002 +02003 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->forceMergeAtTileLevel(); +02004 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->forceMergeAtTileLevel(); +02005 } +02006 +02007 +02008 +02009 <font class="comment">// ***************************************************************************</font> +02010 <font class="comment">// ***************************************************************************</font> +02011 <font class="comment">// Texturing.</font> +02012 <font class="comment">// ***************************************************************************</font> +02013 <font class="comment">// ***************************************************************************</font> +02014 +02015 +02016 <font class="comment">// ***************************************************************************</font> +<a name="l02017"></a><a class="code" href="classNL3D_1_1CPatch.html#z681_0">02017</a> CPatchRdrPass *CPatch::getTileRenderPass(sint tileId, sint pass) +02018 { +02019 <font class="comment">// All but lightmap.</font> +02020 <a class="code" href="debug_8h.html#a6">nlassert</a>(pass==<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a> || pass==<a class="code" href="landscape__def_8h.html#a3">NL3D_TILE_PASS_RGB1</a> || pass==<a class="code" href="landscape__def_8h.html#a4">NL3D_TILE_PASS_RGB2</a> || +02021 pass==<a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>); +02022 +02023 <font class="keywordtype">bool</font> additive= (pass==<a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>); +02024 sint passNum= pass-<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a>; +02025 <font class="comment">// If additive, take the additve tile of bigger existing pass.</font> +02026 <font class="keywordflow">if</font>(additive) +02027 { +02028 <font class="comment">// Default: take addtive of pass 0.</font> +02029 passNum= 0; +02030 <font class="comment">// If the pass1 is not empty, may take its tile.</font> +02031 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[1]!=0xFFFF) +02032 { +02033 passNum= 1; +02034 <font class="comment">// If the pass2 is not empty, take its tile.</font> +02035 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[2]!=0xFFFF) +02036 passNum= 2; +02037 } +02038 } +02039 +02040 sint tileNumber= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[passNum]; +02041 <font class="keywordflow">if</font>(tileNumber==0xFFFF) +02042 { +02043 <font class="comment">// Display a "fake" only if pass 0.</font> +02044 <font class="keywordflow">if</font>(pass==<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a>) +02045 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->Landscape->getTileRenderPass(0xFFFF, <font class="keyword">false</font>); +02046 <font class="comment">// Else, this tile do not have such a pass (not a transition).</font> +02047 <font class="keywordflow">return</font> NULL; +02048 } +02049 <font class="keywordflow">else</font> +02050 { +02051 <font class="comment">// return still may be NULL, in additive case.</font> +02052 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->Landscape->getTileRenderPass(tileNumber, additive); +02053 } +02054 } +02055 +02056 <font class="comment">// ***************************************************************************</font> +<a name="l02057"></a><a class="code" href="classNL3D_1_1CPatch.html#z681_1">02057</a> <font class="keywordtype">void</font> CPatch::getTileUvInfo(sint tileId, sint pass, <font class="keywordtype">bool</font> <a class="code" href="driver__opengl__extension__def_8h.html#a420">alpha</a>, uint8 &orient, CVector &uvScaleBias, <font class="keywordtype">bool</font> &is256x256, uint8 &uvOff) +02058 { +02059 <font class="comment">// All but lightmap.</font> +02060 <a class="code" href="debug_8h.html#a6">nlassert</a>(pass==<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a> || pass==<a class="code" href="landscape__def_8h.html#a3">NL3D_TILE_PASS_RGB1</a> || pass==<a class="code" href="landscape__def_8h.html#a4">NL3D_TILE_PASS_RGB2</a> || +02061 pass==<a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>); +02062 +02063 <font class="keywordtype">bool</font> additive= (pass==<a class="code" href="landscape__def_8h.html#a5">NL3D_TILE_PASS_ADD</a>); +02064 sint passNum= pass-<a class="code" href="landscape__def_8h.html#a2">NL3D_TILE_PASS_RGB0</a>; +02065 <font class="comment">// If additive, take the additve tile of bigger existing pass.</font> +02066 <font class="keywordflow">if</font>(additive) +02067 { +02068 <font class="comment">// Default: take addtive of pass 0.</font> +02069 passNum= 0; +02070 <font class="comment">// If the pass1 is not empty, may take its tile.</font> +02071 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[1]!=0xFFFF) +02072 { +02073 passNum= 1; +02074 <font class="comment">// If the pass2 is not empty, take its tile.</font> +02075 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[2]!=0xFFFF) +02076 passNum= 2; +02077 } +02078 } +02079 +02080 sint tileNumber= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[passNum]; +02081 <font class="keywordflow">if</font>(tileNumber==0xFFFF) +02082 { +02083 <font class="comment">// dummy... Should not be called here.</font> +02084 orient= 0; +02085 uvScaleBias.x=0; +02086 uvScaleBias.y=0; +02087 uvScaleBias.z=1; +02088 is256x256=<font class="keyword">false</font>; +02089 uvOff=0; +02090 } +02091 <font class="keywordflow">else</font> +02092 { +02093 orient= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].getTileOrient(passNum); +02094 <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].getTile256Info(is256x256, uvOff); +02095 CTile::TBitmap <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>; +02096 <font class="comment">// If alpha wanted, return its UV info (works either for Alpha in Diffuse Pass and Alpha in Additive Pass)</font> +02097 <font class="keywordflow">if</font>(alpha) +02098 <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>= CTile::alpha; +02099 <font class="keywordflow">else</font> +02100 { +02101 <font class="keywordflow">if</font>(additive) +02102 <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>= CTile::additive; +02103 <font class="keywordflow">else</font> +02104 <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>= CTile::diffuse; +02105 } +02106 +02107 uint8 rotalpha; +02108 <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->Landscape->getTileUvScaleBiasRot(tileNumber, <a class="code" href="driver__opengl__extension__def_8h.html#a373">type</a>, uvScaleBias, rotalpha); +02109 +02110 <font class="comment">// Add the special rotation of alpha.</font> +02111 <font class="keywordflow">if</font>(alpha) +02112 orient= (orient+rotalpha)&3; +02113 } +02114 +02115 } +02116 +02117 +02118 <font class="comment">// ***************************************************************************</font> +<a name="l02119"></a><a class="code" href="classNL3D_1_1CPatch.html#a29">02119</a> <font class="keywordtype">void</font> CPatch::deleteTileUvs() +02120 { +02121 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->deleteTileUvs(); +02122 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->deleteTileUvs(); +02123 } +02124 +02125 +02126 <font class="comment">// ***************************************************************************</font> +<a name="l02127"></a><a class="code" href="classNL3D_1_1CPatch.html#a30">02127</a> <font class="keywordtype">void</font> CPatch::recreateTileUvs() +02128 { +02129 <font class="comment">// Reset the Tile rdr list.</font> +02130 <font class="keywordflow">for</font>(sint tb=0; tb<(sint)<a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>.size();tb++) +02131 { +02132 <font class="comment">// Vertices must all be reseted.</font> +02133 <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[tb].NearVertexList.clear(); +02134 <font class="keywordflow">for</font>(sint i=0;i<<a class="code" href="tess__block_8h.html#a1">NL3D_TESSBLOCK_TILESIZE</a>;i++) +02135 { +02136 CTileMaterial *tm= <a class="code" href="classNL3D_1_1CPatch.html#z678_1">TessBlocks</a>[tb].RdrTileRoot[i]; +02137 <font class="keywordflow">if</font>(tm) +02138 { +02139 <font class="keywordflow">for</font>(sint pass=0;pass<<a class="code" href="landscape__def_8h.html#a1">NL3D_MAX_TILE_FACE</a>;pass++) +02140 { +02141 tm->TileFaceList[pass].clear(); +02142 } +02143 } +02144 } +02145 } +02146 +02147 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->recreateTileUvs(); +02148 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->recreateTileUvs(); +02149 } +02150 +02151 +02152 <font class="comment">// ***************************************************************************</font> +<a name="l02153"></a><a class="code" href="classNL3D_1_1CPatch.html#z670_4">02153</a> <font class="keywordtype">void</font> CPatch::appendTessellationLeaves(std::vector<const CTessFace*> &leaves)<font class="keyword"> const</font> +02154 <font class="keyword"></font>{ +02155 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>); +02156 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>); +02157 <a class="code" href="classNL3D_1_1CPatch.html#o9">Son0</a>->appendTessellationLeaves(leaves); +02158 <a class="code" href="classNL3D_1_1CPatch.html#o10">Son1</a>->appendTessellationLeaves(leaves); +02159 } +02160 +02161 +02162 <font class="comment">// ***************************************************************************</font> +<a name="l02163"></a><a class="code" href="classNL3D_1_1CPatch.html#a4">02163</a> CLandscape *CPatch::getLandscape ()<font class="keyword"> const</font> +02164 <font class="keyword"></font>{ +02165 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o0">Zone</a>->getLandscape(); +02166 } +02167 +02168 +02169 +02170 +02171 +02172 <font class="comment">// ***************************************************************************</font> +<a name="l02173"></a><a class="code" href="classNL3D_1_1CPatch.html#a8">02173</a> uint8 CPatch::getOrderForEdge(sint8 edge)<font class="keyword"> const</font> +02174 <font class="keyword"></font>{ +02175 uint e= ((sint)edge + 256)&3; +02176 <font class="comment">// If an horizontal edge.</font> +02177 <font class="keywordflow">if</font>( e&1 ) <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>; +02178 <font class="keywordflow">else</font> <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>; +02179 } +02180 +02181 +02182 <font class="comment">// ***************************************************************************</font> +02183 <font class="comment">// ***************************************************************************</font> +02184 <font class="comment">// Realtime Bind info.</font> +02185 <font class="comment">// ***************************************************************************</font> +02186 <font class="comment">// ***************************************************************************</font> +02187 +02188 +02189 <font class="comment">// ***************************************************************************</font> +<a name="l02190"></a><a class="code" href="classNL3D_1_1CPatch.html#a13">02190</a> <font class="keywordtype">void</font> CPatch::getBindNeighbor(uint edge, CBindInfo &neighborEdge)<font class="keyword"> const</font> +02191 <font class="keyword"></font>{ +02192 <a class="code" href="debug_8h.html#a6">nlassert</a>(edge<4); +02193 +02194 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[edge]!=NULL) +02195 { +02196 <a class="code" href="classNL3D_1_1CPatch.html#a5">getZone</a>()->buildBindInfo(<a class="code" href="classNL3D_1_1CPatch.html#o1">PatchId</a>, edge, <a class="code" href="classNL3D_1_1CPatch.html#z684_1">_BindZoneNeighbor</a>[edge], neighborEdge); +02197 } +02198 <font class="keywordflow">else</font> +02199 { +02200 neighborEdge.Zone= NULL; +02201 neighborEdge.NPatchs= 0; +02202 neighborEdge.MultipleBindNum= 0; +02203 } +02204 } +02205 +02206 <font class="comment">// ***************************************************************************</font> +<a name="l02208"></a><a class="code" href="classNL3D_1_1CPatch.html#a37">02208</a> <font class="comment">void CPatch::setupColorsFromTileFlags(const NLMISC::CRGBA colors[4])</font> +02209 { +02210 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> = 0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> <= OrderS; ++<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>) +02211 { +02212 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a> = 0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a> <= OrderT; ++<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) +02213 { +02214 uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, (uint) (OrderT - 1)) * OrderS +02215 + <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, (uint) (OrderS - 1)); +02216 TileColors[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> + <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a> * (OrderS + 1)].Color565 = colors[(uint) (Tiles[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].getVegetableState())].get565(); +02217 } +02218 } +02219 } +02220 +02221 <font class="comment">// ***************************************************************************</font> +<a name="l02222"></a><a class="code" href="classNL3D_1_1CPatch.html#a38">02222</a> <font class="keywordtype">void</font> CPatch::copyTileFlagsFromPatch(<font class="keyword">const</font> CPatch *<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>) +02223 { +02224 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>->OrderS +02225 && <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a> == <a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>->OrderT); +02226 +02227 <font class="keywordflow">for</font> (uint k = 0; k < <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>.size(); ++k) +02228 { +02229 <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[k].copyFlagsFromOther(<a class="code" href="driver__opengl__extension__def_8h.html#a409">src</a>->Tiles[k]); +02230 } +02231 } +02232 +02233 +02234 <font class="comment">// ***************************************************************************</font> +02235 <font class="comment">// ***************************************************************************</font> +02236 <font class="comment">// Tiles get interface.</font> +02237 <font class="comment">// ***************************************************************************</font> +02238 <font class="comment">// ***************************************************************************</font> +02239 +02240 +02241 <font class="comment">// ***************************************************************************</font> +<a name="l02242"></a><a class="code" href="classNL3D_1_1CPatch.html#z672_0">02242</a> CTileElement *CPatch::getTileElement(<font class="keyword">const</font> CUV &uv) +02243 { +02244 <font class="comment">// compute tile coord and lumel coord.</font> +02245 sint ts, tt; +02246 +02247 <font class="comment">// fastFloor: use a precision of 256 to avoid doing OptFastFloorBegin.</font> +02248 <font class="comment">// add 128, to round and get cneter of lumel.</font> +02249 ts= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(uv.U* (<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a><<8) + 128); ts>>=8; +02250 tt= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(uv.V* (<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a><<8) + 128); tt>>=8; +02251 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(ts, 0, <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>-1); +02252 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tt, 0, <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>-1); +02253 +02254 <font class="comment">// get the lumel</font> +02255 <font class="keywordflow">return</font> &(<a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[ts+tt*<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>]); +02256 } +02257 +02258 +02259 } <font class="comment">// NL3D</font> +02260 +</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> |