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
|
<!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>meshvp_wind_tree.cpp</h1><a href="meshvp__wind__tree_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2000-2002 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="meshvp__wind__tree_8h.html">3d/meshvp_wind_tree.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="mesh__base__instance_8h.html">3d/mesh_base_instance.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="scene_8h.html">3d/scene.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="driver_8h.html">3d/driver.h</a>"</font>
00032 <font class="preprocessor">#include <math.h></font>
00033 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="render__trav_8h.html">3d/render_trav.h</a>"</font>
00035
00036
00037 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00038 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00039
00040
00041 <font class="keyword">namespace </font>NL3D
00042 {
00043
00044
00045 <font class="comment">// ***************************************************************************</font>
00046 <font class="comment">// Light VP fragment constants start at 24</font>
00047 <font class="keyword">static</font> <font class="keyword">const</font> uint <a class="code" href="namespaceNL3D.html#a145">VPLightConstantStart</a>= 24;
00048
00049
00050 <font class="comment">// ***************************************************************************</font>
<a name="l00051"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#r0">00051</a> std::auto_ptr<CVertexProgram> CMeshVPWindTree::_VertexProgram[CMeshVPWindTree::NumVp];
00052
00053 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a155">WindTreeVPCodeWave</a>=
00054 <font class="stringliteral">"!!VP1.0 \n\</font>
00055 <font class="stringliteral"> # extract from color.R the 3 factors into R0.xyz \n\</font>
00056 <font class="stringliteral"> MAD R0, v[3].x, c[9].x, c[9].yzww; # col.R*3 \n\</font>
00057 <font class="stringliteral"> MIN R0, R0, c[8].yyyy; # clamp each to 0,1 \n\</font>
00058 <font class="stringliteral"> MAX R0, R0, c[8].xxxx; \n\</font>
00059 <font class="stringliteral"> \n\</font>
00060 <font class="stringliteral"> # Add influence of Bone Level1 \n\</font>
00061 <font class="stringliteral"> MAD R5, c[15], R0.x, v[0]; \n\</font>
00062 <font class="stringliteral"> \n\</font>
00063 <font class="stringliteral"> # Sample LevelPhase into R7.yz: 0 to 3. \n\</font>
00064 <font class="stringliteral"> MUL R7, v[3].xyzw, c[10].x; \n\</font>
00065 <font class="stringliteral"> \n\</font>
00066 <font class="stringliteral"> # Add influence of Bone Level2 \n\</font>
00067 <font class="stringliteral"> ARL A0.x, R7.y; \n\</font>
00068 <font class="stringliteral"> MAD R5, c[A0.x+16], R0.y, R5; \n\</font>
00069 <font class="stringliteral"> \n\</font>
00070 <font class="stringliteral"> # Add influence of Bone Level3 \n\</font>
00071 <font class="stringliteral"> ARL A0.x, R7.z; \n\</font>
00072 <font class="stringliteral"> MAD R5, c[A0.x+20], R0.z, R5; \n\</font>
00073 <font class="stringliteral"> \n\</font>
00074 <font class="stringliteral"> # Get normal in R6 for lighting. \n\</font>
00075 <font class="stringliteral"> MOV R6, v[2]; \n\</font>
00076 <font class="stringliteral">"</font>;
00077
00078 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font>* <a class="code" href="namespaceNL3D.html#a156">WindTreeVPCodeEnd</a>=
00079 <font class="stringliteral">" # compute in Projection space \n\</font>
00080 <font class="stringliteral"> DP4 o[HPOS].x, c[0], R5; \n\</font>
00081 <font class="stringliteral"> DP4 o[HPOS].y, c[1], R5; \n\</font>
00082 <font class="stringliteral"> DP4 o[HPOS].z, c[2], R5; \n\</font>
00083 <font class="stringliteral"> DP4 o[HPOS].w, c[3], R5; \n\</font>
00084 <font class="stringliteral"> MOV o[TEX0].xy, v[8]; \n\</font>
00085 <font class="stringliteral"> MOV o[TEX1].xy, v[9]; \n\</font>
00086 <font class="stringliteral"> DP4 o[FOGC].x, c[6], -R5; # fogc>0 => fogc= - (ModelView*R1).z \n\</font>
00087 <font class="stringliteral"> END \n\</font>
00088 <font class="stringliteral">"</font>;
00089
00090
00091 <font class="comment">// ***************************************************************************</font>
<a name="l00092"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">00092</a> <font class="keywordtype">float</font> CMeshVPWindTree::speedCos(<font class="keywordtype">float</font> angle)
00093 {
00094 <font class="comment">// \todo yoyo TODO_OPTIM</font>
00095 <font class="keywordflow">return</font> cosf(angle * 2*(<font class="keywordtype">float</font>)<a class="code" href="namespaceNLMISC.html#a7">Pi</a>);
00096 }
00097
00098
00099 <font class="comment">// ***************************************************************************</font>
<a name="l00100"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#a0">00100</a> CMeshVPWindTree::CMeshVPWindTree()
00101 {
00102 <font class="keywordflow">for</font>(uint i=0; i<<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#s1s0">HrcDepth</a>; i++)
00103 {
00104 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_0">Frequency</a>[i]= 1;
00105 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_1">FrequencyWindFactor</a>[i]= 0;
00106 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_2">PowerXY</a>[i]= 0;
00107 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_3">PowerZ</a>[i]= 0;
00108 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[i]= 0;
00109 <font class="comment">// Init currentTime.</font>
00110 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[i]= 0;
00111 }
00112 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_5">SpecularLighting</a>= <font class="keyword">false</font>;
00113
00114 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o1">_LastSceneTime</a>= 0;
00115 }
00116
00117
00118 <font class="comment">// ***************************************************************************</font>
<a name="l00119"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#a1">00119</a> CMeshVPWindTree::~CMeshVPWindTree()
00120 {
00121 }
00122
00123
00124 <font class="comment">// ***************************************************************************</font>
<a name="l00125"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z611_5">00125</a> <font class="keywordtype">void</font> CMeshVPWindTree::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &f) <font class="keywordflow">throw</font>(NLMISC::EStream)
00126 {
00127 (void)f.serialVersion(0);
00128
00129 <a class="code" href="debug_8h.html#a6">nlassert</a>(HrcDepth==3);
00130 <font class="keywordflow">for</font>(uint i=0; i<HrcDepth; i++)
00131 {
00132 f.serial(Frequency[i]);
00133 f.serial(FrequencyWindFactor[i]);
00134 f.serial(PowerXY[i]);
00135 f.serial(PowerZ[i]);
00136 f.serial(Bias[i]);
00137 }
00138 f.serial(SpecularLighting);
00139 }
00140
00141
00142 <font class="comment">// ***************************************************************************</font>
<a name="l00143"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z611_0">00143</a> <font class="keywordtype">void</font> CMeshVPWindTree::initInstance(CMeshBaseInstance *mbi)
00144 {
00145 <font class="comment">// init the vertexProgram code.</font>
00146 <font class="keyword">static</font> <font class="keywordtype">bool</font> vpCreated= <font class="keyword">false</font>;
00147 <font class="keywordflow">if</font>(!vpCreated)
00148 {
00149 vpCreated= <font class="keyword">true</font>;
00150 <font class="comment">// All vpcode and begin() written for HrcDepth==3</font>
00151 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#s1s0">HrcDepth</a>==3);
00152
00153 <font class="comment">// combine fragments.</font>
00154 string vpCode;
00155
00156 <font class="comment">// For all possible VP.</font>
00157 <font class="keywordflow">for</font>(uint i=0;i<<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#u1u0">NumVp</a>;i++)
00158 {
00159 <font class="comment">// setup of the VPLight fragment</font>
00160 uint numPls= i/4;
00161 <font class="keywordtype">bool</font> normalize= (i&1)!=0;
00162 <font class="keywordtype">bool</font> specular= (i&2)!=0;
00163
00164 <font class="comment">// combine fragments</font>
00165 vpCode= string(<a class="code" href="namespaceNL3D.html#a155">WindTreeVPCodeWave</a>)
00166 + CRenderTrav::getLightVPFragment(numPls, <a class="code" href="namespaceNL3D.html#a145">VPLightConstantStart</a>, specular, normalize)
00167 + <a class="code" href="namespaceNL3D.html#a156">WindTreeVPCodeEnd</a>;
00168 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#r0">_VertexProgram</a>[i]= std::auto_ptr<CVertexProgram>(<font class="keyword">new</font> CVertexProgram(vpCode.c_str()));
00169 }
00170 }
00171
00172 <font class="comment">// init a random phase.</font>
00173 mbi->_VPWindTreePhase= <a class="code" href="namespaceNLMISC.html#a212">frand</a>(1);
00174 }
00175 <font class="comment">// ***************************************************************************</font>
<a name="l00176"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z611_1">00176</a> <font class="keywordtype">bool</font> CMeshVPWindTree::begin(IDriver *driver, CScene *scene, CMeshBaseInstance *mbi, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &invertedModelMat, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> & <font class="comment">/*viewerPos*/</font>)
00177 {
00178 <font class="keywordflow">if</font> (!(driver->isVertexProgramSupported() && !driver->isVertexProgramEmulated())) <font class="keywordflow">return</font> <font class="keyword">false</font>;
00179
00180
00181 <font class="comment">// precompute mesh/instance.</font>
00182 <font class="comment">//===============</font>
00183
00184
00185 <font class="comment">// Get info from scene/instance</font>
00186 <font class="keywordtype">float</font> windPower= scene->getGlobalWindPower();
00187 <font class="keywordtype">float</font> instancePhase= mbi->_VPWindTreePhase;
00188
00189
00190 <font class="comment">// process current times and current power. Only one time per render() and per CMeshVPWindTree.</font>
00191 <font class="keywordflow">if</font>(scene->getCurrentTime() != <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o1">_LastSceneTime</a>)
00192 {
00193 <font class="keywordtype">float</font> dt= (float)(scene->getCurrentTime() - <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o1">_LastSceneTime</a>);
00194 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o1">_LastSceneTime</a>= scene->getCurrentTime();
00195
00196 <font class="comment">// Update each boneLevel time according to frequency.</font>
00197 uint i;
00198 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#s1s0">HrcDepth</a>; i++)
00199 {
00200 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[i]+= dt*(<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_0">Frequency</a>[i] + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_1">FrequencyWindFactor</a>[i]*windPower);
00201 <font class="comment">// get it between 0 and 1. Important for float precision problems.</font>
00202 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[i]= (float)fmod(<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[i], 1);
00203 }
00204
00205 <font class="comment">// Update each boneLevel maximum amplitude vector.</font>
00206 <font class="keywordflow">for</font>(i=0; i<<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#s1s0">HrcDepth</a>; i++)
00207 {
00208 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o2">_MaxDeltaPos</a>[i]= scene->getGlobalWindDirection() * <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_2">PowerXY</a>[i] * windPower;
00209 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o2">_MaxDeltaPos</a>[i].z= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_3">PowerZ</a>[i] * windPower;
00210 }
00211 }
00212
00213
00214 <font class="comment">// maxDeltaPos in ObjectSpace. So same world Wind direction is applied to all objects</font>
00215 <font class="keyword">static</font> CMatrix invWorldMatrix;
00216 <font class="comment">// Keep only rotation part. (just need it and faster invert)</font>
00217 invWorldMatrix.setRot(mbi->getWorldMatrix());
00218 invWorldMatrix.invert();
00219 <font class="keyword">static</font> CVector maxDeltaPosOS[<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#s1s0">HrcDepth</a>];
00220 <font class="keywordflow">for</font>(uint i=0; i<<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#s1s0">HrcDepth</a>; i++)
00221 {
00222 maxDeltaPosOS[i]= invWorldMatrix.mulVector(<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o2">_MaxDeltaPos</a>[i]);
00223 }
00224
00225
00226 <font class="comment">// Setup constants</font>
00227 <font class="comment">//===============</font>
00228
00229 <font class="comment">// Setup lighting and lighting constants</font>
00230 <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#c0">setupLighting</a>(scene, mbi, invertedModelMat);
00231
00232 <font class="comment">// c[0..3] take the ModelViewProjection Matrix. After setupModelMatrix();</font>
00233 driver->setConstantMatrix(0, IDriver::ModelViewProjection, IDriver::Identity);
00234 <font class="comment">// c[4..7] take the ModelView Matrix. After setupModelMatrix();</font>
00235 driver->setConstantMatrix(4, IDriver::ModelView, IDriver::Identity);
00236 <font class="comment">// c[8] take usefull constants.</font>
00237 <font class="keyword">static</font> <font class="keywordtype">float</font> ct8[4]= {0, 1, 0.5f, 2};
00238 driver->setConstant(8, 1, ct8);
00239 <font class="comment">// c[9] take other usefull constants.</font>
00240 <font class="keyword">static</font> <font class="keywordtype">float</font> ct9[4]= {3.f, 0.f, -1.f, -2.f};
00241 driver->setConstant(9, 1, ct9);
00242 <font class="comment">// c[10] take Number of phase (4) for level2 and 3. -0.01 to avoid int value == 4.</font>
00243 <font class="keyword">static</font> <font class="keywordtype">float</font> ct10[4]= {4-0.01f, 0, 0, 0};
00244 driver->setConstant(10, 1, ct10);
00245
00246
00247 <font class="comment">// c[15] take Wind of level 0.</font>
00248 <font class="keywordtype">float</font> f;
00249 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[0] + instancePhase;
00250 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>(f) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[0];
00251 driver->setConstant(15, maxDeltaPosOS[0]*f );
00252
00253
00254 <font class="comment">// c[16-19] take Wind of level 1.</font>
00255 <font class="comment">// Unrolled. </font>
00256 <font class="keywordtype">float</font> instTime1= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[1] + instancePhase;
00257 <font class="comment">// phase 0.</font>
00258 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime1+0 ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[1];
00259 driver->setConstant(16+0, maxDeltaPosOS[1]*f);
00260 <font class="comment">// phase 1.</font>
00261 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime1+0.25f ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[1];
00262 driver->setConstant(16+1, maxDeltaPosOS[1]*f);
00263 <font class="comment">// phase 2.</font>
00264 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime1+0.50f ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[1];
00265 driver->setConstant(16+2, maxDeltaPosOS[1]*f);
00266 <font class="comment">// phase 3.</font>
00267 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime1+0.75f ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[1];
00268 driver->setConstant(16+3, maxDeltaPosOS[1]*f);
00269
00270
00271 <font class="comment">// c[20, 23] take Wind of level 2.</font>
00272 <font class="comment">// Unrolled. </font>
00273 <font class="keywordtype">float</font> instTime2= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#o0">_CurrentTime</a>[2] + instancePhase;
00274 <font class="comment">// phase 0.</font>
00275 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime2+0 ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[2];
00276 driver->setConstant(20+0, maxDeltaPosOS[2]*f);
00277 <font class="comment">// phase 1.</font>
00278 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime2+0.25f ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[2];
00279 driver->setConstant(20+1, maxDeltaPosOS[2]*f);
00280 <font class="comment">// phase 2.</font>
00281 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime2+0.50f ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[2];
00282 driver->setConstant(20+2, maxDeltaPosOS[2]*f);
00283 <font class="comment">// phase 3.</font>
00284 f= <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#f0">speedCos</a>( instTime2+0.75f ) + <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_4">Bias</a>[2];
00285 driver->setConstant(20+3, maxDeltaPosOS[2]*f);
00286
00287
00288 <font class="comment">// Activate the good VertexProgram</font>
00289 <font class="comment">//===============</font>
00290
00291 <font class="comment">// Get how many pointLights are setuped now.</font>
00292 <a class="code" href="debug_8h.html#a6">nlassert</a>(scene != NULL);
00293 CRenderTrav *renderTrav= scene->getRenderTrav();
00294 sint numPls= renderTrav->getNumVPLights()-1;
00295 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(numPls, 0, CRenderTrav::MaxVPLight-1);
00296
00297 <font class="comment">// Enable normalize only if requested by user. Because lighting don't manage correct "scale lighting"</font>
00298 uint idVP= (<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_5">SpecularLighting</a>?2:0) + (driver->isForceNormalize()?1:0) ;
00299 <font class="comment">// correct VP id for correct unmber of pls.</font>
00300 idVP= numPls*4 + idVP;
00301
00302 <font class="comment">// activate VP.</font>
00303 driver->activeVertexProgram(<a class="code" href="classNL3D_1_1CMeshVPWindTree.html#r0">_VertexProgram</a>[idVP].get());
00304
00305
00306 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00307 }
00308 <font class="comment">// ***************************************************************************</font>
<a name="l00309"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z611_2">00309</a> <font class="keywordtype">void</font> CMeshVPWindTree::end(IDriver *driver)
00310 {
00311 <font class="comment">// Disable the VertexProgram</font>
00312 driver->activeVertexProgram(NULL);
00313 }
00314
00315 <font class="comment">// ***************************************************************************</font>
00316 <font class="comment">// tool fct</font>
00317 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a382">SetupForMaterial</a>(<font class="keyword">const</font> CMaterial &mat, CScene *scene)
00318 {
00319 CRenderTrav *renderTrav= scene->getRenderTrav();
00320 renderTrav->changeVPLightSetupMaterial(mat, <font class="keyword">false</font> <font class="comment">/* don't exclude strongest */</font>);
00321 }
00322
00323 <font class="comment">// ***************************************************************************</font>
<a name="l00324"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z611_3">00324</a> <font class="keywordtype">void</font> CMeshVPWindTree::setupForMaterial(<font class="keyword">const</font> CMaterial &mat,
00325 IDriver *drv,
00326 CScene *scene,
00327 CVertexBuffer *)
00328 {
00329 <a class="code" href="namespaceNL3D.html#a382">SetupForMaterial</a>(mat, scene);
00330 }
00331
00332 <font class="comment">// ***************************************************************************</font>
<a name="l00333"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z611_4">00333</a> <font class="keywordtype">void</font> CMeshVPWindTree::setupForMaterial(<font class="keyword">const</font> CMaterial &mat,
00334 IDriver *drv,
00335 CScene *scene,
00336 IVertexBufferHard *vb)
00337 {
00338 <a class="code" href="namespaceNL3D.html#a382">SetupForMaterial</a>(mat, scene);
00339 }
00340
00341 <font class="comment">// ***************************************************************************</font>
<a name="l00342"></a><a class="code" href="classNL3D_1_1CMeshVPWindTree.html#c0">00342</a> <font class="keywordtype">void</font> CMeshVPWindTree::setupLighting(CScene *scene, CMeshBaseInstance *mbi, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &invertedModelMat)
00343 {
00344 <a class="code" href="debug_8h.html#a6">nlassert</a>(scene != NULL);
00345 CRenderTrav *renderTrav= scene->getRenderTrav();
00346 <font class="comment">// setup cte for lighting</font>
00347 renderTrav->beginVPLightSetup(<a class="code" href="namespaceNL3D.html#a145">VPLightConstantStart</a>, <a class="code" href="classNL3D_1_1CMeshVPWindTree.html#z610_5">SpecularLighting</a>, invertedModelMat);
00348 }
00349
00350 } <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>
|