aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/mini__col_8cpp-source.html
blob: 84e4b4873dac03096619ac1e4fce9c73d34459dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
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="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/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="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/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="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </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&lt;CTriangle&gt; &amp;faces, uint16 zoneId, uint16 patchId)
00057 {
00058         <font class="keywordflow">for</font>(sint i=0;i&lt;(sint)faces.size();i++)
00059         {
00060                 <font class="keyword">const</font> CTriangle &amp;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&lt;CTriangle&gt; faces;
00079         <a class="code" href="classNL3D_1_1CMiniCol.html#o0">_Landscape</a>-&gt;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 &amp;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&lt;CFace&gt;::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>-&gt;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-&gt;getZoneBB().getCenter();
00129         newZone.Sphere.Radius= zone-&gt;getZoneBB().getRadius();
00130         newZone.Patchs.resize(zone-&gt;getNumPatchs());
00131         <font class="keywordflow">for</font>(sint i=0;i&lt;zone-&gt;getNumPatchs();i++)
00132         {
00133                 <font class="keyword">const</font>   CPatch  &amp;pa= *zone-&gt;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      &amp;zone= const_cast&lt;CZoneIdent&amp;&gt;(*itZone);
00159         <font class="keywordflow">for</font>(sint i=0;i&lt;(sint)zone.Patchs.size();i++)
00160         {
00161                 CPatchIdent     &amp;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&amp; 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      &amp;zone= const_cast&lt;CZoneIdent&amp;&gt;(*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&lt;(sint)zone.Patchs.size();i++)
00209                         {
00210                                 CPatchIdent     &amp;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 &amp;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&lt;CFace&gt;::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       &amp;pFace= (*iFace).Face;
00262                 CPlane          &amp;pPlane= (*iFace).Plane;
00263                 <font class="comment">// Order is important.</font>
00264                 CVector         &amp;p0= pFace.V0;
00265                 CVector         &amp;p1= pFace.V1;
00266                 CVector         &amp;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) &lt; 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) &lt; 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) &lt; 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&gt;pos.z+hup) <font class="keywordflow">continue</font>;
00318                         <font class="keywordflow">if</font>(h&lt;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 &amp;pos, CVector &amp;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&lt;CFace&gt;::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       &amp;pFace= (*iFace).Face;
00361                 CPlane          &amp;pPlane= (*iFace).Plane;
00362                 <font class="comment">// Order is important.</font>
00363                 CVector         &amp;p0= pFace.V0;
00364                 CVector         &amp;p1= pFace.V1;
00365                 CVector         &amp;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) &lt; 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) &lt; 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) &lt; 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&gt;pos.z+hup) <font class="keywordflow">continue</font>;
00410                 <font class="keywordflow">if</font>(h&lt;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&gt;<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 &amp;prec, CVector &amp;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&lt;CTriangle&gt;       &amp;triresult, <font class="keyword">const</font> CAABBox &amp;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&lt;CFace&gt;::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       &amp;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>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>