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
|
<!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> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><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="/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>
<!-- 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> </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:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>vegetable.cpp</h1><a href="vegetable_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00027
00028 <font class="preprocessor">#include "<a class="code" href="vegetable_8h.html">3d/vegetable.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="vegetable__manager_8h.html">3d/vegetable_manager.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
00032
00033
00034 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00035 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00036
00037
00038 <font class="keyword">namespace </font>NL3D
00039 {
00040
00041
00042 <font class="comment">// ***************************************************************************</font>
00043 <font class="comment">// Generate random value, but seed is spacial. Take a high frequency, so it gets more the aspect of random.</font>
00044 <font class="keyword">static</font> CNoiseValue <a class="code" href="namespaceNL3D.html#a472">RandomGenerator</a>(0,1, 7.68f);
00045
00046
00047 <font class="comment">// ***************************************************************************</font>
<a name="l00048"></a><a class="code" href="classNL3D_1_1CVegetable.html#a0">00048</a> CVegetable::CVegetable()
00049 {
00050 <font class="comment">// Ground style density.</font>
00051 <a class="code" href="classNL3D_1_1CVegetable.html#z878_1">setAngleGround</a>(0);
00052
00053 <font class="comment">// Density not maximised.</font>
00054 <a class="code" href="classNL3D_1_1CVegetable.html#m2">MaxDensity</a>= -1;
00055
00056 <font class="comment">// No scale.</font>
00057 <a class="code" href="classNL3D_1_1CVegetable.html#m3">Sxy</a>.Abs= <a class="code" href="classNL3D_1_1CVegetable.html#m4">Sz</a>.Abs= 1;
00058 <a class="code" href="classNL3D_1_1CVegetable.html#m3">Sxy</a>.Rand= <a class="code" href="classNL3D_1_1CVegetable.html#m4">Sz</a>.Rand= 0;
00059 <font class="comment">// No rotation.</font>
00060 <a class="code" href="classNL3D_1_1CVegetable.html#m5">Rx</a>.Abs= <a class="code" href="classNL3D_1_1CVegetable.html#m6">Ry</a>.Abs= <a class="code" href="classNL3D_1_1CVegetable.html#m7">Rz</a>.Abs= 0;
00061 <a class="code" href="classNL3D_1_1CVegetable.html#m5">Rx</a>.Rand= <a class="code" href="classNL3D_1_1CVegetable.html#m6">Ry</a>.Rand= <a class="code" href="classNL3D_1_1CVegetable.html#m7">Rz</a>.Rand= 0;
00062 <font class="comment">// No BendFactor.</font>
00063 <a class="code" href="classNL3D_1_1CVegetable.html#m8">BendFactor</a>.Abs= 1;
00064 <a class="code" href="classNL3D_1_1CVegetable.html#m8">BendFactor</a>.Rand= 0;
00065 <a class="code" href="classNL3D_1_1CVegetable.html#m10">BendFrequencyFactor</a>= 1;
00066
00067 <font class="comment">// Appear at 0.</font>
00068 <a class="code" href="classNL3D_1_1CVegetable.html#m12">DistType</a>= 0;
00069
00070 <a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>= NULL;
00071 }
00072
00073
00074 <font class="comment">// ***************************************************************************</font>
<a name="l00075"></a><a class="code" href="classNL3D_1_1CVegetable.html#z878_1">00075</a> <font class="keywordtype">void</font> CVegetable::setAngleGround(<font class="keywordtype">float</font> cosAngleMin)
00076 {
00077 <a class="code" href="classNL3D_1_1CVegetable.html#o4">_AngleType</a>= <a class="code" href="classNL3D_1_1CVegetable.html#z878_0s4">AngleGround</a>;
00078
00079 <a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a>= cosAngleMin;
00080 <font class="comment">// We must be at densityFactor==1, when cosAngle==1, keeping the same formula.</font>
00081 <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>= 1 + (1-cosAngleMin);
00082
00083 <font class="comment">// precalc</font>
00084 <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>= (<a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a> + <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>)/2;
00085 <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>= <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a> - <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>;
00086 <font class="keywordflow">if</font>(_OOCosAngleDist)
00087 <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>= 1.0f / <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>;
00088 }
00089
00090 <font class="comment">// ***************************************************************************</font>
<a name="l00091"></a><a class="code" href="classNL3D_1_1CVegetable.html#z878_2">00091</a> <font class="keywordtype">void</font> CVegetable::setAngleCeiling(<font class="keywordtype">float</font> cosAngleMax)
00092 {
00093 <a class="code" href="classNL3D_1_1CVegetable.html#o4">_AngleType</a>= <a class="code" href="classNL3D_1_1CVegetable.html#z878_0s5">AngleCeiling</a>;
00094
00095 <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>= cosAngleMax;
00096 <font class="comment">// We must be at densityFactor==1, when cosAngle==-1, keeping the same formula.</font>
00097 <a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a>= -1 - (cosAngleMax-(-1));
00098
00099 <font class="comment">// precalc</font>
00100 <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>= (<a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a> + <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>)/2;
00101 <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>= <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a> - <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>;
00102 <font class="keywordflow">if</font>(_OOCosAngleDist)
00103 <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>= 1.0f / <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>;
00104 }
00105
00106 <font class="comment">// ***************************************************************************</font>
<a name="l00107"></a><a class="code" href="classNL3D_1_1CVegetable.html#z878_3">00107</a> <font class="keywordtype">void</font> CVegetable::setAngleWall(<font class="keywordtype">float</font> cosAngleMin, <font class="keywordtype">float</font> cosAngleMax)
00108 {
00109 <a class="code" href="classNL3D_1_1CVegetable.html#o4">_AngleType</a>= <a class="code" href="classNL3D_1_1CVegetable.html#z878_0s6">AngleWall</a>;
00110
00111 <a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a>= cosAngleMin;
00112 <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>= cosAngleMax;
00113
00114 <font class="comment">// precalc</font>
00115 <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>= (<a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a> + <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>)/2;
00116 <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>= <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a> - <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>;
00117 <font class="keywordflow">if</font>(_OOCosAngleDist)
00118 <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>= 1.0f / <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>;
00119 }
00120
00121
00122 <font class="comment">// ***************************************************************************</font>
<a name="l00123"></a><a class="code" href="classNL3D_1_1CVegetable.html#a1">00123</a> <font class="keywordtype">void</font> CVegetable::registerToManager(CVegetableManager *manager)
00124 {
00125 <a class="code" href="debug_8h.html#a6">nlassert</a>(manager);
00126 <a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>= manager;
00127 <a class="code" href="classNL3D_1_1CVegetable.html#o6">_VegetableShape</a>= <a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>->getVegetableShape(<a class="code" href="classNL3D_1_1CVegetable.html#m0">ShapeName</a>);
00128 }
00129
00130
00131 <font class="comment">// ***************************************************************************</font>
<a name="l00132"></a><a class="code" href="classNL3D_1_1CVegetable.html#c0">00132</a> <font class="keywordtype">void</font> CVegetable::generateGroupEx(<font class="keywordtype">float</font> nbInst, <font class="keyword">const</font> CVector &posInWorld, <font class="keyword">const</font> CVector &surfaceNormal, uint vegetSeed, std::vector<CVector2f> &instances)<font class="keyword"> const</font>
00133 <font class="keyword"></font>{
00134
00135 <font class="comment">// Density modulation.</font>
00136 <font class="comment">//===================</font>
00137
00138 <font class="comment">// compute cos of angle between surfaceNormal and K(0,0,1).</font>
00139 <font class="keywordtype">float</font> cosAngle= surfaceNormal.z;
00140 <font class="comment">// compute angleFactor density. Use a quadratic, because f'(_CosAngleMiddle)==0.</font>
00141 <font class="keywordtype">float</font> angleFact= 1 - <a class="code" href="namespaceNLMISC.html#a214">sqr</a>((cosAngle - <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>) * <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>);
00142 angleFact= max(0.f, angleFact);
00143 <font class="comment">// modulate density with angleFactor.</font>
00144 nbInst*= angleFact;
00145
00146 <font class="comment">// Now, 0<=nbInst<+oo. If we have 0.1, it means that we have 10% chance to spawn an instance.</font>
00147 <font class="comment">// So add a "random" value (with help of a noise with High frequency)</font>
00148 <font class="comment">// if nbInst==0, we should never have any instance (which may arise if evalOneLevelRandom()==1).</font>
00149 <font class="comment">// hence the 0.99f* which ensure that we do nbInst+= [0..1[.</font>
00150 nbInst+= 0.99f * <a class="code" href="namespaceNL3D.html#a472">RandomGenerator</a>.evalOneLevelRandom(posInWorld);
00151
00152 <font class="comment">// and then get only the integral part.</font>
00153 sint nbInstances= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(nbInst);
00154 nbInstances= max(0, nbInstances);
00155
00156 <font class="comment">// resize the instances</font>
00157 instances.resize(nbInstances);
00158
00159 <font class="comment">// Position generation.</font>
00160 <font class="comment">//===================</font>
00161 <font class="comment">// For now, generate them randomly.</font>
00162 <font class="keyword">static</font> CVector2f dSeed(0.513f, 0.267f); <font class="comment">// random values.</font>
00163 CVector seed= posInWorld;
00164 seed.z+= vegetSeed * 0.723f; <font class="comment">// 0.723f is a random value.</font>
00165 <font class="keywordflow">for</font>(sint i=0; i<nbInstances; i++)
00166 {
00167 instances[i].x= <a class="code" href="namespaceNL3D.html#a472">RandomGenerator</a>.evalOneLevelRandom(seed);
00168 seed.x+= dSeed.x;
00169 instances[i].y= <a class="code" href="namespaceNL3D.html#a472">RandomGenerator</a>.evalOneLevelRandom(seed);
00170 seed.y+= dSeed.y;
00171 }
00172 }
00173
00174
00175 <font class="comment">// ***************************************************************************</font>
<a name="l00176"></a><a class="code" href="classNL3D_1_1CVegetable.html#a2">00176</a> <font class="keywordtype">void</font> CVegetable::generateGroup(<font class="keyword">const</font> CVector &posInWorld, <font class="keyword">const</font> CVector &surfaceNormal, <font class="keywordtype">float</font> area, uint vegetSeed, std::vector<CVector2f> &instances)<font class="keyword"> const</font>
00177 <font class="keyword"></font>{
00178 <font class="comment">// number of instances to generate</font>
00179 <font class="keywordtype">float</font> dens= <a class="code" href="classNL3D_1_1CVegetable.html#m1">Density</a>.eval(posInWorld);
00180 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetable.html#m2">MaxDensity</a> >= 0)
00181 dens= <a class="code" href="bit__set_8cpp.html#a0">min</a>(dens, <a class="code" href="classNL3D_1_1CVegetable.html#m2">MaxDensity</a>);
00182 <font class="keywordtype">float</font> nbInst= area * dens;
00183
00184 <font class="comment">// modulate by normal and generate them.</font>
00185 <a class="code" href="classNL3D_1_1CVegetable.html#c0">generateGroupEx</a>(nbInst, posInWorld, surfaceNormal, vegetSeed, instances);
00186 }
00187
00188
00189 <font class="comment">// ***************************************************************************</font>
<a name="l00190"></a><a class="code" href="classNL3D_1_1CVegetable.html#a3">00190</a> <font class="keywordtype">void</font> CVegetable::generateGroupBiLinear(<font class="keyword">const</font> CVector &posInWorld, <font class="keyword">const</font> CVector posInWorldBorder[4], <font class="keyword">const</font> CVector &surfaceNormal, <font class="keywordtype">float</font> area, uint vegetSeed, std::vector<CVector2f> &instances)<font class="keyword"> const</font>
00191 <font class="keyword"></font>{
00192 sint i;
00193 <font class="keyword">const</font> <font class="keywordtype">float</font> evenDistribFact= 12.25f; <font class="comment">// an arbitrary value to have a higher frequency for random.</font>
00194
00195 <font class="comment">// compute how many instances to generate on borders of the patch</font>
00196 <font class="comment">// ==================</font>
00197 <font class="keywordtype">float</font> edgeDensity[4];
00198 <font class="keywordflow">for</font>(i=0; i<4; i++)
00199 {
00200 <font class="comment">// Get number of instances generated on edges</font>
00201 edgeDensity[i]= area * <a class="code" href="classNL3D_1_1CVegetable.html#m1">Density</a>.eval(posInWorldBorder[i]);
00202 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetable.html#m2">MaxDensity</a> >= 0)
00203 edgeDensity[i]= <a class="code" href="bit__set_8cpp.html#a0">min</a>(edgeDensity[i], area * <a class="code" href="classNL3D_1_1CVegetable.html#m2">MaxDensity</a>);
00204 edgeDensity[i]= max(0.f, edgeDensity[i]);
00205 }
00206 <font class="comment">// Average on center of the patch for each direction.</font>
00207 <font class="keywordtype">float</font> edgeDensityCenterX;
00208 <font class="keywordtype">float</font> edgeDensityCenterY;
00209 edgeDensityCenterX= 0.5f * (edgeDensity[0] + edgeDensity[1]);
00210 edgeDensityCenterY= 0.5f * (edgeDensity[2] + edgeDensity[3]);
00211
00212
00213 <font class="comment">// Average for all the patch</font>
00214 <font class="keywordtype">float</font> nbInstAverage= 0.5f * (edgeDensityCenterX + edgeDensityCenterY);
00215
00216
00217 <font class="comment">// generate instances on the patch</font>
00218 <font class="comment">// ==================</font>
00219 <a class="code" href="classNL3D_1_1CVegetable.html#c0">generateGroupEx</a>(nbInstAverage, posInWorld, surfaceNormal, vegetSeed, instances);
00220
00221
00222
00223 <font class="comment">// move instances x/y to follow edge repartition</font>
00224 <font class="comment">// ==================</font>
00225 <font class="comment">// If on a direction, both edges are 0 density, then must do a special formula</font>
00226 <font class="keywordtype">bool</font> middleX= edgeDensityCenterX<=1;
00227 <font class="keywordtype">bool</font> middleY= edgeDensityCenterY<=1;
00228 <font class="keywordtype">float</font> OOEdgeDCX=0.0;
00229 <font class="keywordtype">float</font> OOEdgeDCY=0.0;
00230 <font class="keywordflow">if</font>(!middleX) OOEdgeDCX= 1.0f / edgeDensityCenterX;
00231 <font class="keywordflow">if</font>(!middleY) OOEdgeDCY= 1.0f / edgeDensityCenterY;
00232 <font class="comment">// for all instances</font>
00233 <font class="keywordflow">for</font>(i=0; i<(sint)instances.size(); i++)
00234 {
00235 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= instances[i].x;
00236 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= instances[i].y;
00237 <font class="comment">// a seed for random.</font>
00238 CVector randSeed(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*evenDistribFact, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*evenDistribFact, 0);
00239
00240 <font class="comment">// X change.</font>
00241 <font class="keywordflow">if</font>(middleX)
00242 {
00243 <font class="comment">// instances are grouped at middle. this is the bijection of easeInEaseOut</font>
00244 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> - <a class="code" href="classNL3D_1_1CVegetable.html#f0">easeInEaseOut</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00245 <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> - <a class="code" href="classNL3D_1_1CVegetable.html#f0">easeInEaseOut</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>);
00246 instances[i].x= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
00247 }
00248 <font class="keywordflow">else</font>
00249 {
00250 <font class="comment">// Swap X, randomly. swap more on border</font>
00251 <font class="comment">// evaluate the density in X direction we have at this point.</font>
00252 <font class="keywordtype">float</font> densX= edgeDensity[0]*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>) + edgeDensity[1]* <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> ;
00253 <font class="comment">// If on the side of the lowest density</font>
00254 <font class="keywordflow">if</font>(densX < edgeDensityCenterX)
00255 {
00256 <font class="comment">// may swap the position </font>
00257 <font class="keywordtype">float</font> rdSwap= (densX * OOEdgeDCX );
00258 <font class="comment">// (densX * OOEdgeDCX) E [0..1[. The more it is near 0, the more is has chance to be swapped.</font>
00259 rdSwap+= <a class="code" href="namespaceNL3D.html#a472">RandomGenerator</a>.evalOneLevelRandom( randSeed );
00260 <font class="keywordflow">if</font>(rdSwap<1)
00261 instances[i].x= 1 - instances[i].x;
00262 }
00263 }
00264
00265 <font class="comment">// Y change.</font>
00266 <font class="keywordflow">if</font>(middleY)
00267 {
00268 <font class="comment">// instances are grouped at middle. this is the bijection of easeInEaseOut</font>
00269 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> - <a class="code" href="classNL3D_1_1CVegetable.html#f0">easeInEaseOut</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00270 <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> - <a class="code" href="classNL3D_1_1CVegetable.html#f0">easeInEaseOut</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>);
00271 instances[i].y= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00272 }
00273 <font class="keywordflow">else</font>
00274 {
00275 <font class="comment">// Swap Y, randomly. swap more on border</font>
00276 <font class="comment">// evaluate the density in Y direction we have at this point.</font>
00277 <font class="keywordtype">float</font> densY= edgeDensity[2]*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>) + edgeDensity[3]* <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> ;
00278 <font class="comment">// If on the side of the lowest density</font>
00279 <font class="keywordflow">if</font>(densY < edgeDensityCenterY)
00280 {
00281 <font class="comment">// may swap the position </font>
00282 <font class="keywordtype">float</font> rdSwap= (densY * OOEdgeDCY);
00283 <font class="comment">// (densY * OOEdgeDCY) E [0..1[. The more it is near 0, the more is has chance to be swapped.</font>
00284 rdSwap+= <a class="code" href="namespaceNL3D.html#a472">RandomGenerator</a>.evalOneLevelRandom( randSeed );
00285 <font class="keywordflow">if</font>(rdSwap<1)
00286 instances[i].y= 1 - instances[i].y;
00287 }
00288 }
00289
00290 }
00291
00292 }
00293
00294
00295 <font class="comment">// ***************************************************************************</font>
<a name="l00296"></a><a class="code" href="classNL3D_1_1CVegetable.html#a4">00296</a> <font class="keywordtype">void</font> CVegetable::reserveIgAddInstances(CVegetableInstanceGroupReserve &vegetIgReserve, TVegetableWater vegetWaterState, uint numInstances)<font class="keyword"> const</font>
00297 <font class="keyword"></font>{
00298 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>);
00299
00300 <font class="keywordflow">if</font> (_VegetableShape)
00301 <a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>->reserveIgAddInstances(vegetIgReserve, <a class="code" href="classNL3D_1_1CVegetable.html#o6">_VegetableShape</a>, (CVegetableManager::TVegetableWater)vegetWaterState, numInstances);
00302 }
00303
00304
00305 <font class="comment">// ***************************************************************************</font>
<a name="l00306"></a><a class="code" href="classNL3D_1_1CVegetable.html#a5">00306</a> <font class="keywordtype">void</font> CVegetable::generateInstance(CVegetableInstanceGroup *ig, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &posInWorld,
00307 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBAF.html">NLMISC::CRGBAF</a> &modulateAmbientColor, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CRGBAF.html">NLMISC::CRGBAF</a> &modulateDiffuseColor, <font class="keywordtype">float</font> blendDistMax,
00308 TVegetableWater vegetWaterState, CVegetableUV8 dlmUV)<font class="keyword"> const</font>
00309 <font class="keyword"></font>{
00310 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>);
00311
00312
00313 CVector seed= posInWorld.<a class="code" href="classNLMISC_1_1CMatrix.html#z291_4">getPos</a>();
00314
00315 <font class="comment">// Generate Matrix.</font>
00316 <font class="comment">// ===============</font>
00317
00318 <font class="comment">// Generate a random Scale / Rotation matrix.</font>
00319 CMatrix randomMat;
00320 <font class="comment">// setup rotation</font>
00321 CVector rot;
00322 rot.x= <a class="code" href="classNL3D_1_1CVegetable.html#m5">Rx</a>.eval(seed);
00323 rot.y= <a class="code" href="classNL3D_1_1CVegetable.html#m6">Ry</a>.eval(seed);
00324 rot.z= <a class="code" href="classNL3D_1_1CVegetable.html#m7">Rz</a>.eval(seed);
00325 randomMat.setRot(rot, CMatrix::ZXY);
00326 <font class="comment">// scale.</font>
00327 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CVegetable.html#m3">Sxy</a>.Abs!=0 || <a class="code" href="classNL3D_1_1CVegetable.html#m3">Sxy</a>.Rand!=0 || <a class="code" href="classNL3D_1_1CVegetable.html#m4">Sz</a>.Abs!=0 || <a class="code" href="classNL3D_1_1CVegetable.html#m4">Sz</a>.Rand!=0)
00328 {
00329 CVector scale;
00330 scale.x= scale.y= <a class="code" href="classNL3D_1_1CVegetable.html#m3">Sxy</a>.eval(seed);
00331 scale.z= <a class="code" href="classNL3D_1_1CVegetable.html#m4">Sz</a>.eval(seed);
00332 randomMat.scale(scale);
00333 }
00334
00335 <font class="comment">// Final Matrix.</font>
00336 CMatrix finalMatrix;
00337 finalMatrix= posInWorld * randomMat;
00338
00339 <font class="comment">// Generate Color and factor</font>
00340 <font class="comment">// ===============</font>
00341 CRGBAF materialColor(1,1,1,1);
00342 <font class="comment">// evaluate gradients. If none, color not modified.</font>
00343 <a class="code" href="classNL3D_1_1CVegetable.html#m11">Color</a>.eval(seed, materialColor);
00344 <font class="comment">// modulate with user</font>
00345 CRGBAF ambient, diffuse;
00346 ambient= modulateAmbientColor * materialColor;
00347 diffuse= modulateDiffuseColor * materialColor;
00348
00349 <font class="comment">// Generate a bendFactor</font>
00350 <font class="keywordtype">float</font> bendFactor= <a class="code" href="classNL3D_1_1CVegetable.html#m8">BendFactor</a>.eval(seed);
00351 <font class="comment">// Generate a bendPhase</font>
00352 <font class="keywordtype">float</font> bendPhase= <a class="code" href="classNL3D_1_1CVegetable.html#m9">BendPhase</a>.eval(seed);
00353
00354
00355 <font class="comment">// Append to the vegetableManager</font>
00356 <font class="comment">// ===============</font>
00357 <font class="keywordflow">if</font> (_VegetableShape)
00358 {
00359 <a class="code" href="classNL3D_1_1CVegetable.html#o5">_Manager</a>->addInstance(ig, <a class="code" href="classNL3D_1_1CVegetable.html#o6">_VegetableShape</a>, finalMatrix, ambient, diffuse,
00360 bendFactor, bendPhase, <a class="code" href="classNL3D_1_1CVegetable.html#m10">BendFrequencyFactor</a>, blendDistMax,
00361 (CVegetableManager::TVegetableWater)vegetWaterState, dlmUV);
00362 }
00363 }
00364
00365
00366 <font class="comment">// ***************************************************************************</font>
<a name="l00367"></a><a class="code" href="classNL3D_1_1CVegetable.html#a6">00367</a> <font class="keywordtype">void</font> CVegetable::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f)
00368 {
00369 <font class="comment">/*</font>
00370 <font class="comment"> Version 1:</font>
00371 <font class="comment"> - add BendFrequencyFactor</font>
00372 <font class="comment"> Version 0:</font>
00373 <font class="comment"> - base version</font>
00374 <font class="comment"> */</font>
00375 sint ver= f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(1);
00376
00377 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m0">ShapeName</a>);
00378 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m1">Density</a>);
00379 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m2">MaxDensity</a>);
00380 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#o0">_CosAngleMin</a>, <a class="code" href="classNL3D_1_1CVegetable.html#o1">_CosAngleMax</a>, <a class="code" href="classNL3D_1_1CVegetable.html#o2">_CosAngleMiddle</a>, <a class="code" href="classNL3D_1_1CVegetable.html#o3">_OOCosAngleDist</a>);
00381 f.<a class="code" href="classNLMISC_1_1IStream.html#a6">serialEnum</a>(<a class="code" href="classNL3D_1_1CVegetable.html#o4">_AngleType</a>);
00382 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m3">Sxy</a>, <a class="code" href="classNL3D_1_1CVegetable.html#m4">Sz</a>);
00383 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m5">Rx</a>, <a class="code" href="classNL3D_1_1CVegetable.html#m6">Ry</a>, <a class="code" href="classNL3D_1_1CVegetable.html#m7">Rz</a>);
00384 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m8">BendFactor</a>);
00385 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m9">BendPhase</a>);
00386 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m11">Color</a>);
00387 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m12">DistType</a>);
00388
00389 <font class="keywordflow">if</font>(ver>=1)
00390 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CVegetable.html#m10">BendFrequencyFactor</a>);
00391 <font class="keywordflow">else</font>
00392 <a class="code" href="classNL3D_1_1CVegetable.html#m10">BendFrequencyFactor</a>= 1;
00393 }
00394
00395
00396 } <font class="comment">// NL3D</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|