diff options
author | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2018-08-11 20:21:34 +0200 |
commit | 0ea5fc66924303d1bf73ba283a383e2aadee02f2 (patch) | |
tree | 2568e71a7ccc44ec23b8bb3f0ff97fb6bf2ed709 /docs/doxygen/nel/mini__col_8cpp-source.html | |
download | nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.tar.xz nevrax-website-self-hostable-0ea5fc66924303d1bf73ba283a383e2aadee02f2.zip |
Initial commit
Diffstat (limited to 'docs/doxygen/nel/mini__col_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/mini__col_8cpp-source.html | 559 |
1 files changed, 559 insertions, 0 deletions
diff --git a/docs/doxygen/nel/mini__col_8cpp-source.html b/docs/doxygen/nel/mini__col_8cpp-source.html new file mode 100644 index 00000000..2ae8b854 --- /dev/null +++ b/docs/doxygen/nel/mini__col_8cpp-source.html @@ -0,0 +1,559 @@ +<!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>mini_col.cpp</h1><a href="mini__col_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2000 Nevrax Ltd.</font> +00008 <font class="comment"> *</font> +00009 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00013 <font class="comment"> * any later version.</font> +00014 <font class="comment"></font> +00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"></font> +00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00023 <font class="comment"> * MA 02111-1307, USA.</font> +00024 <font class="comment"> */</font> +00025 +00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font> +00027 +00028 <font class="preprocessor">#include "<a class="code" href="mini__col_8h.html">3d/mini_col.h</a>"</font> +00029 <font class="preprocessor">#include "<a class="code" href="aabbox_8h.html">nel/misc/aabbox.h</a>"</font> +00030 <font class="preprocessor">#include "<a class="code" href="3d_2quad__grid_8h.html">3d/quad_grid.h</a>"</font> +00031 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00032 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00033 +00034 +00035 <font class="keyword">namespace </font>NL3D +00036 { +00037 +00038 <font class="keyword">static</font> <font class="keyword">const</font> sint <a class="code" href="namespaceNL3D.html#a157">QuadDepth</a>= 10; +00039 +00040 +00041 <font class="comment">// Element for grid lookup.</font> +00042 <font class="keyword">static</font> <font class="keyword">const</font> sint <a class="code" href="namespaceNL3D.html#a158">GridSize</a>=512; +00043 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">float</font> <a class="code" href="namespaceNL3D.html#a159">GridEltSize</a>=2; +00044 +00045 +00046 <font class="comment">// ***************************************************************************</font> +<a name="l00047"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a0">00047</a> CMiniCol::CMiniCol() +00048 { +00049 <a class="code" href="classNL3D_1_1CMiniCol.html#o1">_RadMin</a>= 100; +00050 <a class="code" href="classNL3D_1_1CMiniCol.html#o2">_RadMax</a>= 125; +00051 <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.create(<a class="code" href="namespaceNL3D.html#a158">GridSize</a>, <a class="code" href="namespaceNL3D.html#a159">GridEltSize</a>); +00052 } +00053 +00054 +00055 <font class="comment">// ***************************************************************************</font> +<a name="l00056"></a><a class="code" href="classNL3D_1_1CMiniCol.html#c0">00056</a> <font class="keywordtype">void</font> CMiniCol::addFaces(<font class="keyword">const</font> std::vector<CTriangle> &faces, uint16 zoneId, uint16 patchId) +00057 { +00058 <font class="keywordflow">for</font>(sint i=0;i<(sint)faces.size();i++) +00059 { +00060 <font class="keyword">const</font> CTriangle &f= faces[i]; +00061 CAABBox box; +00062 box.setCenter(f.V0); +00063 box.extend(f.V1); +00064 box.extend(f.V2); +00065 CFace node; +00066 node.Face= f; +00067 node.Plane.make(f.V0, f.V1, f.V2); +00068 node.ZoneId= zoneId; +00069 node.PatchId=patchId; +00070 <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.insert(box.getMin(), box.getMax(), node); +00071 } +00072 } +00073 +00074 +00075 <font class="comment">// ***************************************************************************</font> +<a name="l00076"></a><a class="code" href="classNL3D_1_1CMiniCol.html#c1">00076</a> <font class="keywordtype">void</font> CMiniCol::addLandscapePart(uint16 zoneId, uint16 patchId) +00077 { +00078 vector<CTriangle> faces; +00079 <a class="code" href="classNL3D_1_1CMiniCol.html#o0">_Landscape</a>->buildCollideFaces(zoneId, patchId, faces); +00080 <a class="code" href="classNL3D_1_1CMiniCol.html#c0">addFaces</a>(faces, zoneId, patchId); +00081 } +00082 +00083 +00084 <font class="comment">// ***************************************************************************</font> +<a name="l00085"></a><a class="code" href="classNL3D_1_1CMiniCol.html#c2">00085</a> <font class="keywordtype">void</font> CMiniCol::removeLandScapePart(uint16 zoneId, uint16 patchId, <font class="keyword">const</font> CBSphere &sphere) +00086 { +00087 <font class="comment">// Build the AAbox which englobe the bsphere of the patch.</font> +00088 CAABBox bb; +00089 bb.setCenter(sphere.Center); +00090 <font class="keywordtype">float</font> <a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>= sphere.Radius; +00091 bb.setHalfSize(CVector(<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>,<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>,<a class="code" href="namespaceNLAISCRIPT.html#a20">l</a>)); +00092 +00093 <font class="comment">// For optimisation, select only faces which are IN the bbox of the patch.</font> +00094 <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.select(bb.getMin(), bb.getMax()); +00095 CQuadGrid<CFace>::CIterator iFace; +00096 <font class="keywordflow">for</font>(iFace= <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.begin();iFace!=<a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.end();) +00097 { +00098 <font class="keywordflow">if</font>((*iFace).isFromPatch(zoneId, patchId)) +00099 iFace= <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.erase(iFace); +00100 <font class="keywordflow">else</font> +00101 iFace++; +00102 } +00103 } +00104 +00105 +00106 <font class="comment">// ***************************************************************************</font> +<a name="l00107"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a1">00107</a> <font class="keywordtype">void</font> CMiniCol::init(CLandscape *land, <font class="keywordtype">float</font> radMin, <font class="keywordtype">float</font> radDelta) +00108 { +00109 <a class="code" href="classNL3D_1_1CMiniCol.html#o0">_Landscape</a>= land; +00110 <a class="code" href="classNL3D_1_1CMiniCol.html#o1">_RadMin</a>= radMin; +00111 <a class="code" href="classNL3D_1_1CMiniCol.html#o2">_RadMax</a>= radMin+radDelta; +00112 } +00113 +00114 +00115 <font class="comment">// ***************************************************************************</font> +<a name="l00116"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a2">00116</a> <font class="keywordtype">void</font> CMiniCol::addZone(uint16 zoneId) +00117 { +00118 CZoneIdent newZone; +00119 +00120 <font class="comment">// landscape must have been inited.</font> +00121 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CMiniCol.html#o0">_Landscape</a>); +00122 <font class="keyword">const</font> CZone *zone= <a class="code" href="classNL3D_1_1CMiniCol.html#o0">_Landscape</a>->getZone(zoneId); +00123 <font class="comment">// zone must be loaded into landscape.</font> +00124 <a class="code" href="debug_8h.html#a6">nlassert</a>(zone); +00125 +00126 <font class="comment">// Fill the newzone.</font> +00127 newZone.ZoneId= zoneId; +00128 newZone.Sphere.Center= zone->getZoneBB().getCenter(); +00129 newZone.Sphere.Radius= zone->getZoneBB().getRadius(); +00130 newZone.Patchs.resize(zone->getNumPatchs()); +00131 <font class="keywordflow">for</font>(sint i=0;i<zone->getNumPatchs();i++) +00132 { +00133 <font class="keyword">const</font> CPatch &pa= *zone->getPatch(i); +00134 newZone.Patchs[i].Sphere= pa.getBSphere(); +00135 } +00136 +00137 <font class="comment">// Add it to the set (if not already done...).</font> +00138 <a class="code" href="classNL3D_1_1CMiniCol.html#o4">_Zones</a>.insert(newZone); +00139 } +00140 +00141 +00142 <font class="comment">// ***************************************************************************</font> +<a name="l00143"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a3">00143</a> <font class="keywordtype">void</font> CMiniCol::removeZone(uint16 zoneId) +00144 { +00145 CZoneIdent delZone; +00146 +00147 +00148 <font class="comment">// First, delete all patch from the grid.</font> +00149 <font class="comment">//=======================================</font> +00150 <font class="comment">// Fill the key part only.</font> +00151 delZone.ZoneId= zoneId; +00152 <font class="comment">// Find the zone (or quit).</font> +00153 TZoneSet::iterator itZone; +00154 itZone= <a class="code" href="classNL3D_1_1CMiniCol.html#o4">_Zones</a>.find(delZone); +00155 <font class="keywordflow">if</font>(itZone==<a class="code" href="classNL3D_1_1CMiniCol.html#o4">_Zones</a>.end()) +00156 <font class="keywordflow">return</font>; +00157 +00158 CZoneIdent &zone= const_cast<CZoneIdent&>(*itZone); +00159 <font class="keywordflow">for</font>(sint i=0;i<(sint)zone.Patchs.size();i++) +00160 { +00161 CPatchIdent &pa= zone.Patchs[i]; +00162 <font class="keywordflow">if</font>(pa.Inserted) +00163 { +00164 <font class="comment">// Reject the patch.</font> +00165 <a class="code" href="classNL3D_1_1CMiniCol.html#c2">removeLandScapePart</a>(zone.ZoneId, i, pa.Sphere); +00166 pa.Inserted= <font class="keyword">false</font>; +00167 zone.NPatchInserted--; +00168 } +00169 } +00170 +00171 <font class="comment">// Then, delete it.</font> +00172 <font class="comment">//=================</font> +00173 <a class="code" href="classNL3D_1_1CMiniCol.html#o4">_Zones</a>.erase(delZone); +00174 +00175 } +00176 +00177 +00178 <font class="comment">// ***************************************************************************</font> +<a name="l00179"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a4">00179</a> <font class="keywordtype">void</font> CMiniCol::setCenter(<font class="keyword">const</font> CVector& center) +00180 { +00181 CBSphere BMin(center, <a class="code" href="classNL3D_1_1CMiniCol.html#o1">_RadMin</a>), BMax(center, <a class="code" href="classNL3D_1_1CMiniCol.html#o2">_RadMax</a>); +00182 +00183 <font class="comment">// For all zones, test if must insert patchs..</font> +00184 TZoneSet::iterator itZone; +00185 <font class="keywordflow">for</font>(itZone= <a class="code" href="classNL3D_1_1CMiniCol.html#o4">_Zones</a>.begin();itZone!=<a class="code" href="classNL3D_1_1CMiniCol.html#o4">_Zones</a>.end();itZone++) +00186 { +00187 CZoneIdent &zone= const_cast<CZoneIdent&>(*itZone); +00188 +00189 <font class="comment">// Tests must be done in 2D...</font> +00190 BMin.Center.z= zone.Sphere.Center.z; +00191 BMax.Center.z= zone.Sphere.Center.z; +00192 +00193 <font class="comment">// Must test first if the zone is IN the area.</font> +00194 <font class="comment">//=============================================</font> +00195 <font class="keywordtype">bool</font> zoneIn= <font class="keyword">false</font>; +00196 <font class="keywordflow">if</font>(zone.NPatchInserted==0) +00197 { +00198 <font class="keywordflow">if</font>(BMin.intersect(zone.Sphere)) +00199 zoneIn= <font class="keyword">true</font>; +00200 } +00201 <font class="keywordflow">else</font> +00202 zoneIn= <font class="keyword">true</font>; +00203 +00204 <font class="comment">// Then for all patchs, must test if the patch must be inserted, or rejected.</font> +00205 <font class="comment">//=============================================</font> +00206 <font class="keywordflow">if</font>(zoneIn) +00207 { +00208 <font class="keywordflow">for</font>(sint i=0;i<(sint)zone.Patchs.size();i++) +00209 { +00210 CPatchIdent &pa= zone.Patchs[i]; +00211 +00212 <font class="comment">// Tests must be done in 2D...</font> +00213 BMin.Center.z= pa.Sphere.Center.z; +00214 BMax.Center.z= pa.Sphere.Center.z; +00215 +00216 <font class="keywordflow">if</font>(pa.Inserted) +00217 { +00218 <font class="comment">// Reject the patch, if entirely OUT the max radius.</font> +00219 <font class="keywordflow">if</font>(!BMax.intersect(pa.Sphere)) +00220 { +00221 <a class="code" href="classNL3D_1_1CMiniCol.html#c2">removeLandScapePart</a>(zone.ZoneId, i, pa.Sphere); +00222 pa.Inserted= <font class="keyword">false</font>; +00223 zone.NPatchInserted--; +00224 } +00225 } +00226 <font class="keywordflow">else</font> +00227 { +00228 <font class="comment">// Insert the pacth, if only partially IN the min radius.</font> +00229 <font class="keywordflow">if</font>(BMin.intersect(pa.Sphere)) +00230 { +00231 <a class="code" href="classNL3D_1_1CMiniCol.html#c1">addLandscapePart</a>(zone.ZoneId, i); +00232 pa.Inserted= <font class="keyword">true</font>; +00233 zone.NPatchInserted++; +00234 } +00235 } +00236 } +00237 } +00238 } +00239 } +00240 +00241 +00242 <font class="comment">// ***************************************************************************</font> +<a name="l00243"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a6">00243</a> <font class="keywordtype">bool</font> CMiniCol::snapToGround(CVector &pos, <font class="keywordtype">float</font> hup, <font class="keywordtype">float</font> hbot) +00244 { +00245 CVector b1,b2; +00246 <font class="keywordtype">bool</font> found=<font class="keyword">false</font>; +00247 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>; +00248 +00249 +00250 <font class="comment">// Select quad nodes which contains pos.</font> +00251 b1=b2=pos; +00252 b1.z-= hbot; +00253 b2.z+= hup; +00254 <font class="comment">// Select.</font> +00255 <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.select(b1,b2); +00256 +00257 <font class="comment">// For each face, test if it is under pos, then test if height is correct.</font> +00258 CQuadGrid<CFace>::CIterator iFace; +00259 <font class="keywordflow">for</font>(iFace= <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.begin();iFace!=<a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.end();iFace++) +00260 { +00261 CTriangle &pFace= (*iFace).Face; +00262 CPlane &pPlane= (*iFace).Plane; +00263 <font class="comment">// Order is important.</font> +00264 CVector &p0= pFace.V0; +00265 CVector &p1= pFace.V1; +00266 CVector &p2= pFace.V2; +00267 +00268 <font class="comment">// TOIMP: This is VERY SLOW!!! (hope that the quadtree will help, but it still very slow...).</font> +00269 +00270 <font class="comment">// Yoyo Debug, test, if the point may be IN the bbox.</font> +00271 <font class="comment">/*CAABBox bbFace;</font> +00272 <font class="comment"> bbFace.setCenter(p0);</font> +00273 <font class="comment"> bbFace.extend(p1);</font> +00274 <font class="comment"> bbFace.extend(p2);</font> +00275 <font class="comment"> CVector bext=p0;</font> +00276 <font class="comment"> bext.z= maxof(p0.z, p1.z, p2.z)+hbot;</font> +00277 <font class="comment"> bbFace.extend(bext);</font> +00278 <font class="comment"> bext.z= minof(p0.z, p1.z, p2.z)-hup;</font> +00279 <font class="comment"> bbFace.extend(bext);</font> +00280 <font class="comment"> if(!bbFace.include(pos))</font> +00281 <font class="comment"> continue;*/</font> +00282 +00283 <font class="comment">// Test if the face enclose the pos in X/Y plane.</font> +00284 <font class="comment">// NB: compute and using a BBox to do a rapid test is not a very good idea, since it will </font> +00285 <font class="comment">// add an overhead which is NOT negligeable compared to the following test.</font> +00286 <font class="keywordtype">float</font> a,b,c; <font class="comment">// 2D cartesian coefficients of line in plane X/Y.</font> +00287 <font class="comment">// Line p0-p1.</font> +00288 a= -(p1.y-p0.y); +00289 b= (p1.x-p0.x); +00290 c= -(p0.x*a + p0.y*b); +00291 <font class="keywordflow">if</font>( (a*pos.x + b*pos.y + c) < 0) <font class="keywordflow">continue</font>; +00292 <font class="comment">// Line p1-p2.</font> +00293 a= -(p2.y-p1.y); +00294 b= (p2.x-p1.x); +00295 c= -(p1.x*a + p1.y*b); +00296 <font class="keywordflow">if</font>( (a*pos.x + b*pos.y + c) < 0) <font class="keywordflow">continue</font>; +00297 <font class="comment">// Line p2-p0.</font> +00298 a= -(p0.y-p2.y); +00299 b= (p0.x-p2.x); +00300 c= -(p2.x*a + p2.y*b); +00301 <font class="keywordflow">if</font>( (a*pos.x + b*pos.y + c) < 0) <font class="keywordflow">continue</font>; +00302 +00303 +00304 <font class="comment">// Compute the possible height.</font> +00305 CVector tmp; +00306 <font class="comment">// intersect the vertical line with the plane.</font> +00307 tmp= pPlane.intersect(pos, pos-CVector(0,0,100)); +00308 +00309 <font class="comment">/*</font> +00310 <font class="comment"> // CTriangle intersect() method.</font> +00311 <font class="comment"> CVector tmp;</font> +00312 <font class="comment"> if(pFace.intersect(b1, b2, tmp, pPlane))</font> +00313 <font class="comment"> */</font> +00314 { +00315 <font class="keywordtype">float</font> h= tmp.z; +00316 <font class="comment">// Test if it would fit in the wanted field.</font> +00317 <font class="keywordflow">if</font>(h>pos.z+hup) <font class="keywordflow">continue</font>; +00318 <font class="keywordflow">if</font>(h<pos.z-hbot) <font class="keywordflow">continue</font>; +00319 +00320 <font class="comment">// OK!!</font> +00321 <font class="keywordflow">if</font>(!found) +00322 { +00323 found=<font class="keyword">true</font>; +00324 <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=h; +00325 } +00326 <font class="keywordflow">else</font> +00327 { +00328 <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>= max(<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>,h); +00329 } +00330 } +00331 } +00332 +00333 <font class="keywordflow">if</font>(found) +00334 pos.z= <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>; +00335 +00336 <font class="keywordflow">return</font> found; +00337 } +00338 +00339 +00340 +00341 <font class="comment">// ***************************************************************************</font> +<a name="l00342"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a7">00342</a> <font class="keywordtype">bool</font> CMiniCol::getGroundNormal(<font class="keyword">const</font> CVector &pos, CVector &normal, <font class="keywordtype">float</font> hup, <font class="keywordtype">float</font> hbot) +00343 { +00344 CVector b1,b2; +00345 <font class="keywordtype">bool</font> found=<font class="keyword">false</font>; +00346 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=0.0; +00347 +00348 +00349 <font class="comment">// Select quad nodes which contains pos.</font> +00350 b1=b2=pos; +00351 b1.z-= hbot; +00352 b2.z+= hup; +00353 <font class="comment">// Select.</font> +00354 <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.select(b1,b2); +00355 +00356 <font class="comment">// For each face, test if it is under pos, then test if height is correct.</font> +00357 CQuadGrid<CFace>::CIterator iFace; +00358 <font class="keywordflow">for</font>(iFace= <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.begin();iFace!=<a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.end();iFace++) +00359 { +00360 CTriangle &pFace= (*iFace).Face; +00361 CPlane &pPlane= (*iFace).Plane; +00362 <font class="comment">// Order is important.</font> +00363 CVector &p0= pFace.V0; +00364 CVector &p1= pFace.V1; +00365 CVector &p2= pFace.V2; +00366 +00367 <font class="comment">// TOIMP: This is VERY SLOW!!! (hope that the quadtree will help, but it still very slow...).</font> +00368 +00369 <font class="comment">// Yoyo Debug, test, if the point may be IN the bbox.</font> +00370 CAABBox bbFace; +00371 bbFace.setCenter(p0); +00372 bbFace.extend(p1); +00373 bbFace.extend(p2); +00374 CVector bext=p0; +00375 bext.z= maxof(p0.z, p1.z, p2.z)+hbot; +00376 bbFace.extend(bext); +00377 bext.z= minof(p0.z, p1.z, p2.z)-hup; +00378 bbFace.extend(bext); +00379 <font class="keywordflow">if</font>(!bbFace.include(pos)) +00380 <font class="keywordflow">continue</font>; +00381 +00382 <font class="comment">// Test if the face enclose the pos in X/Y plane.</font> +00383 <font class="comment">// NB: compute and using a BBox to do a rapid test is not a very good idea, since it will </font> +00384 <font class="comment">// add an overhead which is NOT negligeable compared to the following test.</font> +00385 <font class="keywordtype">float</font> a,b,c; <font class="comment">// 2D cartesian coefficients of line in plane X/Y.</font> +00386 <font class="comment">// Line p0-p1.</font> +00387 a= -(p1.y-p0.y); +00388 b= (p1.x-p0.x); +00389 c= -(p0.x*a + p0.y*b); +00390 <font class="keywordflow">if</font>( (a*pos.x + b*pos.y + c) < 0) <font class="keywordflow">continue</font>; +00391 <font class="comment">// Line p1-p2.</font> +00392 a= -(p2.y-p1.y); +00393 b= (p2.x-p1.x); +00394 c= -(p1.x*a + p1.y*b); +00395 <font class="keywordflow">if</font>( (a*pos.x + b*pos.y + c) < 0) <font class="keywordflow">continue</font>; +00396 <font class="comment">// Line p2-p0.</font> +00397 a= -(p0.y-p2.y); +00398 b= (p0.x-p2.x); +00399 c= -(p2.x*a + p2.y*b); +00400 <font class="keywordflow">if</font>( (a*pos.x + b*pos.y + c) < 0) <font class="keywordflow">continue</font>; +00401 +00402 +00403 <font class="comment">// Compute the possible height.</font> +00404 CVector tmp; +00405 <font class="comment">// intersect the vertical line with the plane.</font> +00406 tmp= pPlane.intersect(pos, pos-CVector(0,0,100)); +00407 <font class="keywordtype">float</font> h= tmp.z; +00408 <font class="comment">// Test if it would fit in the wanted field.</font> +00409 <font class="keywordflow">if</font>(h>pos.z+hup) <font class="keywordflow">continue</font>; +00410 <font class="keywordflow">if</font>(h<pos.z-hbot) <font class="keywordflow">continue</font>; +00411 +00412 <font class="comment">// OK!!</font> +00413 <font class="keywordflow">if</font>(!found) +00414 { +00415 found=<font class="keyword">true</font>; +00416 <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=h; +00417 normal= pPlane.getNormal(); +00418 } +00419 <font class="keywordflow">else</font> +00420 { +00421 <font class="keywordflow">if</font>(h><a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>) +00422 { +00423 normal= pPlane.getNormal(); +00424 <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>= h; +00425 } +00426 } +00427 } +00428 +00429 <font class="keywordflow">return</font> found; +00430 } +00431 +00432 +00433 <font class="comment">// ***************************************************************************</font> +<a name="l00434"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a5">00434</a> <font class="keywordtype">bool</font> CMiniCol::testMove(<font class="keyword">const</font> CVector &prec, CVector &cur) +00435 { +00436 CVector dir= cur-prec; +00437 dir.normalize(); +00438 +00439 <font class="comment">// Angle max.</font> +00440 <font class="keywordtype">float</font> anglemax= 65; <font class="comment">// 65 degrees.</font> +00441 anglemax= (float)tan( anglemax*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/180); +00442 +00443 <font class="comment">// Must not go to near of a wall.</font> +00444 CVector test= cur+dir*0.5; +00445 <font class="keywordtype">float</font> norm= (test-prec).norm(); +00446 norm*=anglemax; +00447 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CMiniCol.html#a6">snapToGround</a>(test, norm, norm)) +00448 { +00449 cur= prec; +00450 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00451 } +00452 <font class="keywordflow">else</font> +00453 { +00454 <font class="comment">// Must test and snap the current position.</font> +00455 norm= (cur-prec).norm(); +00456 norm*=anglemax; +00457 <font class="keywordflow">if</font>(!<a class="code" href="classNL3D_1_1CMiniCol.html#a6">snapToGround</a>(cur, norm, norm)) +00458 { +00459 cur= prec; +00460 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00461 } +00462 } +00463 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00464 } +00465 +00466 +00467 <font class="comment">// ***************************************************************************</font> +<a name="l00468"></a><a class="code" href="classNL3D_1_1CMiniCol.html#a8">00468</a> <font class="keywordtype">void</font> CMiniCol::getFaces(std::vector<CTriangle> &triresult, <font class="keyword">const</font> CAABBox &bbox) +00469 { +00470 triresult.clear(); +00471 +00472 <font class="comment">// Select.</font> +00473 <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.select(bbox.getMin(),bbox.getMax()); +00474 +00475 <font class="comment">// For each face, test if it is under pos, then test if height is correct.</font> +00476 CQuadGrid<CFace>::CIterator iFace; +00477 <font class="keywordflow">for</font>(iFace= <a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.begin();iFace!=<a class="code" href="classNL3D_1_1CMiniCol.html#o3">_Grid</a>.end();iFace++) +00478 { +00479 CTriangle &face= (*iFace).Face; +00480 +00481 <font class="keywordflow">if</font>(bbox.intersect(face.V0, face.V1, face.V2)) +00482 { +00483 triresult.push_back(face); +00484 } +00485 } +00486 +00487 } +00488 +00489 +00490 } <font class="comment">// NL3D</font> +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </FONT> +</TD> +<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD> +</TR> +</TABLE> +</BODY> +</HTML> |