aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/lighting__manager_8cpp-source.html
blob: 15e64ace6877eded896e77a668a6d049591b4456 (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=http://www.nevrax.com><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>lighting_manager.cpp</h1><a href="lighting__manager_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="lighting__manager_8h.html">3d/lighting_manager.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="point__light_8h.html">3d/point_light.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="transform_8h.html">3d/transform.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="logic__info_8h.html">nel/3d/logic_info.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="aabbox_8h.html">nel/misc/aabbox.h</a>"</font>
00034 
00035 
00036 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00037 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00038 
00039 
00040 <font class="keyword">namespace </font>NL3D {
00041 
00042 
00043 <font class="comment">// ***************************************************************************</font>
00044 <font class="comment">/* LightQuadGrid setup. This is the same setup for StaticLightedModelQuadGrid setup.</font>
00045 <font class="comment">        NB: with this setup, a light will lies into 4*4=16 squares of a quadGrid at max.</font>
00046 <font class="comment">*/</font>
<a name="l00047"></a><a class="code" href="lighting__manager_8cpp.html#a0">00047</a> <font class="preprocessor">#define NL3D_LIGHT_QUAD_GRID_SIZE                               256</font>
<a name="l00048"></a><a class="code" href="lighting__manager_8cpp.html#a1">00048</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_LIGHT_QUAD_GRID_ELTSIZE                    10.f</font>
<a name="l00049"></a><a class="code" href="lighting__manager_8cpp.html#a2">00049</a> <font class="preprocessor"></font><font class="preprocessor">#define NL3D_LIGHT_QUAD_GRID_RADIUS_LIMIT               20.f</font>
00050 <font class="preprocessor"></font><font class="comment">// Factor for a level to the next: size/=factor, eltSize*=factor, and radiusLimit*=factor.</font>
<a name="l00051"></a><a class="code" href="lighting__manager_8cpp.html#a3">00051</a> <font class="preprocessor">#define NL3D_LIGHT_QUAD_GRID_FACTOR                             4</font>
00052 <font class="preprocessor"></font>
00053 
00054 <font class="comment">// this is a big radius for light that don't have attenuation</font>
<a name="l00055"></a><a class="code" href="lighting__manager_8cpp.html#a4">00055</a> <font class="preprocessor">#define NL3D_DEFAULT_NOATT_LIGHT_RADIUS                                 1000.f</font>
00056 <font class="preprocessor"></font><font class="comment">// this is used when the model is out of attBegin/attEnd, to modulate the influence</font>
<a name="l00057"></a><a class="code" href="lighting__manager_8cpp.html#a5">00057</a> <font class="preprocessor">#define NL3D_DEFAULT_OUT_OF_ATT_LIGHT_INF_FACTOR                0.1f</font>
00058 <font class="preprocessor"></font><font class="comment">// Defualt LightTransitionThreshold</font>
<a name="l00059"></a><a class="code" href="lighting__manager_8cpp.html#a6">00059</a> <font class="preprocessor">#define NL3D_DEFAULT_LIGHT_TRANSITION_THRESHOLD                 0.1f</font>
00060 <font class="preprocessor"></font>
00061 
00062 <font class="comment">// ***************************************************************************</font>
<a name="l00063"></a><a class="code" href="classNL3D_1_1CLightingManager.html#a0">00063</a> CLightingManager::CLightingManager()
00064 {
00065         <font class="comment">// Init the lightQuadGrids and StaticLightedModelQuadGrid</font>
00066         <font class="comment">// finer level.</font>
00067         uint    qgSize= <a class="code" href="lighting__manager_8cpp.html#a0">NL3D_LIGHT_QUAD_GRID_SIZE</a>;
00068         <font class="keywordtype">float</font>   eltSize= <a class="code" href="lighting__manager_8cpp.html#a1">NL3D_LIGHT_QUAD_GRID_ELTSIZE</a>;
00069         <font class="keywordtype">float</font>   radiusLimit= <a class="code" href="lighting__manager_8cpp.html#a2">NL3D_LIGHT_QUAD_GRID_RADIUS_LIMIT</a>;
00070         <font class="comment">// for all levels</font>
00071         <font class="keywordflow">for</font>(uint i=0;i&lt;<a class="code" href="lighting__manager_8h.html#a0">NL3D_QUADGRID_LIGHT_NUM_LEVEL</a>;i++)
00072         {
00073                 <font class="comment">// init _LightQuadGrid and _StaticLightedModelQuadGrid</font>
00074                 <a class="code" href="classNL3D_1_1CLightingManager.html#o1">_LightQuadGrid</a>[i].create(qgSize, eltSize);
00075                 <a class="code" href="classNL3D_1_1CLightingManager.html#o0">_StaticLightedModelQuadGrid</a>[i].create(qgSize, eltSize);
00076                 <a class="code" href="classNL3D_1_1CLightingManager.html#o2">_LightQuadGridRadiusLimit</a>[i]= radiusLimit;
00077 
00078                 <font class="comment">// coarser quadGrid level</font>
00079                 qgSize/= <a class="code" href="lighting__manager_8cpp.html#a3">NL3D_LIGHT_QUAD_GRID_FACTOR</a>;
00080                 qgSize= max(qgSize, 1U);
00081                 eltSize*= <a class="code" href="lighting__manager_8cpp.html#a3">NL3D_LIGHT_QUAD_GRID_FACTOR</a>;
00082                 radiusLimit*= <a class="code" href="lighting__manager_8cpp.html#a3">NL3D_LIGHT_QUAD_GRID_FACTOR</a>;
00083         }
00084 
00085 
00086         <font class="comment">// default paramters</font>
00087         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_1">_NoAttLightRadius</a>= <a class="code" href="lighting__manager_8cpp.html#a4">NL3D_DEFAULT_NOATT_LIGHT_RADIUS</a>;
00088         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_2">_OutOfAttLightInfFactor</a>= <a class="code" href="lighting__manager_8cpp.html#a5">NL3D_DEFAULT_OUT_OF_ATT_LIGHT_INF_FACTOR</a>;
00089         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_3">_LightTransitionThreshold</a>= <a class="code" href="lighting__manager_8cpp.html#a6">NL3D_DEFAULT_LIGHT_TRANSITION_THRESHOLD</a>;
00090 
00091 
00092         <font class="comment">// Default number of pointLight on an object.</font>
00093         <a class="code" href="classNL3D_1_1CLightingManager.html#z523_0">setMaxLightContribution</a>(3);
00094 }
00095 
00096 
00097 <font class="comment">// ***************************************************************************</font>
<a name="l00098"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z523_0">00098</a> <font class="keywordtype">void</font>            CLightingManager::setMaxLightContribution(uint nlights)
00099 {
00100         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_0">_MaxLightContribution</a>= <a class="code" href="bit__set_8cpp.html#a0">min</a>(nlights, (uint)<a class="code" href="light__contribution_8h.html#a0">NL3D_MAX_LIGHT_CONTRIBUTION</a>);
00101 }
00102 
00103 
00104 <font class="comment">// ***************************************************************************</font>
<a name="l00105"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z523_2">00105</a> <font class="keywordtype">void</font>            CLightingManager::setNoAttLightRadius(<font class="keywordtype">float</font> noAttLightRadius)
00106 {
00107         <a class="code" href="debug_8h.html#a6">nlassert</a>(noAttLightRadius&gt;0);
00108         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_1">_NoAttLightRadius</a>= noAttLightRadius;
00109 }
00110 
00111 
00112 <font class="comment">// ***************************************************************************</font>
<a name="l00113"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z523_4">00113</a> <font class="keywordtype">void</font>            CLightingManager::setOutOfAttLightInfFactor(<font class="keywordtype">float</font> outOfAttLightInfFactor)
00114 {
00115         outOfAttLightInfFactor= max(0.f, outOfAttLightInfFactor);
00116         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_2">_OutOfAttLightInfFactor</a>= outOfAttLightInfFactor;
00117 }
00118 
00119 
00120 <font class="comment">// ***************************************************************************</font>
<a name="l00121"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z523_6">00121</a> <font class="keywordtype">void</font>            CLightingManager::setLightTransitionThreshold(<font class="keywordtype">float</font> lightTransitionThreshold)
00122 {
00123         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(lightTransitionThreshold, 0.f, 1.f);
00124         <a class="code" href="classNL3D_1_1CLightingManager.html#z526_3">_LightTransitionThreshold</a>= lightTransitionThreshold;
00125 }
00126 
00127 
00128         
00129 <font class="comment">// ***************************************************************************</font>
<a name="l00130"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z524_0">00130</a> <font class="keywordtype">void</font>            CLightingManager::clearDynamicLights()
00131 {
00132         <font class="comment">// for all levels</font>
00133         <font class="keywordflow">for</font>(uint i=0;i&lt;<a class="code" href="lighting__manager_8h.html#a0">NL3D_QUADGRID_LIGHT_NUM_LEVEL</a>;i++)
00134         {
00135                 <font class="comment">// clear all the lights in the quadGrid.</font>
00136                 <a class="code" href="classNL3D_1_1CLightingManager.html#o1">_LightQuadGrid</a>[i].clear();
00137         }
00138 
00139         <font class="comment">// clear the list.</font>
00140         <a class="code" href="classNL3D_1_1CLightingManager.html#o3">_DynamicLightList</a>.clear();
00141 }
00142 
00143 <font class="comment">// ***************************************************************************</font>
<a name="l00144"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z524_1">00144</a> <font class="keywordtype">void</font>            CLightingManager::addDynamicLight(CPointLight *light)
00145 {
00146 
00147         <font class="comment">// Insert the light in the quadGrid.</font>
00148         <font class="comment">//----------</font>
00149         CPointLightInfo         plInfo;
00150         plInfo.Light= light;
00151 
00152         <font class="comment">// build the bounding sphere for this light, with the AttenuationEnd of the light</font>
00153         <font class="keywordtype">float</font>   radius=light-&gt;getAttenuationEnd();
00154         <font class="comment">// if attenuation is disabled (ie getAttenuationEnd() return 0), then have a dummy radius</font>
00155         <font class="keywordflow">if</font>(radius==0)
00156                 radius= <a class="code" href="classNL3D_1_1CLightingManager.html#z526_1">_NoAttLightRadius</a>;
00157         plInfo.Sphere.Center= light-&gt;getPosition();
00158         plInfo.Sphere.Radius= radius;
00159 
00160         <font class="comment">// build a bbox, so it includes the sphere</font>
00161         CVector bbmin= light-&gt;getPosition();
00162         bbmin-= CVector(radius, radius, radius);
00163         CVector bbmax= light-&gt;getPosition();
00164         bbmax+= CVector(radius, radius, radius);
00165 
00166         <font class="comment">// choose the correct quadgrid according to the radius of the light.</font>
00167         uint qgId;
00168         <font class="keywordflow">for</font>(qgId= 0; qgId&lt;<a class="code" href="lighting__manager_8h.html#a0">NL3D_QUADGRID_LIGHT_NUM_LEVEL</a>-1; qgId++)
00169         {
00170                 <font class="comment">// if radius is inferior to the requested radius for this quadGrid, ok!</font>
00171                 <font class="keywordflow">if</font>(radius&lt;<a class="code" href="classNL3D_1_1CLightingManager.html#o2">_LightQuadGridRadiusLimit</a>[qgId])
00172                         <font class="keywordflow">break</font>;
00173         }
00174         <font class="comment">// insert this light in the correct quadgrid.</font>
00175         <a class="code" href="classNL3D_1_1CLightingManager.html#o1">_LightQuadGrid</a>[qgId].insert(bbmin, bbmax, plInfo);
00176 
00177 
00178         <font class="comment">// touch the objects around the lights.</font>
00179         <font class="comment">//----------</font>
00180 
00181         <font class="comment">// Select the static lightedModels to update around this light.</font>
00182         <font class="comment">// Use the same level of _StaticLightedModelQuadGrid than me to not select too many squares in the quadGrid</font>
00183         <a class="code" href="classNL3D_1_1CLightingManager.html#o0">_StaticLightedModelQuadGrid</a>[qgId].select(bbmin, bbmax);
00184         <font class="comment">// For all those models.</font>
00185         CQuadGrid&lt;CTransform*&gt;::CIterator       itModel= <a class="code" href="classNL3D_1_1CLightingManager.html#o0">_StaticLightedModelQuadGrid</a>[qgId].begin();
00186         <font class="keywordflow">while</font>(itModel != <a class="code" href="classNL3D_1_1CLightingManager.html#o0">_StaticLightedModelQuadGrid</a>[qgId].end() )
00187         {
00188                 CTransform      *model= *itModel;
00189                 <font class="keyword">const</font> CVector &amp;modelPos= model-&gt;getWorldMatrix().getPos();
00190 
00191                 <font class="comment">// test first if this model is in the area of the light.</font>
00192                 <font class="keywordflow">if</font>( plInfo.Sphere.include(modelPos) )
00193                 {
00194                         <font class="comment">// yes, then this model must recompute his lighting, because a dynamic light touch him.</font>
00195                         model-&gt;resetLighting();
00196                 }
00197 
00198                 <font class="comment">// next.</font>
00199                 itModel++;
00200         }
00201 
00202 
00203         <font class="comment">// insert the light in the list.</font>
00204         <font class="comment">//----------</font>
00205         <a class="code" href="classNL3D_1_1CLightingManager.html#o3">_DynamicLightList</a>.push_back(light);
00206 
00207 }
00208 
00209 <font class="comment">// ***************************************************************************</font>
<a name="l00210"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z525_0">00210</a> CLightingManager::CQGItLightedModel     CLightingManager::eraseStaticLightedModel(CQGItLightedModel ite)
00211 {
00212         <font class="comment">// Erase the iterator for all levels</font>
00213         <font class="keywordflow">for</font>(uint i=0;i&lt;<a class="code" href="lighting__manager_8h.html#a0">NL3D_QUADGRID_LIGHT_NUM_LEVEL</a>;i++)
00214         {
00215                 <font class="comment">// NB: it is possible here that the iterator is NULL (ie end()).</font>
00216                 <a class="code" href="classNL3D_1_1CLightingManager.html#o0">_StaticLightedModelQuadGrid</a>[i].erase(ite.QgItes[i]);
00217         }
00218 
00219         <font class="comment">// return end(), ie NULL iterators</font>
00220         <font class="keywordflow">return</font> CQGItLightedModel();
00221 }
00222 
00223 <font class="comment">// ***************************************************************************</font>
<a name="l00224"></a><a class="code" href="classNL3D_1_1CLightingManager.html#z525_1">00224</a> CLightingManager::CQGItLightedModel     CLightingManager::insertStaticLightedModel(CTransform *model)
00225 {
00226         CQGItLightedModel       ite;
00227         <font class="keyword">const</font> CVector &amp;worldPos= model-&gt;getWorldMatrix().getPos();
00228 
00229         <font class="comment">// Insert the models in all levels, because addDynamicLight() may choose the best suited level to select</font>
00230         <font class="keywordflow">for</font>(uint i=0;i&lt;<a class="code" href="lighting__manager_8h.html#a0">NL3D_QUADGRID_LIGHT_NUM_LEVEL</a>;i++)
00231         {
00232                 ite.QgItes[i]= <a class="code" href="classNL3D_1_1CLightingManager.html#o0">_StaticLightedModelQuadGrid</a>[i].insert(worldPos, worldPos, model);
00233         }
00234 
00235         <font class="comment">// return the iterator</font>
00236         <font class="keywordflow">return</font> ite;
00237 }
00238 
00239 
00240 <font class="comment">// ***************************************************************************</font>
<a name="l00241"></a><a class="code" href="structNL3D_1_1CSortLight.html">00241</a> <font class="keyword">struct  </font>CSortLight
00242 {
<a name="l00243"></a><a class="code" href="structNL3D_1_1CSortLight.html#m0">00243</a>         CPointLight             *<a class="code" href="structNL3D_1_1CSortLight.html#m0">PointLight</a>;
<a name="l00244"></a><a class="code" href="structNL3D_1_1CSortLight.html#m1">00244</a>         <font class="keywordtype">float</font>                   <a class="code" href="structNL3D_1_1CSortLight.html#m1">Influence</a>;
00245 
00246 };
00247 
00248 <font class="comment">// ***************************************************************************</font>
<a name="l00249"></a><a class="code" href="classNL3D_1_1CLightingManager.html#a1">00249</a> <font class="keywordtype">void</font>            CLightingManager::computeModelLightContributions(CTransform *model, CLightContribution &amp;lightContrib, 
00250         ILogicInfo *logicInfo)
00251 {
00252         sint    i;
00253 
00254         <font class="comment">// This is the list of light which touch this model.</font>
00255         <font class="keyword">static</font> std::vector&lt;CPointLightInfluence&gt;        lightList;
00256         <font class="comment">// static, for malloc perf.</font>
00257         lightList.clear();
00258 
00259         <font class="comment">// the position of the model.</font>
00260         CVector modelPos;
00261         <font class="keywordtype">float</font>   modelRadius;
00262 
00263         <font class="comment">// get the untransformed bbox from the model.</font>
00264         CAABBox         bbox;
00265         model-&gt;getAABBox(bbox);
00266         <font class="comment">// get transformed center pos of bbox</font>
00267         modelPos= model-&gt;getWorldMatrix() * bbox.getCenter();
00268         <font class="comment">// If the model is a big lightable, must take radius from aabbox, else suppose 0 radius.</font>
00269         <font class="keywordflow">if</font>(model-&gt;isBigLightable())
00270         {
00271                 <font class="comment">// get size of the bbox (bounding sphere)</font>
00272                 modelRadius= bbox.getRadius();
00273         }
00274         <font class="keywordflow">else</font>
00275         {
00276                 <font class="comment">// Assume 0 radius =&gt; faster computeLinearAttenuation()</font>
00277                 modelRadius= 0;
00278         }
00279 
00280 
00281         <font class="comment">// First pass, fill the list of light which touch this model.</font>
00282         <font class="comment">//=========</font>
00283         <font class="comment">// get the dynamic lights around the model</font>
00284         <a class="code" href="classNL3D_1_1CLightingManager.html#c0">getDynamicPointLightList</a>(modelPos, lightList);
00285 
00286         <font class="comment">// if not already precomputed, append staticLights to this list.</font>
00287         <font class="keywordflow">if</font>( !lightContrib.FrozenStaticLightSetup )
00288         {
00289                 <font class="comment">// If no logicInfo provided</font>
00290                 <font class="keywordflow">if</font>(!logicInfo)
00291                 {
00292                         <font class="comment">// Default: suppose full SunLight and no PointLights.</font>
00293                         lightContrib.SunContribution= 255;
00294                         <font class="comment">// Take full SunAmbient.</font>
00295                         lightContrib.LocalAmbient.set(0,0,0,0);
00296                         <font class="comment">// do not append any pointLight to the setup</font>
00297                 }
00298                 <font class="keywordflow">else</font>
00299                 {
00300                         <font class="comment">// NB: SunContribution is computed by logicInfo</font>
00301                         logicInfo-&gt;getStaticLightSetup(lightList, lightContrib.SunContribution, lightContrib.LocalAmbient);
00302                 }
00303         }
00304 
00305         <font class="comment">// Second pass, in the lightList, choose the best suited light to lit this model</font>
00306         <font class="comment">//=========</font>
00307 
00308         <font class="comment">// for each light, modulate the factor of influence</font>
00309         <font class="keywordflow">for</font>(i=0; i&lt;(sint)lightList.size();i++)
00310         {
00311                 CPointLight     *pl= lightList[i].PointLight;
00312 
00313                 <font class="comment">// get the distance from the light to the model</font>
00314                 <font class="keywordtype">float</font>   dist= (pl-&gt;getPosition() - modelPos).norm();
00315                 <font class="keywordtype">float</font>   distMinusRadius= dist - modelRadius;
00316 
00317                 <font class="comment">// modulate the factor by the distance and the attenuation distance.</font>
00318                 <font class="keywordtype">float</font>    inf;
00319                 <font class="keywordtype">float</font>   attBegin= pl-&gt;getAttenuationBegin();
00320                 <font class="keywordtype">float</font>   attEnd= pl-&gt;getAttenuationEnd();
00321                 <font class="comment">// if no attenuation</font>
00322                 <font class="keywordflow">if</font>( attEnd==0 )
00323                 {
00324                         <font class="comment">// influence is awlays 1.</font>
00325                         inf= 1;
00326 
00327                         <font class="comment">// If SpotLight, must modulate with SpotAttenuation.</font>
00328                         <font class="keywordflow">if</font>(pl-&gt;getType() == CPointLight::SpotLight)
00329                                 inf*= pl-&gt;computeLinearAttenuation(modelPos, dist, modelRadius);
00330                 }
00331                 <font class="keywordflow">else</font>
00332                 {
00333                         <font class="comment">// if correct attenuation radius</font>
00334                         <font class="keywordflow">if</font>(distMinusRadius&lt;attBegin)
00335                         {
00336                                 <font class="comment">// NB: we are sure that attBegin&gt;0, because dist&gt;=0.</font>
00337                                 <font class="comment">// if &lt; attBegin, inf should be ==1, but must select the nearest lights; for better</font>
00338                                 <font class="comment">// understanding of the scene</font>
00339                                 inf= 1 + <a class="code" href="classNL3D_1_1CLightingManager.html#z526_2">_OutOfAttLightInfFactor</a> * (attBegin - distMinusRadius);        <font class="comment">// inf E [1, +oo[</font>
00340                                 <font class="comment">// NB: this formula favour big lights (ie light with big attBegin).</font>
00341 
00342                                 <font class="comment">// If SpotLight, must modulate with SpotAttenuation.</font>
00343                                 <font class="keywordflow">if</font>(pl-&gt;getType() == CPointLight::SpotLight)
00344                                         inf*= pl-&gt;computeLinearAttenuation(modelPos, dist, modelRadius);
00345                         }
00346                         <font class="keywordflow">else</font> <font class="keywordflow">if</font>(distMinusRadius&lt;attEnd)
00347                         {
00348                                 <font class="comment">// we are sure attEnd-attBegin&gt;0 because of the test</font>
00349                                 <font class="comment">// compute influence of the light: attenuation and SpotAttenuation</font>
00350                                 inf= pl-&gt;computeLinearAttenuation(modelPos, dist, modelRadius);
00351                         }
00352                         <font class="keywordflow">else</font>
00353                         {
00354                                 <font class="comment">// if &gt;= attEnd, inf should be ==0, but must select the nearest lights; for better</font>
00355                                 <font class="comment">// understanding of the scene</font>
00356                                 inf= <a class="code" href="classNL3D_1_1CLightingManager.html#z526_2">_OutOfAttLightInfFactor</a> * (attEnd - distMinusRadius);              <font class="comment">// inf E ]-oo, 0]</font>
00357                         }
00358                 }
00359 
00360                 <font class="comment">// modulate the influence with this factor</font>
00361                 lightList[i].BkupInfluence= lightList[i].Influence;
00362                 lightList[i].Influence*= inf;
00363 
00364                 <font class="comment">// Bkup distance to model.</font>
00365                 lightList[i].DistanceToModel= dist;
00366         }
00367 
00368         <font class="comment">// sort the light by influence</font>
00369         sort(lightList.begin(), lightList.end());
00370 
00371 
00372         <font class="comment">// and choose only max light.</font>
00373         uint    startId= 0;
00374         uint    ligthSrcId= 0;
00375         <font class="comment">// skip already setuped light (statically)</font>
00376         <font class="keywordflow">if</font>(lightContrib.FrozenStaticLightSetup)
00377                 startId= lightContrib.NumFrozenStaticLight;
00378 
00379         <font class="comment">// If there is still place for Dynamic lights.</font>
00380         <font class="keywordflow">if</font>(startId &lt; <a class="code" href="classNL3D_1_1CLightingManager.html#z526_0">_MaxLightContribution</a>)
00381         {
00382                 <font class="comment">// setup the transition.</font>
00383                 <font class="keywordtype">float</font>   deltaMinInfluence= <a class="code" href="classNL3D_1_1CLightingManager.html#z526_3">_LightTransitionThreshold</a>;
00384                 <font class="keywordtype">float</font>   minInfluence= 0;
00385                 <font class="comment">// If there is more light that we can accept, </font>
00386                 <font class="keywordflow">if</font>(lightList.size() &gt; <a class="code" href="classNL3D_1_1CLightingManager.html#z526_0">_MaxLightContribution</a>-startId)
00387                 {
00388                         <font class="comment">// the minInfluence is the influence of the first light not taken.</font>
00389                         minInfluence= lightList[<a class="code" href="classNL3D_1_1CLightingManager.html#z526_0">_MaxLightContribution</a>-startId].Influence;
00390                         <font class="comment">// but must still be &gt;=0.</font>
00391                         minInfluence= max(minInfluence, 0.f);
00392                 }
00393                 <font class="comment">// Any light under this minInfluence+deltaMinInfluence will be smoothly darken.</font>
00394                 <font class="keywordtype">float</font>   minInfluenceStart = minInfluence + deltaMinInfluence;
00395                 <font class="keywordtype">float</font>   OOdeltaMinInfluencex255= 255.f / deltaMinInfluence;
00396 
00397                 <font class="comment">// fill maxLight at max.</font>
00398                 <font class="keywordflow">for</font>(i=startId;i&lt;(sint)<a class="code" href="classNL3D_1_1CLightingManager.html#z526_0">_MaxLightContribution</a>; i++)
00399                 {
00400                         <font class="comment">// if not so many pointLights found, end!!</font>
00401                         <font class="keywordflow">if</font>(ligthSrcId&gt;=lightList.size())
00402                                 <font class="keywordflow">break</font>;
00403                         <font class="keywordflow">else</font>
00404                         {
00405                                 CPointLight     *pl= lightList[ligthSrcId].PointLight;
00406                                 <font class="keywordtype">float</font>           inf= lightList[ligthSrcId].Influence;
00407                                 <font class="keywordtype">float</font>           bkupInf= lightList[ligthSrcId].BkupInfluence;
00408                                 <font class="keywordtype">float</font>           distToModel= lightList[ligthSrcId].DistanceToModel;
00409                                 <font class="comment">// else fill it.</font>
00410                                 lightContrib.PointLight[i]= pl;
00411 
00412                                 <font class="comment">// Compute the Final factor of influence of the light.</font>
00413                                 <font class="keywordflow">if</font>(inf &gt;= minInfluenceStart)
00414                                 {
00415                                         <font class="comment">// For Static LightSetup BiLinear to work correctly, modulate with BkupInfluence</font>
00416                                         <font class="comment">// don't worry about the precision of floor, because of *255.</font>
00417                                         lightContrib.Factor[i]= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(bkupInf*255);
00418                                 }
00419                                 <font class="keywordflow">else</font>
00420                                 {
00421                                         <font class="keywordtype">float</font>   f= (inf-minInfluence) * OOdeltaMinInfluencex255;
00422                                         sint    fi;
00423                                         <font class="comment">// For Static LightSetup BiLinear to work correctly, modulate with BkupInfluence</font>
00424                                         <font class="comment">// don't worry about the precision of floor, because of *255.</font>
00425                                         fi= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>( bkupInf*f );
00426                                         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(fi, 0, 255);
00427                                         lightContrib.Factor[i]= fi;
00428                                 }
00429 
00430                                 <font class="comment">// Compute the Final Att factor for models using Global Attenuation. NB: modulate with Factor</font>
00431                                 <font class="comment">// don't worry about the precision of floor, because of *255.</font>
00432                                 <font class="comment">// NB: compute att on the center of the model =&gt; modelRadius==0</font>
00433                                 sint    attFactor= <a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>( lightContrib.Factor[i] * pl-&gt;computeLinearAttenuation(modelPos, distToModel) );
00434                                 lightContrib.AttFactor[i]= (uint8)attFactor;
00435 
00436                                 <font class="comment">// must append this lightedModel to the list in the light.</font>
00437                                 lightContrib.TransformIterator[i]= pl-&gt;appendLightedModel(model);
00438 
00439                                 <font class="comment">// next light.</font>
00440                                 ligthSrcId++;
00441                         }
00442                 }
00443         }
00444         <font class="keywordflow">else</font>
00445         {
00446                 <font class="comment">// point to end the list</font>
00447                 i= startId;
00448         }
00449 
00450         <font class="comment">// End the list.</font>
00451         <font class="keywordflow">if</font>(i&lt;<a class="code" href="light__contribution_8h.html#a0">NL3D_MAX_LIGHT_CONTRIBUTION</a>)
00452         {
00453                 lightContrib.PointLight[i]= NULL;
00454         }
00455 
00456 }
00457 
00458 
00459 <font class="comment">// ***************************************************************************</font>
<a name="l00460"></a><a class="code" href="classNL3D_1_1CLightingManager.html#c0">00460</a> <font class="keywordtype">void</font>            CLightingManager::getDynamicPointLightList(<font class="keyword">const</font> CVector &amp;worldPos, std::vector&lt;CPointLightInfluence&gt;   &amp;lightList)
00461 {
00462         <font class="comment">// For all quadGrids.</font>
00463         <font class="keywordflow">for</font>(uint qgId=0; qgId&lt;<a class="code" href="lighting__manager_8h.html#a0">NL3D_QUADGRID_LIGHT_NUM_LEVEL</a>; qgId++)
00464         {
00465                 CQuadGrid&lt;CPointLightInfo&gt;      &amp;quadGrid= <a class="code" href="classNL3D_1_1CLightingManager.html#o1">_LightQuadGrid</a>[qgId];
00466 
00467                 <font class="comment">// select the lights around this position in the quadGrids.</font>
00468                 quadGrid.select(worldPos, worldPos);
00469 
00470                 <font class="comment">// for all possible found lights</font>
00471                 CQuadGrid&lt;CPointLightInfo&gt;::CIterator   itLight;
00472                 <font class="keywordflow">for</font>(itLight= quadGrid.begin(); itLight!=quadGrid.end(); itLight++)
00473                 {
00474                         <font class="comment">// verify it includes the entity</font>
00475                         <font class="keywordflow">if</font>( (*itLight).Sphere.include(worldPos) )
00476                         {
00477                                 <font class="comment">// ok, insert in list.</font>
00478                                 CPointLightInfluence    pli;
00479                                 pli.PointLight= (*itLight).Light;
00480                                 <font class="comment">// No special Influence degradation scheme for Dynamic lighting</font>
00481                                 pli.Influence= 1;
00482                                 lightList.push_back( pli );
00483                         }
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>