aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/lod__character__shape_8cpp-source.html
blob: bb8494aa84d1dbe3691d39fc3f93523f5126d4ab (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
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF='/'><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF='/'><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

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

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

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>lod_character_shape.cpp</h1><a href="lod__character__shape_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="lod__character__shape_8h.html">3d/lod_character_shape.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="vectord_8h.html">nel/misc/vectord.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="fast__floor_8h.html">3d/fast_floor.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="lod__character__texture_8h.html">3d/lod_character_texture.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="triangle_8h.html">nel/misc/triangle.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="polygon_8h.html">nel/misc/polygon.h</a>"</font>
00034 
00035 
00036 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00037 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00038 
00039 
00040 <font class="keyword">namespace </font>NL3D 
00041 {
00042 
00043 
00044 <font class="comment">// ***************************************************************************</font>
00045 <font class="comment">// ***************************************************************************</font>
00046 <font class="comment">// CLodCharacterShape</font>
00047 <font class="comment">// ***************************************************************************</font>
00048 <font class="comment">// ***************************************************************************</font>
00049 
00050 
00051 <font class="comment">// ***************************************************************************</font>
00052 <font class="keyword">const</font> CLodCharacterShapeBuild::CPixelInfo               CLodCharacterShapeBuild::CPixelInfo::EmptyPixel(
00053                 CVector::Null, CVector(1000,0,0));
00054 
00055 
00056 <font class="comment">// ***************************************************************************</font>
<a name="l00057"></a><a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#a0">00057</a> CLodCharacterShapeBuild::CLodCharacterShapeBuild()
00058 {
00059         <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>= 0;
00060         <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>= 0;
00061 }
00062 
00063 
00064 <font class="comment">// ***************************************************************************</font>
<a name="l00065"></a><a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#a1">00065</a> <font class="keywordtype">void</font>    CLodCharacterShapeBuild::compile(<font class="keyword">const</font> std::vector&lt;bool&gt; &amp;triangleSelection, uint textureOverSample)
00066 {
00067         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>.size()==<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m0">Vertices</a>.size());
00068         <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m3">Normals</a>.size()==<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m0">Vertices</a>.size());
00069 
00070         <font class="comment">// take the sqrtf.</font>
00071         textureOverSample= (uint)sqrtf((<font class="keywordtype">float</font>)textureOverSample);
00072         textureOverSample= max(textureOverSample, 1U);
00073 
00074         <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>= <a class="code" href="lod__character__texture_8h.html#a0">NL3D_CLOD_TEXT_WIDTH</a>;
00075         <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>= <a class="code" href="lod__character__texture_8h.html#a1">NL3D_CLOD_TEXT_HEIGHT</a>;
00076 
00077         uint    wOver= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>*textureOverSample;
00078         uint    hOver= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>*textureOverSample;
00079         std::vector&lt;CPixelInfo&gt;         overTextureInfo;
00080 
00081         <font class="comment">// do some tri selection?</font>
00082         <font class="keywordtype">bool</font>    triSelectOk= triangleSelection.size()==<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m5">TriangleIndices</a>.size()/3;
00083 
00084 
00085         <font class="comment">// **** reset the texture and init with "empty" pixel (ie normal.x==1000, which is not possible because normal.norm()==1)</font>
00086         <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>.resize(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>*<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>);
00087         fill(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>.begin(), <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>.end(), CPixelInfo::EmptyPixel);
00088         <font class="comment">// do it to the oversampled texture</font>
00089         overTextureInfo.resize(wOver*hOver, CPixelInfo::EmptyPixel);
00090 
00091 
00092         <font class="comment">// **** For each triangle in the shape, polyfill this triangle from a texture view, in the overSampledTexture</font>
00093         CPolygon2D      poly;
00094         poly.Vertices.resize(3);
00095         <font class="keywordflow">for</font>(uint i=0; i&lt;<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m5">TriangleIndices</a>.size();i+=3)
00096         {
00097                 <font class="comment">// if selection OK, and the tri is not selected, skip</font>
00098                 <font class="keywordflow">if</font>(triSelectOk &amp;&amp; !triangleSelection[i/3])
00099                         <font class="keywordflow">continue</font>;
00100 
00101                 <font class="comment">// Setup triangle.</font>
00102                 <font class="comment">// -----------</font>
00103                 uint    idx[3];
00104                 idx[0]= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m5">TriangleIndices</a>[i+0];
00105                 idx[1]= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m5">TriangleIndices</a>[i+1];
00106                 idx[2]= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m5">TriangleIndices</a>[i+2];
00107                 <font class="comment">// compute corners UVs, in texel size</font>
00108                 CTriangle               triangleUV;
00109                 triangleUV.V0= CVector(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>[idx[0]].U*wOver, <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>[idx[0]].V*hOver, 0);
00110                 triangleUV.V1= CVector(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>[idx[1]].U*wOver, <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>[idx[1]].V*hOver, 0);
00111                 triangleUV.V2= CVector(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>[idx[2]].U*wOver, <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>[idx[2]].V*hOver, 0);
00112                 <font class="comment">// compute corners pixelInfos </font>
00113                 CPixelInfo              pInf[3];
00114                 <font class="keywordflow">for</font>(uint corner=0; corner&lt;3; corner++)
00115                 {
00116                         pInf[corner].Pos= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m0">Vertices</a>[idx[corner]];
00117                         pInf[corner].Normal= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m3">Normals</a>[idx[corner]];
00118                 }
00119                 <font class="comment">// Compute Gradients</font>
00120                 CVector         GradPosX, GradPosY, GradPosZ;
00121                 CVector         GradNormalX, GradNormalY, GradNormalZ;
00122                 triangleUV.computeGradient(pInf[0].Pos.x, pInf[1].Pos.x, pInf[2].Pos.x, GradPosX);
00123                 triangleUV.computeGradient(pInf[0].Pos.y, pInf[1].Pos.y, pInf[2].Pos.y, GradPosY);
00124                 triangleUV.computeGradient(pInf[0].Pos.z, pInf[1].Pos.z, pInf[2].Pos.z, GradPosZ);
00125                 triangleUV.computeGradient(pInf[0].Normal.x, pInf[1].Normal.x, pInf[2].Normal.x, GradNormalX);
00126                 triangleUV.computeGradient(pInf[0].Normal.y, pInf[1].Normal.y, pInf[2].Normal.y, GradNormalY);
00127                 triangleUV.computeGradient(pInf[0].Normal.z, pInf[1].Normal.z, pInf[2].Normal.z, GradNormalZ);
00128                 <font class="comment">// Compute Gradients offset</font>
00129                 <font class="keywordtype">float</font>           OffPosX, OffPosY, OffPosZ;
00130                 <font class="keywordtype">float</font>           OffNormalX, OffNormalY, OffNormalZ;
00131                 OffPosX= pInf[0].Pos.x - GradPosX*triangleUV.V0;
00132                 OffPosY= pInf[0].Pos.y - GradPosY*triangleUV.V0;
00133                 OffPosZ= pInf[0].Pos.z - GradPosZ*triangleUV.V0;
00134                 OffNormalX= pInf[0].Normal.x - GradNormalX*triangleUV.V0;
00135                 OffNormalY= pInf[0].Normal.y - GradNormalY*triangleUV.V0;
00136                 OffNormalZ= pInf[0].Normal.z - GradNormalZ*triangleUV.V0;
00137 
00138 
00139                 <font class="comment">// PolyFiller</font>
00140                 <font class="comment">// -----------</font>
00141                 CVector2f       dCenter(0.5f, 0.5f);
00142                 <font class="comment">// select texels if their centers is in the triangle</font>
00143                 poly.Vertices[0]= triangleUV.V0-dCenter;
00144                 poly.Vertices[1]= triangleUV.V1-dCenter;
00145                 poly.Vertices[2]= triangleUV.V2-dCenter;
00146                 <font class="comment">// polyFiller</font>
00147                 CPolygon2D::TRasterVect rasters;
00148                 sint    minY;
00149                 poly.computeBorders(rasters, minY);
00150                 <font class="keywordflow">for</font>(sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;(sint)rasters.size();<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
00151                 {
00152                         sint x0= rasters[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>].first;
00153                         sint x1= rasters[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>].second;
00154                         CVector <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00155                         <font class="comment">// get the center coord of this texel</font>
00156                         <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+minY+0.5f;
00157                         <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z= 0;
00158                         <font class="keywordflow">for</font>(sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=x0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;=x1;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
00159                         {
00160                                 <font class="comment">// get the center coord of this texel</font>
00161                                 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x= <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+0.5f;
00162                                 <font class="comment">// Compute Pos/Normal on this texel.</font>
00163                                 CPixelInfo      texelInf;
00164                                 texelInf.Pos.x= OffPosX + GradPosX * <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00165                                 texelInf.Pos.y= OffPosY + GradPosY * <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00166                                 texelInf.Pos.z= OffPosZ + GradPosZ * <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00167                                 texelInf.Normal.x= OffNormalX + GradNormalX * <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00168                                 texelInf.Normal.y= OffNormalY + GradNormalY * <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00169                                 texelInf.Normal.z= OffNormalZ + GradNormalZ * <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00170                                 <font class="comment">// normalize.</font>
00171                                 texelInf.Normal.normalize();
00172                                 <font class="comment">// Store (NB: overwrite any pixel)</font>
00173                                 sint    texX= ((uint)<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)%wOver;
00174                                 sint    texY= ((uint)<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+minY)%hOver;
00175                                 overTextureInfo[texY*wOver+texX]= texelInf;
00176                         }
00177                 }
00178 
00179         }
00180 
00181 
00182         <font class="comment">// **** Down sample the overSampled texture.</font>
00183         sint    <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
00184         <font class="keywordflow">if</font>(textureOverSample==1)
00185         {
00186                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>= overTextureInfo;
00187         }
00188         <font class="keywordflow">else</font>
00189         {
00190                 <font class="comment">// eg: 3 gives 1. delta ranges from -1 to 1.</font>
00191                 <font class="keywordtype">float</font>   middle= (textureOverSample-1)/2.f;
00192 
00193                 <font class="comment">// for all pixels.</font>
00194                 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;(sint)<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
00195                 {
00196                         <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;(sint)<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
00197                         {
00198                                 <font class="comment">// for all samples, take the best one.</font>
00199                                 sint            xo, yo;
00200                                 <font class="keywordtype">float</font>           bestDist= FLT_MAX;
00201                                 CPixelInfo      bestPixel= CPixelInfo::EmptyPixel;
00202                                 <font class="keywordflow">for</font>(yo=0;yo&lt;(sint)textureOverSample;yo++)
00203                                 {
00204                                         <font class="keywordflow">for</font>(xo=0;xo&lt;(sint)textureOverSample;xo++)
00205                                         {
00206                                                 <font class="comment">// compute distance to the pixel center.</font>
00207                                                 <font class="keywordtype">float</font>   dist= <a class="code" href="namespaceNLMISC.html#a214">sqr</a>(yo-middle)+<a class="code" href="namespaceNLMISC.html#a214">sqr</a>(xo-middle);
00208                                                 <font class="keyword">const</font> CPixelInfo        &amp;overPixel= overTextureInfo[(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*textureOverSample+yo)*wOver+(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*textureOverSample+xo)];
00209                                                 <font class="comment">// if the overPixel is not empty.</font>
00210                                                 <font class="keywordflow">if</font>( !(overPixel==CPixelInfo::EmptyPixel) )
00211                                                 {
00212                                                         <font class="comment">// take it if the best: nearest to the pixel center.</font>
00213                                                         <font class="keywordflow">if</font>(dist&lt;bestDist)
00214                                                         {
00215                                                                 bestDist= dist;
00216                                                                 bestPixel= overPixel;
00217                                                         }
00218                                                 }
00219                                         }
00220                                 }
00221 
00222                                 <font class="comment">// fill textureInfo</font>
00223                                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= bestPixel;
00224                         }
00225                 }
00226         }
00227 
00228 
00229         <font class="comment">// **** Dilate texture 1 time: each empty pixel info get neighbor full pixel (8box)</font>
00230         <font class="comment">// copy the non dilated texture</font>
00231         std::vector&lt;CPixelInfo&gt;         tmpTextureInfo= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>;
00232         <font class="comment">// process all pixels</font>
00233         <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;(sint)<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
00234         {
00235                 sint    y0=<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>-1, y1=<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>+1;
00236                 y0= max(y0, 0);
00237                 y1= <a class="code" href="bit__set_8cpp.html#a0">min</a>(y1, (sint)<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>-1);
00238                 <font class="keywordflow">for</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=0;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;(sint)<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>;<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
00239                 {
00240                         CPixelInfo      &amp;texelInf= <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>+<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>];
00241                         <font class="comment">// if an empty pixel.</font>
00242                         <font class="keywordflow">if</font>(texelInf==CPixelInfo::EmptyPixel)
00243                         {
00244                                 <font class="comment">// dilate: look around for non empty pixel.</font>
00245                                 sint    x0=<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>-1, x1=<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>+1;
00246                                 x0= max(x0, 0);
00247                                 x1= <a class="code" href="bit__set_8cpp.html#a0">min</a>(x1, (sint)<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>-1);
00248                                 <font class="comment">// For the 8 possible pixels (nb: look us too, but doesn't matter since we are an empty pixel)</font>
00249                                 <font class="keywordflow">for</font>(sint yb= y0; yb&lt;=y1;yb++)
00250                                 {
00251                                         <font class="keywordflow">for</font>(sint xb= x0; xb&lt;=x1;xb++)
00252                                         {
00253                                                 <font class="comment">// if the neighbor is not an empty pixel. NB: avoid override problems using not Dilated texture</font>
00254                                                 CPixelInfo      &amp;nbTexelInf= tmpTextureInfo[yb*<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>+xb];
00255                                                 <font class="keywordflow">if</font>( !(nbTexelInf==CPixelInfo::EmptyPixel) )
00256                                                 {
00257                                                         <font class="comment">// write it in the center pixel, and skip the search</font>
00258                                                         texelInf= nbTexelInf;
00259                                                         yb= y1+1;
00260                                                         <font class="keywordflow">break</font>;
00261                                                 }
00262                                         }
00263                                 }
00264                         }
00265                 }
00266         }
00267 
00268 }
00269 
00270 
00271 <font class="comment">// ***************************************************************************</font>
<a name="l00272"></a><a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#a2">00272</a> <font class="keywordtype">void</font>    CLodCharacterShapeBuild::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f)
00273 {
00274         <font class="comment">// NEL_CLODBULD</font>
00275         f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'_LEN');
00276         f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'DOLC');
00277         f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'DLUB');
00278 
00279         <font class="comment">/*</font>
00280 <font class="comment">        Version 1:</font>
00281 <font class="comment">                - UVs and Normals + texture info</font>
00282 <font class="comment">        */</font>
00283         sint    ver= f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(1);
00284 
00285         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m0">Vertices</a>);
00286         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m1">SkinWeights</a>);
00287         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m4">BonesNames</a>);
00288         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m5">TriangleIndices</a>);
00289 
00290         <font class="keywordflow">if</font>(ver&gt;=1)
00291         {
00292                 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>);
00293                 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m3">Normals</a>);
00294                 f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>, <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>);
00295                 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>);
00296         }
00297         <font class="keywordflow">else</font>
00298         {
00299                 <font class="comment">// Must init dummy UVs/normals</font>
00300                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m2">UVs</a>.resize(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m0">Vertices</a>.size(), CUV(0,0));
00301                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m3">Normals</a>.resize(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#m0">Vertices</a>.size(), CVector::K);
00302                 <font class="comment">// Must init dummy texture</font>
00303                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>= <a class="code" href="lod__character__texture_8h.html#a0">NL3D_CLOD_TEXT_WIDTH</a>;
00304                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>= <a class="code" href="lod__character__texture_8h.html#a1">NL3D_CLOD_TEXT_HEIGHT</a>;
00305                 <a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>.resize(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o1">_Width</a>*<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o2">_Height</a>, CPixelInfo::EmptyPixel);
00306         }
00307 
00308 }
00309 
00310 
00311 <font class="comment">// ***************************************************************************</font>
<a name="l00312"></a><a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#a3">00312</a> <font class="keyword">const</font> CLodCharacterShapeBuild::CPixelInfo       *CLodCharacterShapeBuild::getTextureInfoPtr()
00313 {
00314         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>.empty())
00315                 <font class="keywordflow">return</font> NULL;
00316         <font class="keywordflow">else</font>
00317                 <font class="keywordflow">return</font> &amp;<a class="code" href="classNL3D_1_1CLodCharacterShapeBuild.html#o0">_TextureInfo</a>[0];
00318 }
00319 
00320 
00321 <font class="comment">// ***************************************************************************</font>
00322 <font class="comment">// ***************************************************************************</font>
00323 <font class="comment">// CLodCharacterShape</font>
00324 <font class="comment">// ***************************************************************************</font>
00325 <font class="comment">// ***************************************************************************</font>
00326 
00327 
00328 <font class="comment">// ***************************************************************************</font>
<a name="l00329"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a0">00329</a> CLodCharacterShape::CLodCharacterShape()
00330 {
00331         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>= 0;
00332         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o2">_NumTriangles</a>= 0;
00333 }
00334 
00335 <font class="comment">// ***************************************************************************</font>
<a name="l00336"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a1">00336</a> <font class="keywordtype">void</font>                    CLodCharacterShape::buildMesh(<font class="keyword">const</font> std::string &amp;name, <font class="keyword">const</font> CLodCharacterShapeBuild &amp;lodBuild)
00337 {
00338         uint    numVertices= lodBuild.Vertices.size();
00339         <font class="keyword">const</font> vector&lt;uint32&gt;                            &amp;triangleIndices= lodBuild.TriangleIndices;
00340         <font class="keyword">const</font> vector&lt;CMesh::CSkinWeight&gt;        &amp;skinWeights= lodBuild.SkinWeights;
00341         <font class="keyword">const</font> vector&lt;CUV&gt;                                       &amp;uvs= lodBuild.UVs;
00342         <font class="keyword">const</font> vector&lt;CVector&gt;                           &amp;normals= lodBuild.Normals;
00343 
00344         <a class="code" href="debug_8h.html#a6">nlassert</a>(numVertices&gt;0);
00345         <a class="code" href="debug_8h.html#a6">nlassert</a>(triangleIndices.size()&gt;0);
00346         <a class="code" href="debug_8h.html#a6">nlassert</a>((triangleIndices.size()%3)==0);
00347         <a class="code" href="debug_8h.html#a6">nlassert</a>(skinWeights.size() == numVertices);
00348         <a class="code" href="debug_8h.html#a6">nlassert</a>(uvs.size() == numVertices);
00349         <a class="code" href="debug_8h.html#a6">nlassert</a>(normals.size() == numVertices);
00350 
00351         <font class="comment">// reset data</font>
00352         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o8">_Anims</a>);
00353         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o9">_AnimMap</a>);
00354         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>);
00355         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o6">_BoneMap</a>);
00356         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o7">_TriangleIndices</a>);
00357         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o3">_UVs</a>);
00358         <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o4">_Normals</a>);
00359 
00360         <font class="comment">// Copy data.</font>
00361         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o0">_Name</a>= name;
00362         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>= numVertices;
00363         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o2">_NumTriangles</a>= triangleIndices.size()/3;
00364         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o7">_TriangleIndices</a>= triangleIndices;
00365         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o3">_UVs</a>= uvs;
00366         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o4">_Normals</a>= normals;
00367 
00368         <font class="comment">// check indices.</font>
00369         uint    i;
00370         <font class="keywordflow">for</font>(i=0;i&lt;triangleIndices.size();i++)
00371         {
00372                 <a class="code" href="debug_8h.html#a6">nlassert</a>(triangleIndices[i]&lt;<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>);
00373         }
00374 
00375         <font class="comment">// Copy bone names, and compute bone Map</font>
00376         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>.resize(lodBuild.BonesNames.size());
00377         <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>.size(); i++)
00378         {
00379                 <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>[i].Name= lodBuild.BonesNames[i];
00380                 <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o6">_BoneMap</a>.insert( make_pair(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>[i].Name, i) );
00381         }
00382 
00383         <font class="comment">// "Normalize" SkinWeights for CLodCharacterShape</font>
00384         <font class="keywordflow">for</font>(i=0;i&lt;skinWeights.size();i++)
00385         {
00386                 <a class="code" href="debug_8h.html#a6">nlassert</a>(skinWeights[i].Weights[0]&gt;0);
00387                 <font class="comment">// for all slots not 0</font>
00388                 <font class="keywordflow">for</font>(uint j=0;j&lt;<a class="code" href="mesh_8h.html#a0">NL3D_MESH_SKINNING_MAX_MATRIX</a>;j++)
00389                 {
00390                         <font class="comment">// if this this slot is used.</font>
00391                         <font class="keywordflow">if</font>(skinWeights[i].Weights[j]&gt;0)
00392                         {
00393                                 uint boneId= skinWeights[i].MatrixId[j];
00394                                 <a class="code" href="debug_8h.html#a6">nlassert</a>(boneId &lt; <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>.size());
00395                                 <font class="comment">// init the vInf data</font>
00396                                 CVertexInf      vInf;
00397                                 vInf.VertexId= i;
00398                                 vInf.Influence= skinWeights[i].Weights[j];
00399                                 <font class="comment">// Insert this vertex influence in the bone.</font>
00400                                 <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>[boneId].InfVertices.push_back(vInf);
00401                         }
00402                         <font class="keywordflow">else</font>
00403                                 <font class="comment">// stop for this vertex.</font>
00404                                 <font class="keywordflow">break</font>;
00405                 }
00406         }
00407 }
00408 
00409 <font class="comment">// ***************************************************************************</font>
<a name="l00410"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a2">00410</a> <font class="keywordtype">bool</font>                    CLodCharacterShape::addAnim(<font class="keyword">const</font> CAnimBuild &amp;animBuild)
00411 {
00412         <font class="comment">// first, verify don't exist.</font>
00413         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#a5">getAnimIdByName</a>(animBuild.Name)!=-1)
00414                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00415 
00416         <font class="comment">// build basics of the animation</font>
00417         CAnim   dstAnim;
00418         dstAnim.Name= animBuild.Name;
00419         dstAnim.AnimLength= animBuild.AnimLength;
00420         <font class="comment">// Possible to have an Anim with just one key. setup an epsilon for animLength if 0.</font>
00421         <font class="keywordflow">if</font>(dstAnim.AnimLength&lt;=0)
00422                 dstAnim.AnimLength= 0.001f;
00423         dstAnim.OOAnimLength= 1.0f / animBuild.AnimLength;
00424         dstAnim.NumKeys= animBuild.NumKeys;
00425         <font class="comment">// verify size of the array</font>
00426         <a class="code" href="debug_8h.html#a6">nlassert</a>(dstAnim.NumKeys&gt;0);
00427         <a class="code" href="debug_8h.html#a6">nlassert</a>(dstAnim.NumKeys * <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a> == animBuild.Keys.size());
00428         <font class="comment">// resize dest array</font>
00429         dstAnim.Keys.resize(animBuild.Keys.size());
00430 
00431 
00432         <font class="comment">// Pack animation. 1st pass: compute max size over the animation vertices</font>
00433         uint    i;
00434         <font class="comment">// minimum shape size is , say, 1 cm :)</font>
00435         CVector         maxSize(0.01f, 0.01f, 0.01f);
00436         <font class="keywordflow">for</font>(i=0;i&lt;animBuild.Keys.size();i++)
00437         {
00438                 <font class="comment">// take the maxSize of the abs values</font>
00439                 maxSize.maxof(maxSize, -animBuild.Keys[i]);
00440                 maxSize.maxof(maxSize, animBuild.Keys[i]);
00441         }
00442 
00443         <font class="comment">// compute the UnPackScaleFactor ie maxSize, to be multiplied by max Abs value of a sint16</font>
00444         dstAnim.UnPackScaleFactor= maxSize * (1.0f/32767);
00445 
00446         <font class="comment">// Pack animation. 2st pass: pack.</font>
00447         CVectorD                packScaleFactor;
00448         packScaleFactor.x= 1.0 / dstAnim.UnPackScaleFactor.x;
00449         packScaleFactor.y= 1.0 / dstAnim.UnPackScaleFactor.y;
00450         packScaleFactor.z= 1.0 / dstAnim.UnPackScaleFactor.z;
00451         <font class="comment">// For all key vertices</font>
00452         <font class="keywordflow">for</font>(i=0;i&lt;animBuild.Keys.size();i++)
00453         {
00454                 CVector         <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= animBuild.Keys[i];
00455                 CVector3s       &amp;dstV= dstAnim.Keys[i];
00456 
00457                 <font class="comment">// compress</font>
00458                 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x= float(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x*packScaleFactor.x);
00459                 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y= float(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y*packScaleFactor.y);
00460                 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z= float(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z*packScaleFactor.z);
00461                 <font class="comment">// clamp to sint16 limits (for float precision problems).</font>
00462                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x, -32767, 32767);
00463                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y, -32767, 32767);
00464                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z, -32767, 32767);
00465                 <font class="comment">// get into the vector3s</font>
00466                 dstV.x= (sint16)floor(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.x);
00467                 dstV.y= (sint16)floor(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.y);
00468                 dstV.z= (sint16)floor(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>.z);
00469         }
00470 
00471 
00472         <font class="comment">// Add the anim to the array, and add an entry to the map</font>
00473         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o8">_Anims</a>.push_back(dstAnim);
00474         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o9">_AnimMap</a>.insert(make_pair(dstAnim.Name, <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o8">_Anims</a>.size()-1));
00475 
00476         <font class="keywordflow">return</font> <font class="keyword">true</font>;
00477 }
00478 
00479 <font class="comment">// ***************************************************************************</font>
<a name="l00480"></a><a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#a0">00480</a> <font class="keywordtype">void</font>                    CLodCharacterShape::CAnim::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f)
00481 {
00482         (void)f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(0);
00483 
00484         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#m0">Name</a>);
00485         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#m1">NumKeys</a>);
00486         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#m2">AnimLength</a>);
00487         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#m3">OOAnimLength</a>);
00488         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#m4">UnPackScaleFactor</a>);
00489         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CAnim.html#m5">Keys</a>);
00490 }
00491 
00492 
00493 <font class="comment">// ***************************************************************************</font>
<a name="l00494"></a><a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CBoneInfluence.html#a0">00494</a> <font class="keywordtype">void</font>                    CLodCharacterShape::CBoneInfluence::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f)
00495 {
00496         (void)f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(0);
00497 
00498         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CBoneInfluence.html#m0">Name</a>);
00499         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="structNL3D_1_1CLodCharacterShape_1_1CBoneInfluence.html#m1">InfVertices</a>);
00500 }
00501 
00502 
00503 <font class="comment">// ***************************************************************************</font>
<a name="l00504"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a3">00504</a> <font class="keywordtype">void</font>                    CLodCharacterShape::serial(<a class="code" href="classNLMISC_1_1IStream.html">NLMISC::IStream</a> &amp;f)
00505 {
00506         <font class="comment">// NEL_CLODSHAP</font>
00507         f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'_LEN');
00508         f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'DOLC');
00509         f.<a class="code" href="classNLMISC_1_1IStream.html#a30">serialCheck</a>((uint32)'PAHS');
00510 
00511         <font class="comment">/*</font>
00512 <font class="comment">        Version 1:</font>
00513 <font class="comment">                - UVs and Normals.</font>
00514 <font class="comment">        */</font>
00515         sint ver= f.<a class="code" href="classNLMISC_1_1IStream.html#a29">serialVersion</a>(1);
00516 
00517         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o0">_Name</a>);
00518         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>);
00519         f.<a class="code" href="classNLMISC_1_1IStream.html#a5">serial</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o2">_NumTriangles</a>);
00520         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>);
00521         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o6">_BoneMap</a>);
00522         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o7">_TriangleIndices</a>);
00523         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o8">_Anims</a>);
00524         f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o9">_AnimMap</a>);
00525 
00526         <font class="keywordflow">if</font>(ver&gt;=1)
00527         {
00528                 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o3">_UVs</a>);
00529                 f.<a class="code" href="classNLMISC_1_1IStream.html#a7">serialCont</a>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o4">_Normals</a>);
00530         }
00531         <font class="keywordflow">else</font>
00532         {
00533                 <font class="comment">// Must init dummy UVs/normals</font>
00534                 <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o3">_UVs</a>.resize(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>, CUV(0,0));
00535                 <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o4">_Normals</a>.resize(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>, CVector::K);
00536         }
00537 }
00538 
00539 <font class="comment">// ***************************************************************************</font>
<a name="l00540"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a5">00540</a> sint                    CLodCharacterShape::getAnimIdByName(<font class="keyword">const</font> std::string &amp;name)<font class="keyword"> const</font>
00541 <font class="keyword"></font>{
00542         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#u2">CstItStrIdMap</a>   it= <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o9">_AnimMap</a>.find(name);
00543         <font class="keywordflow">if</font>(it == <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o9">_AnimMap</a>.end())
00544                 <font class="keywordflow">return</font> -1;
00545         <font class="keywordflow">else</font>
00546                 <font class="keywordflow">return</font> it-&gt;second;
00547 }
00548 
00549 
00550 <font class="comment">// ***************************************************************************</font>
<a name="l00551"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a9">00551</a> sint                    CLodCharacterShape::getBoneIdByName(<font class="keyword">const</font> std::string &amp;name)<font class="keyword"> const</font>
00552 <font class="keyword"></font>{
00553         <a class="code" href="classNL3D_1_1CLodCharacterShape.html#u2">CstItStrIdMap</a>   it= <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o6">_BoneMap</a>.find(name);
00554         <font class="keywordflow">if</font>(it == <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o6">_BoneMap</a>.end())
00555                 <font class="keywordflow">return</font> -1;
00556         <font class="keywordflow">else</font>
00557                 <font class="keywordflow">return</font> it-&gt;second;
00558 }
00559 
00560 
00561 <font class="comment">// ***************************************************************************</font>
<a name="l00562"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a10">00562</a> <font class="keyword">const</font> uint32    *CLodCharacterShape::getTriangleArray()<font class="keyword"> const</font>
00563 <font class="keyword"></font>{
00564         <font class="keywordflow">if</font>(_NumTriangles)
00565                 <font class="keywordflow">return</font> &amp;<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o7">_TriangleIndices</a>[0];
00566         <font class="keywordflow">else</font>
00567                 <font class="keywordflow">return</font> NULL;
00568 }
00569 
00570 <font class="comment">// ***************************************************************************</font>
<a name="l00571"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a13">00571</a> <font class="keyword">const</font> CLodCharacterShape::CVector3s     *CLodCharacterShape::getAnimKey(uint animId, <a class="code" href="namespaceNL3D.html#a2">TGlobalAnimationTime</a> time, <font class="keywordtype">bool</font> wrapMode, CVector &amp;unPackScaleFactor)<font class="keyword"> const</font>
00572 <font class="keyword"></font>{
00573         <font class="keywordtype">float</font>   localTime;
00574 
00575         <font class="keywordflow">if</font>(animId&gt;=<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o8">_Anims</a>.size())
00576                 <font class="keywordflow">return</font> NULL;
00577 
00578         <font class="comment">// get the anim.</font>
00579         <font class="keyword">const</font> CAnim &amp;anim= <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o8">_Anims</a>[animId];
00580 
00581         <font class="comment">// scale info</font>
00582         unPackScaleFactor= anim.UnPackScaleFactor;
00583 
00584         <font class="comment">// Loop mgt.</font>
00585         <font class="keywordflow">if</font>(wrapMode)
00586                 localTime= (float)fmod(time, anim.AnimLength);
00587         <font class="keywordflow">else</font>
00588                 localTime= (float)time;
00589 
00590         <font class="comment">// Clamp to the range.</font>
00591         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(localTime, 0, anim.AnimLength);
00592 
00593         <font class="comment">// get the key.</font>
00594         sint    keyId= (sint)floor( (localTime*anim.OOAnimLength) * anim.NumKeys );
00595         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(keyId, 0, <a class="code" href="memory__common_8h.html#a14">sint</a>(anim.NumKeys-1));
00596 
00597         <font class="comment">// return the key.</font>
00598         <font class="keywordflow">return</font> &amp;anim.Keys[keyId * <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>];
00599 }
00600 
00601 <font class="comment">// ***************************************************************************</font>
<a name="l00602"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a11">00602</a> <font class="keyword">const</font> CUV               *CLodCharacterShape::getUVs()<font class="keyword"> const</font>
00603 <font class="keyword"></font>{
00604         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>==0)
00605                 <font class="keywordflow">return</font> NULL;
00606 
00607         <font class="keywordflow">return</font> &amp;<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o3">_UVs</a>[0];
00608 }
00609 
00610 <font class="comment">// ***************************************************************************</font>
<a name="l00611"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#a12">00611</a> <font class="keyword">const</font> CVector   *CLodCharacterShape::getNormals()<font class="keyword"> const</font>
00612 <font class="keyword"></font>{
00613         <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o1">_NumVertices</a>==0)
00614                 <font class="keywordflow">return</font> NULL;
00615 
00616         <font class="keywordflow">return</font> &amp;<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o4">_Normals</a>[0];
00617 }
00618 
00619 
00620 
00621 <font class="comment">// ***************************************************************************</font>
00622 <font class="comment">// ***************************************************************************</font>
00623 <font class="comment">// Bone coloring</font>
00624 <font class="comment">// ***************************************************************************</font>
00625 <font class="comment">// ***************************************************************************</font>
00626 
00627 
00628 <font class="comment">// ***************************************************************************</font>
<a name="l00629"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#z536_0">00629</a> <font class="keywordtype">void</font>                    CLodCharacterShape::startBoneColor(std::vector&lt;NLMISC::CRGBAF&gt;  &amp;tmpColors)<font class="keyword"> const</font>
00630 <font class="keyword"></font>{
00631         <font class="comment">// alocate</font>
00632         tmpColors.resize(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#a6">getNumVertices</a>());
00633         <font class="comment">// fill with black (in Alpha too)</font>
00634         CRGBAF  black(0,0,0,0);
00635         fill(tmpColors.begin(), tmpColors.end(), black);
00636 }
00637 
00638 <font class="comment">// ***************************************************************************</font>
<a name="l00639"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#z536_1">00639</a> <font class="keywordtype">void</font>                    CLodCharacterShape::addBoneColor(uint boneId, CRGBA     color, std::vector&lt;NLMISC::CRGBAF&gt; &amp;tmpColors)<font class="keyword"> const</font>
00640 <font class="keyword"></font>{
00641         <font class="comment">// Yoyo: This is an error to not have the same skeleton that the one stored in the lod shape. But must not crash</font>
00642         <font class="keywordflow">if</font>(boneId&gt;=<a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>.size())
00643                 <font class="keywordflow">return</font>;
00644         <font class="keyword">const</font> CBoneInfluence    &amp;bone= <a class="code" href="classNL3D_1_1CLodCharacterShape.html#o5">_Bones</a>[boneId];
00645 
00646         <font class="comment">// for all vertices influenced by this bone, must influence the color</font>
00647         <font class="keywordflow">for</font>(uint i=0; i&lt;bone.InfVertices.size(); i++)
00648         {
00649                 <font class="keyword">const</font> CVertexInf        &amp;vInf= bone.InfVertices[i];
00650                 <font class="comment">// Add the color, modulated by the vertex weight</font>
00651                 tmpColors[vInf.VertexId].R+= color.R * vInf.Influence;
00652                 tmpColors[vInf.VertexId].G+= color.G * vInf.Influence;
00653                 tmpColors[vInf.VertexId].B+= color.B * vInf.Influence;
00654                 <font class="comment">// Add the weight in alpha channel</font>
00655                 tmpColors[vInf.VertexId].A+= vInf.Influence;
00656         }
00657 }
00658 
00659 <font class="comment">// ***************************************************************************</font>
<a name="l00660"></a><a class="code" href="classNL3D_1_1CLodCharacterShape.html#z536_2">00660</a> <font class="keywordtype">void</font>                    CLodCharacterShape::endBoneColor(<font class="keyword">const</font> std::vector&lt;NLMISC::CRGBAF&gt; &amp;tmpColors, std::vector&lt;NLMISC::CRGBA&gt;       &amp;dstColors)<font class="keyword"> const</font>
00661 <font class="keyword"></font>{
00662         <font class="comment">// The default value if vertex is not influenced at all</font>
00663         CRGBA   defaultColor(128,128,128,0);
00664 
00665         <font class="comment">// resize dstColors</font>
00666         <a class="code" href="debug_8h.html#a6">nlassert</a>(tmpColors.size() == <a class="code" href="classNL3D_1_1CLodCharacterShape.html#a6">getNumVertices</a>());
00667         dstColors.resize(<a class="code" href="classNL3D_1_1CLodCharacterShape.html#a6">getNumVertices</a>());
00668 
00669         <font class="comment">// For all vertices</font>
00670         <font class="keywordflow">for</font>(uint i=0; i&lt;dstColors.size(); i++)
00671         {
00672                 <font class="comment">// If the vertex is not influenced, set transparent</font>
00673                 <font class="keywordflow">if</font>(tmpColors[i].A==0)
00674                         dstColors[i]= defaultColor;
00675                 <font class="keywordflow">else</font>
00676                 {
00677                         <font class="comment">// Average the color.</font>
00678                         <font class="keywordtype">float</font>   R= tmpColors[i].R / tmpColors[i].A;
00679                         <font class="keywordtype">float</font>   G= tmpColors[i].G / tmpColors[i].A;
00680                         <font class="keywordtype">float</font>   B= tmpColors[i].B / tmpColors[i].A;
00681                         <font class="comment">// store.</font>
00682                         dstColors[i].R= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(R);
00683                         dstColors[i].G= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(G);
00684                         dstColors[i].B= (uint8)<a class="code" href="namespaceNL3D.html#a362">OptFastFloor</a>(B);
00685                         dstColors[i].A= 255;
00686                 }
00687         }
00688 }
00689 
00690 
00691 
00692 } <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>