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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>patch_noise.cpp</h1><a href="patch__noise_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2000 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026 <font class="preprocessor">#include "<a class="code" href="std3d_8h.html">std3d.h</a>"</font>
00027
00028
00029 <font class="preprocessor">#include "<a class="code" href="patch_8h.html">3d/patch.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="tessellation_8h.html">3d/tessellation.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="bezier__patch_8h.html">3d/bezier_patch.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="src_23d_2zone_8h.html">3d/zone.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="vector_8h.html">nel/misc/vector.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font>
00036 <font class="preprocessor">#include "<a class="code" href="tile__noise__map_8h.html">3d/tile_noise_map.h</a>"</font>
00037 <font class="preprocessor">#include "<a class="code" href="patchuv__locator_8h.html">3d/patchuv_locator.h</a>"</font>
00038 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00039 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00040
00041
00042 <font class="keyword">namespace </font>NL3D
00043 {
00044
00045
00046 <font class="comment">// ***************************************************************************</font>
00047
00048
00049 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00050 <font class="preprocessor"></font>
00051 <font class="comment">/* This floor works only for floor with noise, because floor/ceil are only made on decimal coordinates:</font>
00052 <font class="comment"> sTile =1.25 .... NB: because of difference of mapping (rare case), we may have sometimes values with</font>
00053 <font class="comment"> precision < 1/4 (eg 1.125). Just use f*256 to compute the floor.</font>
00054 <font class="comment"></font>
00055 <font class="comment"> NB: using a fastFloor() (fistp changing the controlfp() is not very a good idea here, because </font>
00056 <font class="comment"> computeNoise() are not "packed", so change on controlFp() would bee to frequent... </font>
00057 <font class="comment"> And also because we need either floor() or ceil() here.</font>
00058 <font class="comment">*/</font>
00059 <font class="keyword">inline</font> sint <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(<font class="keywordtype">float</font> f)
00060 {
00061 <font class="comment">// build a fixed 24:8.</font>
00062 sint a;
00063 f*=256;
00064
00065 <font class="comment">// fast ftol. work if no decimal.</font>
00066 _asm
00067 {
00068 fld f
00069 fistp a
00070 }
00071
00072 <font class="comment">// floor.</font>
00073 a>>=8;
00074
00075 <font class="keywordflow">return</font> a;
00076 }
00077
00078
00079 <font class="keyword">inline</font> sint <a class="code" href="namespaceNL3D.html#a394">noiseCeil</a>(<font class="keywordtype">float</font> f)
00080 {
00081 <font class="comment">// build a fixed 24:8.</font>
00082 sint a;
00083 f*=256;
00084
00085 <font class="comment">// fast ftol. work if no decimal.</font>
00086 _asm
00087 {
00088 fld f
00089 fistp a
00090 }
00091
00092 <font class="comment">// ceil.</font>
00093 a+=255;
00094 a>>=8;
00095
00096 <font class="keywordflow">return</font> a;
00097 }
00098
00099
00100 <font class="keyword">inline</font> <font class="keywordtype">float</font> <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(<font class="keywordtype">float</font> f)
00101 {
00102 <font class="keywordflow">return</font> (float)<a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(f);
00103 }
00104 <font class="keyword">inline</font> <font class="keywordtype">float</font> <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(<font class="keywordtype">float</font> f)
00105 {
00106 <font class="keywordflow">return</font> (float)<a class="code" href="namespaceNL3D.html#a394">noiseCeil</a>(f);
00107 }
00108
00109
00110 <font class="preprocessor">#else</font>
00111 <font class="preprocessor"></font>
00112
00113 <font class="keyword">inline</font> <font class="keywordtype">float</font> <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(<font class="keywordtype">float</font> f)
00114 {
00115 <font class="keywordflow">return</font> (float)floor(f);
00116 }
00117 <font class="keyword">inline</font> <font class="keywordtype">float</font> <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(<font class="keywordtype">float</font> f)
00118 {
00119 <font class="keywordflow">return</font> (float)ceil(f);
00120 }
00121
00122 <font class="keyword">inline</font> sint <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(<font class="keywordtype">float</font> f)
00123 {
00124 <font class="keywordflow">return</font> (sint)floor(f);
00125 }
00126 <font class="keyword">inline</font> sint <a class="code" href="namespaceNL3D.html#a394">noiseCeil</a>(<font class="keywordtype">float</font> f)
00127 {
00128 <font class="keywordflow">return</font> (sint)ceil(f);
00129 }
00130
00131 <font class="preprocessor">#endif</font>
00132 <font class="preprocessor"></font>
00133
00134
00135 <font class="comment">// ***************************************************************************</font>
<a name="l00136"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_0">00136</a> <font class="keywordtype">float</font> CPatch::computeDisplaceRawInteger(sint ts, sint tt, sint ms, sint mt)<font class="keyword"> const</font>
00137 <font class="keyword"></font>{
00138 <font class="comment">// Choose the noiseMap.</font>
00139 <font class="comment">// ===============================</font>
00140 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(ts, 0, <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>-1);
00141 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tt, 0, <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>-1);
00142
00143 uint tileId= tt*<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a> + ts;
00144 <font class="comment">// Get the tile for pass0. This is the principal tile, and this one tells what noise to take.</font>
00145 sint tileNumber= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].Tile[0];
00146 <font class="comment">// Get the subNoise from tileElement.</font>
00147 uint tileSubNoise= <a class="code" href="classNL3D_1_1CPatch.html#m4">Tiles</a>[tileId].getTileSubNoise();
00148
00149 <font class="comment">// retrieve the wanted noiseMap.</font>
00150 CTileNoiseMap *noiseMap;
00151 noiseMap = <a class="code" href="classNL3D_1_1CPatch.html#a5">getZone</a>()->getLandscape()->TileBank.getTileNoiseMap (tileNumber, tileSubNoise);
00152
00153
00154 <font class="comment">// Sample the noiseMap with (s,t).</font>
00155 <font class="comment">// ===============================</font>
00156
00157 <font class="comment">// sample from map.</font>
00158 sint8 pix= noiseMap->Pixels[mt*<a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a> + ms];
00159
00160 <font class="comment">// normalize.</font>
00161 <font class="keywordflow">return</font> (float)pix * (<a class="code" href="patch_8h.html#a11">NL3D_NOISE_MAX</a> / 127.f);
00162 }
00163
00164
00165 <font class="comment">// ***************************************************************************</font>
<a name="l00166"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_1">00166</a> <font class="keywordtype">void</font> CPatch::computeDisplaceRawCoordinates(<font class="keywordtype">float</font> sTile, <font class="keywordtype">float</font> tTile, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>,
00167 sint &ts, sint &tt, sint &ms, sint &mt)<font class="keyword"> const</font>
00168 <font class="keyword"></font>{
00169 <font class="comment">// Choose the noiseMap.</font>
00170 <font class="comment">// ===============================</font>
00171 <font class="comment">// Compute coordinate in the patch.</font>
00172 ts= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(sTile);
00173 tt= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(tTile);
00174
00175
00176 <font class="comment">// Sample the noiseMap with (s,t).</font>
00177 <font class="comment">// ===============================</font>
00178
00179 <font class="comment">// scale the map.</font>
00180 <font class="keywordtype">float</font> u= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a> * <a class="code" href="tile__noise__map_8h.html#a0">NL3D_TILE_NOISE_MAP_TILE_FACTOR</a>;
00181 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a> * <a class="code" href="tile__noise__map_8h.html#a0">NL3D_TILE_NOISE_MAP_TILE_FACTOR</a>;
00182
00183 <font class="comment">// Speed rotation.</font>
00184 CUV uv;
00185 <font class="keywordflow">switch</font>(<a class="code" href="classNL3D_1_1CPatch.html#z668_2">NoiseRotation</a> & 3)
00186 {
00187 <font class="keywordflow">case</font> 0:
00188 uv.U= u;
00189 uv.V= <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00190 <font class="keywordflow">break</font>;
00191 <font class="keywordflow">case</font> 1:
00192 uv.U= <a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>-<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00193 uv.V= u;
00194 <font class="keywordflow">break</font>;
00195 <font class="keywordflow">case</font> 2:
00196 uv.U= <a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>-u;
00197 uv.V= <a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>-<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00198 <font class="keywordflow">break</font>;
00199 <font class="keywordflow">case</font> 3:
00200 uv.U= <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00201 uv.V= <a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>-u;
00202 <font class="keywordflow">break</font>;
00203 }
00204
00205 <font class="comment">// direct map (no bilinear, no round, the case where s,t < 1/4 of a tile is very rare).</font>
00206 ms= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(uv.U);
00207 mt= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(uv.V);
00208
00209 <font class="comment">// Manage Tiling (add NL3D_TILE_NOISE_MAP_SIZE*1 should be sufficient, but take margin).</font>
00210 ms= (ms + (<a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>*256)) & (<a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>-1);
00211 mt= (mt + (<a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>*256)) & (<a class="code" href="tile__noise__map_8h.html#a1">NL3D_TILE_NOISE_MAP_SIZE</a>-1);
00212 }
00213
00214
00215
00216 <font class="comment">// ***************************************************************************</font>
<a name="l00217"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_2">00217</a> <font class="keywordtype">float</font> CPatch::computeDisplaceRaw(<font class="keywordtype">float</font> sTile, <font class="keywordtype">float</font> tTile, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)<font class="keyword"> const</font>
00218 <font class="keyword"></font>{
00219 sint ts,tt,ms,mt;
00220 <a class="code" href="classNL3D_1_1CPatch.html#z685_1">computeDisplaceRawCoordinates</a>(sTile, tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, ts, tt, ms, mt);
00221 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#z685_0">computeDisplaceRawInteger</a>(ts, tt, ms, mt);
00222
00223 }
00224
00225 <font class="comment">// ***************************************************************************</font>
00226 <font class="keyword">static</font> <font class="keyword">inline</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a395">computeDisplaceBilinear</a>(<font class="keywordtype">float</font> sTile, <font class="keywordtype">float</font> tTile,
00227 <font class="keywordtype">float</font> &sInc, <font class="keywordtype">float</font> &tInc, <font class="keywordtype">float</font> &sa, <font class="keywordtype">float</font> &ta, <font class="keywordtype">float</font> &sa1, <font class="keywordtype">float</font> &ta1)
00228 {
00229 <font class="keywordtype">float</font> sDecimal= sTile-<a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(sTile);
00230 <font class="keywordtype">float</font> tDecimal= tTile-<a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(tTile);
00231 <font class="keywordtype">float</font> sDist, tDist;
00232
00233 <font class="comment">// Do a bilinear centered on 0.5, 0.5.</font>
00234
00235 <font class="comment">// Compute increment, according to position against center.</font>
00236 <font class="keywordflow">if</font>(sDecimal>=0.5)
00237 sInc= 1;
00238 <font class="keywordflow">else</font>
00239 sInc= -1;
00240 <font class="keywordflow">if</font>(tDecimal>=0.5)
00241 tInc= 1;
00242 <font class="keywordflow">else</font>
00243 tInc= -1;
00244
00245 <font class="comment">// Compute weight factor.</font>
00246 sDist= (float)fabs(0.5 - sDecimal); <font class="comment">// s distance from center.</font>
00247 tDist= (float)fabs(0.5 - tDecimal); <font class="comment">// t distance from center.</font>
00248 sa= 1-sDist;
00249 ta= 1-tDist;
00250 sa1= 1-sa;
00251 ta1= 1-ta;
00252 }
00253
00254
00255 <font class="comment">// ***************************************************************************</font>
<a name="l00256"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_4">00256</a> <font class="keywordtype">float</font> CPatch::computeDisplaceInteriorSmooth(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)<font class="keyword"> const</font>
00257 <font class="keyword"></font>{
00258 <font class="keywordtype">float</font> sTile= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00259 <font class="keywordtype">float</font> tTile= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00260 <font class="keywordtype">float</font> ret;
00261
00262 <font class="comment">// compute bi-linear weight factors.</font>
00263 <font class="keywordtype">float</font> sInc, tInc, sa, ta, sa1, ta1;
00264 <a class="code" href="namespaceNL3D.html#a395">computeDisplaceBilinear</a>(sTile, tTile, sInc, tInc, sa, ta, sa1, ta1);
00265
00266
00267 <font class="comment">// NB: to have smooth transition, must keep the same (s,t), so we do a transition with the noise tile of </font>
00268 <font class="comment">// our neigbhor, but under us.</font>
00269
00270 <font class="comment">// speed up, using just one computeDisplaceRawCoordinates(), and multiple computeDisplaceRawInteger().</font>
00271 sint ts,tt,ms,mt;
00272 <a class="code" href="classNL3D_1_1CPatch.html#z685_1">computeDisplaceRawCoordinates</a>(sTile, tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, ts, tt, ms, mt);
00273
00274 sint sIncInt= (sint) sInc;
00275 sint tIncInt= (sint) tInc;
00276 ret = <a class="code" href="classNL3D_1_1CPatch.html#z685_0">computeDisplaceRawInteger</a>(ts, tt, ms,mt) * sa * ta;
00277 ret+= <a class="code" href="classNL3D_1_1CPatch.html#z685_0">computeDisplaceRawInteger</a>(ts+sIncInt, tt, ms,mt) * sa1 * ta;
00278 ret+= <a class="code" href="classNL3D_1_1CPatch.html#z685_0">computeDisplaceRawInteger</a>(ts, tt+tIncInt, ms,mt) * sa * ta1;
00279 ret+= <a class="code" href="classNL3D_1_1CPatch.html#z685_0">computeDisplaceRawInteger</a>(ts+sIncInt, tt+tIncInt, ms,mt) * sa1 * ta1;
00280
00281 <font class="keywordflow">return</font> ret;
00282 }
00283
00284
00285 <font class="comment">// ***************************************************************************</font>
<a name="l00286"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_5">00286</a> <font class="keywordtype">float</font> CPatch::computeDisplaceEdgeSmooth(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, sint8 smoothBorderX, sint8 smoothBorderY)<font class="keyword"> const</font>
00287 <font class="keyword"></font>{
00288 <font class="keywordtype">float</font> sTile= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00289 <font class="keywordtype">float</font> tTile= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00290 CBindInfo bindInfo;
00291 uint edge=0;
00292
00293 <font class="comment">// only one must be not null</font>
00294 <a class="code" href="debug_8h.html#a6">nlassert</a>( (smoothBorderX==0) != (smoothBorderY==0) );
00295
00296
00297 <font class="comment">// Get the edge against we must share displace.</font>
00298 <font class="keywordflow">if</font>(smoothBorderX==-1) edge=0;
00299 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==1) edge=1;
00300 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderX==1) edge=2;
00301 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==-1) edge=3;
00302 <font class="keywordflow">else</font> <a class="code" href="debug_8h.html#a12">nlstop</a>;
00303
00304 <font class="comment">// Build the bindInfo against this edge.</font>
00305 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edge, bindInfo);
00306
00307 <font class="comment">// Fast reject: if no neighbor, just do a simple computeDisplaceInteriorSmooth.</font>
00308 <font class="keywordflow">if</font>(!bindInfo.Zone)
00309 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#z685_4">computeDisplaceInteriorSmooth</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00310 <font class="comment">// else, look for result in neighborhood.</font>
00311 <font class="keywordflow">else</font>
00312 {
00313 <font class="keywordtype">float</font> ret;
00314
00315
00316 <font class="comment">// compute bi-linear weight factors.</font>
00317 <font class="keywordtype">float</font> sInc, tInc, sa, ta, sa1, ta1;
00318 <a class="code" href="namespaceNL3D.html#a395">computeDisplaceBilinear</a>(sTile, tTile, sInc, tInc, sa, ta, sa1, ta1);
00319 <font class="comment">// Manage limit case: if bilinear has not chosen the good direction (because of floor and orientation).</font>
00320 <font class="comment">// eg on Right edge: This case arise if sDecimal==0, so if sa==sa1==0.5f. result is that</font>
00321 <font class="comment">// smoothBorderX is != than sInc on right border. same reasoning with downBorder (smoothBorderY=1).</font>
00322
00323 <font class="comment">// NO NEED TO DO HERE, because sInc or tInc is not used if it is bad (smoothBorder? used instead).</font>
00324 <font class="comment">// and no need to correct sa, sa1, because in this case they are both equal to 0.5.</font>
00325
00326
00327 <font class="comment">// compute Neighboring info.</font>
00328 CPatchUVLocator uvLocator;
00329 uvLocator.build(<font class="keyword">this</font>, edge, bindInfo);
00330
00331 <font class="comment">/* NB: there is floor problems with neighbors:</font>
00332 <font class="comment"> - difference of orientation => uv.v=1. This point to the 1th tile. But this is not the same, if</font>
00333 <font class="comment"> v goes to up, or goes to down.</font>
00334 <font class="comment"> - if multiple bind, problem at limit (eg a bind 1/2 on edge 0 with OrdertT=8, when uv.v= 4).</font>
00335 <font class="comment"> because, selection of the patch is dependent of orientation too.</font>
00336 <font class="comment"> To avoid them, just take center of (sTile, tTile) to remove ambiguity.</font>
00337 <font class="comment"> This works because computeDisplaceRaw() use sTile, tTile to get the noiseMap, so the decimal part is not </font>
00338 <font class="comment"> used.</font>
00339 <font class="comment"></font>
00340 <font class="comment"> Notice that we do this AFTER computeDisplaceBilinear() of course.</font>
00341 <font class="comment"> */</font>
00342 sTile= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(sTile) + 0.5f;
00343 tTile= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(tTile) + 0.5f;
00344 <font class="comment">// If we were exactly on the superior edge, prec compute is false... so correct this here.</font>
00345 <font class="keywordflow">if</font>(sTile><a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>) sTile--;
00346 <font class="keywordflow">if</font>(tTile><a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) tTile--;
00347
00348
00349 <font class="comment">// Bilinear across an edge (enjoy!!).</font>
00350 CVector2f stTileIn, stIn;
00351 CVector2f stTileOut, stOut;
00352 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchOut;
00353 uint patchId;
00354
00355
00356 <font class="comment">// if vertical edge.</font>
00357 <font class="keywordflow">if</font>(smoothBorderX!=0)
00358 {
00359 <font class="comment">// compute contribution of our patch.</font>
00360 ret = <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile,tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) * sa * ta;
00361 ret+= <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile,tTile+tInc, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) * sa * ta1;
00362
00363 <font class="comment">// compute contribution of next(s) patchs.</font>
00364
00365 <font class="comment">// contribution of next at tTile.</font>
00366 <font class="comment">// Keep the same coordinate.</font>
00367 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00368 <font class="comment">// But look for the neighbor noise tile.</font>
00369 stTileIn.set(sTile+smoothBorderX, tTile);
00370 <font class="comment">// change basis: find the s,t on the neighbor patch.</font>
00371 patchId= uvLocator.selectPatch(stTileIn);
00372 uvLocator.locateUV(stTileIn, patchId, patchOut, stTileOut);
00373 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00374 <font class="comment">// Compute displace, and bi-linear on the neighbor patch.</font>
00375 ret+= patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa1 * ta;
00376
00377 <font class="comment">// contribution of next at tTile+tInc (same reasoning).</font>
00378 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00379 stTileIn.set(sTile+smoothBorderX, tTile+tInc);
00380 patchId= uvLocator.selectPatch(stTileIn);
00381 uvLocator.locateUV(stTileIn, patchId, patchOut, stTileOut);
00382 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00383 ret+= patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa1 * ta1;
00384
00385 }
00386 <font class="comment">// else if horizontal edge.</font>
00387 <font class="keywordflow">else</font>
00388 {
00389 <font class="comment">// same reasoning as above.</font>
00390
00391 <font class="comment">// compute contribution of our patch.</font>
00392 ret = <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile, tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) * sa * ta;
00393 ret+= <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile+sInc,tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) * sa1 * ta;
00394
00395 <font class="comment">// compute contribution of next(s) patchs.</font>
00396 <font class="comment">// contribution of next at tTile.</font>
00397 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00398 stTileIn.set(sTile, tTile+smoothBorderY);
00399 patchId= uvLocator.selectPatch(stTileIn);
00400 uvLocator.locateUV(stTileIn, patchId, patchOut, stTileOut);
00401 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00402 ret+= patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa * ta1;
00403
00404 <font class="comment">// contribution of next at tTile+tInc (same reasoning).</font>
00405 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00406 stTileIn.set(sTile+sInc, tTile+smoothBorderY);
00407 patchId= uvLocator.selectPatch(stTileIn);
00408 uvLocator.locateUV(stTileIn, patchId, patchOut, stTileOut);
00409 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00410 ret+= patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa1 * ta1;
00411 }
00412
00413 <font class="keywordflow">return</font> ret;
00414 }
00415
00416 }
00417
00418
00419 <font class="comment">// ***************************************************************************</font>
<a name="l00420"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_3">00420</a> <font class="keywordtype">float</font> CPatch::computeDisplaceRawOnNeighbor(<font class="keywordtype">float</font> sTile, <font class="keywordtype">float</font> tTile, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)<font class="keyword"> const</font>
00421 <font class="keyword"></font>{
00422 sint edge= -1;
00423
00424 <font class="comment">// look on what neighbor patch we must find the value (if any).</font>
00425 <font class="keywordflow">if</font>(sTile<0) edge=0;
00426 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(tTile><a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) edge=1;
00427 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(sTile><a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>) edge=2;
00428 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(tTile<0) edge=3;
00429
00430 <font class="comment">// If the location is In the patch, just return normal value.</font>
00431 <font class="keywordflow">if</font>(edge==-1)
00432 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile, tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00433 <font class="comment">// else must find on neighbor.</font>
00434 <font class="keywordflow">else</font>
00435 {
00436 CBindInfo bindInfo;
00437 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edge, bindInfo);
00438
00439 <font class="comment">// Fast reject: if no neighbor on the edge, just do a simple computeDisplaceRaw()</font>
00440 <font class="keywordflow">if</font>(!bindInfo.Zone)
00441 {
00442 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile, tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00443 }
00444 <font class="comment">// else must find on neighbor.</font>
00445 <font class="keywordflow">else</font>
00446 {
00447 CPatchUVLocator uvLocator;
00448 uvLocator.build(<font class="keyword">this</font>, edge, bindInfo);
00449
00450 CVector2f stTileIn, stIn;
00451 CVector2f stTileOut, stOut;
00452 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchOut;
00453 uint patchId;
00454
00455 <font class="comment">// look on neighbor. same reasoning as in computeDisplaceEdgeSmooth();</font>
00456 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00457 stTileIn.set(sTile, tTile);
00458 patchId= uvLocator.selectPatch(stTileIn);
00459 uvLocator.locateUV(stTileIn, patchId, patchOut, stTileOut);
00460 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00461 <font class="keywordflow">return</font> patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y);
00462 }
00463
00464 }
00465 }
00466
00467
00468 <font class="comment">// ***************************************************************************</font>
<a name="l00469"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_6">00469</a> <font class="keywordtype">float</font> CPatch::computeDisplaceCornerSmooth(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, sint8 smoothBorderX, sint8 smoothBorderY)<font class="keyword"> const</font>
00470 <font class="keyword"></font>{
00471 <font class="comment">// compute the value across the corner (enjoy!!)</font>
00472 <font class="comment">// NB: Only corners with Edges==4 and corners on a bind are correclty supported.</font>
00473 <font class="comment">// ignore problems with corner which nbEdges!=4, because Blend of normals blend to 0 on corner (see computenoise()).</font>
00474
00475 <font class="keywordtype">float</font> sTile= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00476 <font class="keywordtype">float</font> tTile= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00477 CBindInfo bindInfoX;
00478 CBindInfo bindInfoY;
00479 uint edgeX=0;
00480 uint edgeY=0;
00481
00482 <font class="comment">// both must be not null</font>
00483 <a class="code" href="debug_8h.html#a6">nlassert</a>( (smoothBorderX!=0) && (smoothBorderY!=0) );
00484
00485
00486 <font class="comment">// Get the edge against we must share displace.</font>
00487 <font class="keywordflow">if</font>(smoothBorderX==-1) edgeX=0;
00488 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderX==1) edgeX=2;
00489 <font class="keywordflow">else</font> <a class="code" href="debug_8h.html#a12">nlstop</a>;
00490 <font class="keywordflow">if</font>(smoothBorderY==1) edgeY=1;
00491 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==-1) edgeY=3;
00492 <font class="keywordflow">else</font> <a class="code" href="debug_8h.html#a12">nlstop</a>;
00493
00494 <font class="comment">// Build the bindInfo against those 2 edge.</font>
00495 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edgeX, bindInfoX);
00496 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edgeY, bindInfoY);
00497
00498 <font class="comment">// Fast reject: if no neighbor on one of the edge, just do a simple computeDisplaceInteriorSmooth.</font>
00499 <font class="keywordflow">if</font>(!bindInfoX.Zone || !bindInfoY.Zone)
00500 <font class="keywordflow">return</font> <a class="code" href="classNL3D_1_1CPatch.html#z685_4">computeDisplaceInteriorSmooth</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00501 <font class="keywordflow">else</font>
00502 {
00503 <font class="keywordtype">float</font> ret;
00504
00505
00506 <font class="comment">// compute bi-linear weight factors.</font>
00507 <font class="keywordtype">float</font> sInc, tInc, sa, ta, sa1, ta1;
00508 <a class="code" href="namespaceNL3D.html#a395">computeDisplaceBilinear</a>(sTile, tTile, sInc, tInc, sa, ta, sa1, ta1);
00509 <font class="comment">// Manage limit case: if bilinear has not chosen the good direction (because of floor and orientation).</font>
00510 <font class="comment">// eg on Right edge: This case arise if sDecimal==0, so if sa==sa1==0.5f. result is that</font>
00511 <font class="comment">// smoothBorderX is != than sInc on right border. same reasoning with downBorder (smoothBorderY=1).</font>
00512
00513 <font class="comment">// NO NEED TO DO HERE, because sInc or tInc are not used at all.</font>
00514
00515
00516
00517 <font class="comment">// compute Neighboring info.</font>
00518 CPatchUVLocator uvLocatorX;
00519 CPatchUVLocator uvLocatorY;
00520 uvLocatorX.build(<font class="keyword">this</font>, edgeX, bindInfoX);
00521 uvLocatorY.build(<font class="keyword">this</font>, edgeY, bindInfoY);
00522
00523
00524 <font class="comment">/* NB: see floor problems note in computeDisplaceEdgeSmooth();</font>
00525 <font class="comment"> */</font>
00526 sTile= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(sTile) + 0.5f;
00527 tTile= <a class="code" href="namespaceNL3D.html#a393">noiseFloor</a>(tTile) + 0.5f;
00528 <font class="comment">// If we were exactly on the superior edge, prec compute is false... so correct this here.</font>
00529 <font class="keywordflow">if</font>(sTile><a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>) sTile--;
00530 <font class="keywordflow">if</font>(tTile><a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>) tTile--;
00531
00532
00533 <font class="comment">// Bilinear across a corner.</font>
00534 CVector2f stTileIn, stIn;
00535 CVector2f stTileOut, stOut;
00536 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchOut;
00537 uint patchId;
00538
00539
00540 <font class="comment">// compute contribution of our patch.</font>
00541 ret = <a class="code" href="classNL3D_1_1CPatch.html#z685_2">computeDisplaceRaw</a>(sTile,tTile, <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>,<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>) * sa * ta;
00542
00543 <font class="comment">// compute contribution of the patch on the left/right side. same reasoning as in computeDisplaceEdgeSmooth();</font>
00544 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00545 stTileIn.set(sTile+smoothBorderX, tTile);
00546 patchId= uvLocatorX.selectPatch(stTileIn);
00547 uvLocatorX.locateUV(stTileIn, patchId, patchOut, stTileOut);
00548 uvLocatorX.locateUV(stIn, patchId, patchOut, stOut);
00549 ret+= patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa1 * ta;
00550
00551
00552 <font class="comment">// compute contribution of the patch on the up/down side. same reasoning as in computeDisplaceEdgeSmooth();</font>
00553 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00554 stTileIn.set(sTile, tTile+smoothBorderY);
00555 patchId= uvLocatorY.selectPatch(stTileIn);
00556 uvLocatorY.locateUV(stTileIn, patchId, patchOut, stTileOut);
00557 uvLocatorY.locateUV(stIn, patchId, patchOut, stOut);
00558 ret+= patchOut->computeDisplaceRaw(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa * ta1;
00559
00560
00561 <font class="comment">/* compute contribution of the patch adjacent to me.</font>
00562 <font class="comment"> There is multiple case to consider here. Take example with corner=0 (ie smBdX=smBdY=-1):</font>
00563 <font class="comment"> - if we are a normal corner with 4 edges, take the result from the left patch of our top patch.</font>
00564 <font class="comment"> - if the corner is on a bind Edge, the top patch may be the bigger patch, so don't take the result</font>
00565 <font class="comment"> from his neighbor (of course).</font>
00566 <font class="comment"> - if we are a normal corner with N!=4 edges, just do same thing than if N==4. this is false but don't bother.</font>
00567 <font class="comment"></font>
00568 <font class="comment"> To solve smoothly cases 1 and 2, use computeDisplaceRawOnNeighbor().</font>
00569 <font class="comment"> This method, if nessecary, look on his neighbor to compute the value.</font>
00570 <font class="comment"> */</font>
00571 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00572 stTileIn.set(sTile+smoothBorderX, tTile+smoothBorderY);
00573 <font class="comment">// look on our "top" patch (this is arbitrary).</font>
00574 patchId= uvLocatorY.selectPatch(stTileIn);
00575 uvLocatorY.locateUV(stTileIn, patchId, patchOut, stTileOut);
00576 uvLocatorY.locateUV(stIn, patchId, patchOut, stOut);
00577 ret+= patchOut->computeDisplaceRawOnNeighbor(stTileOut.x, stTileOut.y, stOut.x, stOut.y) * sa1 * ta1;
00578
00579
00580 <font class="keywordflow">return</font> ret;
00581 }
00582
00583 }
00584
00585 <font class="comment">// ***************************************************************************</font>
<a name="l00586"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_7">00586</a> CVector CPatch::computeNormalEdgeSmooth(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, sint8 smoothBorderX, sint8 smoothBorderY)<font class="keyword"> const</font>
00587 <font class="keyword"></font>{
00588 CBindInfo bindInfo;
00589 uint edge=0;
00590 CBezierPatch *bpatch;
00591 bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
00592
00593 <font class="comment">// only one must be not null</font>
00594 <a class="code" href="debug_8h.html#a6">nlassert</a>( (smoothBorderX==0) != (smoothBorderY==0) );
00595
00596
00597 <font class="comment">// Get the edge against we must share displace.</font>
00598 <font class="keywordflow">if</font>(smoothBorderX==-1) edge=0;
00599 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==1) edge=1;
00600 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderX==1) edge=2;
00601 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==-1) edge=3;
00602 <font class="keywordflow">else</font> <a class="code" href="debug_8h.html#a12">nlstop</a>;
00603
00604 <font class="comment">// If the edge is smoothed, blend with neighbor.</font>
00605 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#a40">getSmoothFlag</a>(edge))
00606 {
00607 <font class="comment">// Build the bindInfo against this edge.</font>
00608 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edge, bindInfo);
00609
00610 <font class="comment">// Fast reject: if no neighbor, just do a simple computeDisplaceInteriorSmooth.</font>
00611 <font class="keywordflow">if</font>(!bindInfo.Zone)
00612 <font class="keywordflow">return</font> bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>());
00613 <font class="keywordflow">else</font>
00614 {
00615 CVector r0, r1;
00616
00617 <font class="comment">// Compute our contribution.</font>
00618 r0= bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>());
00619
00620 <font class="comment">// Compute the coordinate on the border of the edge, and the coef of the blend.</font>
00621 <font class="keywordtype">float</font> se=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00622 <font class="keywordtype">float</font> te=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00623 <font class="keywordtype">float</font> coef=0.0;
00624 <font class="keywordflow">if</font>(smoothBorderX==-1) se= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(se), coef=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>-se;
00625 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderX==1) se= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(se), coef=se-<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00626 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==-1) te= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(te), coef=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>-te;
00627 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==1) te= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(te), coef=te-<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00628 coef= 0.5f + coef*0.5f;
00629
00630 <font class="comment">// Compute contribution of the normal on the neighbor, on the border of the edge.</font>
00631 CPatchUVLocator uvLocator;
00632 CVector2f stIn, stOut;
00633 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchOut;
00634 uint patchId;
00635
00636 uvLocator.build(<font class="keyword">this</font>, edge, bindInfo);
00637 stIn.set(se, te);
00638 patchId= uvLocator.selectPatch(stIn);
00639 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00640
00641 bpatch= patchOut->unpackIntoCache();
00642 r1= bpatch->evalNormal(stOut.x/patchOut->getOrderS(), stOut.y/patchOut->getOrderT());
00643
00644 <font class="comment">// NB: don't bother problems with bind 1/X and the choice of the patch, because bind are C1, so normal is C0.</font>
00645
00646 <font class="comment">// Blend 2 result. For speed optim, don't normalize.</font>
00647 <font class="keywordflow">return</font> r0*coef + r1*(1-coef);
00648 }
00649 }
00650 <font class="comment">// else blend with vector Null.</font>
00651 <font class="keywordflow">else</font>
00652 {
00653 <font class="comment">// compute coef.</font>
00654 <font class="keywordtype">float</font> se=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00655 <font class="keywordtype">float</font> te=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00656 <font class="keywordtype">float</font> coef=0.0;
00657 <font class="keywordflow">if</font>(smoothBorderX==-1) se= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(se), coef=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>-se;
00658 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderX==1) se= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(se), coef=se-<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00659 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==-1) te= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(te), coef=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>-te;
00660 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==1) te= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(te), coef=te-<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00661
00662 <font class="comment">// Compute our contribution.</font>
00663 CVector r0;
00664 r0= bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>());
00665
00666 <font class="comment">// Blend with 0.</font>
00667 <font class="keywordflow">return</font> r0*coef;
00668 }
00669 }
00670
00671
00672 <font class="comment">// ***************************************************************************</font>
<a name="l00673"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_9">00673</a> CVector CPatch::computeNormalOnNeighbor(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, uint edgeExclude)<font class="keyword"> const</font>
00674 <font class="keyword"></font>{
00675 sint edge= -1;
00676
00677 <font class="comment">// look on what neighbor patch we must find the value (if any).</font>
00678 <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a><1 && edgeExclude!=0) edge=0;
00679 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>><a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>-1 && edgeExclude!=1) edge=1;
00680 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>><a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>-1 && edgeExclude!=2) edge=2;
00681 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a><1 && edgeExclude!=3) edge=3;
00682
00683
00684 <font class="comment">// If the location is In the patch, just return normal value. (case of a bind 1/X).</font>
00685 <font class="keywordflow">if</font>(edge==-1)
00686 {
00687 CBezierPatch *bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
00688 <font class="keywordflow">return</font> bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>());
00689 }
00690 <font class="comment">// else must find on neighbor.</font>
00691 <font class="keywordflow">else</font>
00692 {
00693 CBindInfo bindInfo;
00694 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edge, bindInfo);
00695
00696 <font class="comment">// Fast reject: if no neighbor on the edge, just do a simple computeDisplaceRaw()</font>
00697 <font class="keywordflow">if</font>(!bindInfo.Zone)
00698 {
00699 CBezierPatch *bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
00700 <font class="keywordflow">return</font> bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>());
00701 }
00702 <font class="comment">// else must find on neighbor.</font>
00703 <font class="keywordflow">else</font>
00704 {
00705 CPatchUVLocator uvLocator;
00706 uvLocator.build(<font class="keyword">this</font>, edge, bindInfo);
00707
00708 CVector2f stIn;
00709 CVector2f stOut;
00710 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchOut;
00711 uint patchId;
00712
00713 <font class="comment">// look on neighbor. same reasoning as in computeDisplaceEdgeSmooth();</font>
00714 stIn.set(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00715 patchId= uvLocator.selectPatch(stIn);
00716 uvLocator.locateUV(stIn, patchId, patchOut, stOut);
00717 CBezierPatch *bpatch= patchOut->unpackIntoCache();
00718 <font class="keywordflow">return</font> bpatch->evalNormal(stOut.x/patchOut->getOrderS(), stOut.y/patchOut->getOrderT());
00719 }
00720
00721 }
00722 }
00723
00724
00725 <font class="comment">// ***************************************************************************</font>
<a name="l00726"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_8">00726</a> CVector CPatch::computeNormalCornerSmooth(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, sint8 smoothBorderX, sint8 smoothBorderY)<font class="keyword"> const</font>
00727 <font class="keyword"></font>{
00728 CBindInfo bindInfoX;
00729 CBindInfo bindInfoY;
00730 uint edgeX=0;
00731 uint edgeY=0;
00732 uint corner;
00733 CBezierPatch *bpatch;
00734 bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
00735
00736 <font class="comment">// both must be not null</font>
00737 <a class="code" href="debug_8h.html#a6">nlassert</a>( (smoothBorderX!=0) && (smoothBorderY!=0) );
00738
00739
00740 <font class="comment">// Get the edge against we must share displace.</font>
00741 <font class="keywordflow">if</font>(smoothBorderX==-1) edgeX=0;
00742 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderX==1) edgeX=2;
00743 <font class="keywordflow">else</font> <a class="code" href="debug_8h.html#a12">nlstop</a>;
00744 <font class="keywordflow">if</font>(smoothBorderY==1) edgeY=1;
00745 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothBorderY==-1) edgeY=3;
00746 <font class="keywordflow">else</font> <a class="code" href="debug_8h.html#a12">nlstop</a>;
00747
00748 <font class="comment">// Get the corner against we must share displace.</font>
00749 <font class="keywordflow">if</font>(smoothBorderX==-1)
00750 {
00751 <font class="keywordflow">if</font>(smoothBorderY==-1) corner=0;
00752 <font class="keywordflow">else</font> corner=1;
00753 }
00754 <font class="keywordflow">else</font>
00755 {
00756 <font class="keywordflow">if</font>(smoothBorderY==-1) corner=3;
00757 <font class="keywordflow">else</font> corner=2;
00758 }
00759
00760 <font class="comment">// If this corner is smoothed, blend with 4 neighbors patchs.</font>
00761 <font class="keywordflow">if</font>(<a class="code" href="classNL3D_1_1CPatch.html#z668_1">getCornerSmoothFlag</a>(corner))
00762 {
00763 <font class="comment">// Build the bindInfo against the 2 edge.</font>
00764 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edgeX, bindInfoX);
00765 <a class="code" href="classNL3D_1_1CPatch.html#a13">getBindNeighbor</a>(edgeY, bindInfoY);
00766
00767 <font class="comment">// Fast reject: if no neighbor, just do a simple computeDisplaceInteriorSmooth.</font>
00768 <font class="keywordflow">if</font>(!bindInfoX.Zone || !bindInfoY.Zone)
00769 <font class="keywordflow">return</font> bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>());
00770 <font class="keywordflow">else</font>
00771 {
00772 CVector ret;
00773
00774
00775 <font class="comment">// Compute the coordinate on the border of the edge, and the coef of the blend.</font>
00776 <font class="keywordtype">float</font> se=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00777 <font class="keywordtype">float</font> te=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00778 <font class="keywordtype">float</font> coefX;
00779 <font class="keywordtype">float</font> coefY;
00780 <font class="keywordflow">if</font>(smoothBorderX==-1) se= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(se), coefX=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>-se;
00781 <font class="keywordflow">else</font> se= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(se), coefX=se-<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00782 <font class="keywordflow">if</font>(smoothBorderY==-1) te= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(te), coefY=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>-te;
00783 <font class="keywordflow">else</font> te= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(te), coefY=te-<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00784 coefX= 0.5f + coefX*0.5f;
00785 coefY= 0.5f + coefY*0.5f;
00786
00787
00788 <font class="comment">// Compute our contribution.</font>
00789 ret= bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>/<a class="code" href="classNL3D_1_1CPatch.html#a6">getOrderS</a>(), <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>/<a class="code" href="classNL3D_1_1CPatch.html#a7">getOrderT</a>()) *coefX*coefY;
00790
00791
00792 <font class="comment">// compute Neighboring info.</font>
00793 CPatchUVLocator uvLocatorX;
00794 CPatchUVLocator uvLocatorY;
00795 CVector2f stIn, stOut;
00796 <a class="code" href="classNL3D_1_1CPatch.html#a0">CPatch</a> *patchOut;
00797 uint patchId;
00798
00799 uvLocatorX.build(<font class="keyword">this</font>, edgeX, bindInfoX);
00800 uvLocatorY.build(<font class="keyword">this</font>, edgeY, bindInfoY);
00801
00802 <font class="comment">// Patch on our X side.</font>
00803 stIn.set(se, te);
00804 patchId= uvLocatorX.selectPatch(stIn);
00805 uvLocatorX.locateUV(stIn, patchId, patchOut, stOut);
00806 bpatch= patchOut->unpackIntoCache();
00807 ret+= bpatch->evalNormal(stOut.x/patchOut->getOrderS(), stOut.y/patchOut->getOrderT()) *(1-coefX)*coefY;
00808
00809 <font class="comment">// Patch on our Y side.</font>
00810 stIn.set(se, te);
00811 patchId= uvLocatorY.selectPatch(stIn);
00812 uvLocatorY.locateUV(stIn, patchId, patchOut, stOut);
00813 bpatch= patchOut->unpackIntoCache();
00814 ret+= bpatch->evalNormal(stOut.x/patchOut->getOrderS(), stOut.y/patchOut->getOrderT()) *coefX*(1-coefY);
00815
00816 <font class="comment">/* compute contribution of the patch adjacent to me.</font>
00817 <font class="comment"> Same reasoning as in computeDisplaceCornerSmooth().</font>
00818 <font class="comment"> */</font>
00819 stIn.set(se, te);
00820 patchId= uvLocatorY.selectPatch(stIn);
00821 uvLocatorY.locateUV(stIn, patchId, patchOut, stOut);
00822 <font class="comment">// Because we compute the normal exactly on the edge, we must inform this method not to take us as neighbor.</font>
00823 <font class="comment">// ugly but simpler.</font>
00824 ret+= patchOut->computeNormalOnNeighbor(stOut.x, stOut.y, bindInfoY.Edge[patchId]) *(1-coefX)*(1-coefY);
00825
00826 <font class="keywordflow">return</font> ret;
00827 }
00828 }
00829 <font class="comment">// else must blend with 0.</font>
00830 <font class="keywordflow">else</font>
00831 {
00832 <font class="comment">// compute coef.</font>
00833 <font class="keywordtype">float</font> se=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00834 <font class="keywordtype">float</font> te=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00835 <font class="keywordtype">float</font> coefX;
00836 <font class="keywordtype">float</font> coefY;
00837 <font class="keywordflow">if</font>(smoothBorderX==-1) se= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(se), coefX=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>-se;
00838 <font class="keywordflow">else</font> se= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(se), coefX=se-<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>;
00839 <font class="keywordflow">if</font>(smoothBorderY==-1) te= <a class="code" href="namespaceNL3D.html#a391">noiseFloorF</a>(te), coefY=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>-te;
00840 <font class="keywordflow">else</font> te= <a class="code" href="namespaceNL3D.html#a392">noiseCeilF</a>(te), coefY=te-<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>;
00841
00842
00843 <font class="comment">// To have smooth continuities with smooth on edge (if any), we must do this.</font>
00844 CVector rx, ry;
00845 <font class="comment">// Compute a smooth with my X neighbor.</font>
00846 rx= <a class="code" href="classNL3D_1_1CPatch.html#z685_7">computeNormalEdgeSmooth</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, smoothBorderX, 0);
00847 <font class="comment">// Compute a smooth with my Y neighbor.</font>
00848 ry= <a class="code" href="classNL3D_1_1CPatch.html#z685_7">computeNormalEdgeSmooth</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, 0, smoothBorderY);
00849
00850 <font class="comment">// Blend the 2 result.</font>
00851 <font class="keywordflow">if</font>(coefY + coefX>0)
00852 {
00853 <font class="comment">// This the weight used to blend to 0.</font>
00854 <font class="keywordtype">float</font> maxCoef= max(coefY, coefX);
00855 <font class="comment">// This the weight used to blend beetween rx and ry.</font>
00856 <font class="keywordtype">float</font> ooSum= 1.0f / (coefY + coefX);
00857 <font class="keywordtype">float</font> blendCoefX= coefX * ooSum;
00858 <font class="keywordtype">float</font> blendCoefY= coefY * ooSum;
00859
00860 <font class="keywordflow">return</font> maxCoef* (rx*blendCoefY + ry*blendCoefX);
00861 }
00862 <font class="keywordflow">else</font>
00863 {
00864 <font class="keywordflow">return</font> CVector::Null;
00865 }
00866 }
00867 }
00868
00869
00870
00871 <font class="comment">// ***************************************************************************</font>
<a name="l00872"></a><a class="code" href="classNL3D_1_1CPatch.html#z685_10">00872</a> <font class="keywordtype">void</font> CPatch::computeNoise(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, CVector &displace)<font class="keyword"> const</font>
00873 <font class="keyword"></font>{
00874 <font class="keywordtype">float</font> so= <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>*<a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>;
00875 <font class="keywordtype">float</font> to= <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*<a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>;
00876
00877
00878 <font class="comment">// Pre-Compute Border Smothing.</font>
00879 <font class="comment">//=========================</font>
00880 <font class="comment">// If we are on a border, flag it.</font>
00881 sint8 smoothNormalBorderX= 0;
00882 sint8 smoothNormalBorderY= 0;
00883 <font class="comment">// NB: because OrderS and OrderT >=2, smoothNormalBorderX=-1 and smoothNormalBorderX=1 are exclusive (as smoothNormalBorderY).</font>
00884 <font class="keywordflow">if</font>(so < 1) smoothNormalBorderX= -1;
00885 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(so > <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>-1) smoothNormalBorderX= 1;
00886 <font class="keywordflow">if</font>(to < 1) smoothNormalBorderY= -1;
00887 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(to > <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>-1) smoothNormalBorderY= 1;
00888
00889 <font class="keywordtype">bool</font> smoothNormalEdge= (smoothNormalBorderX!=0) != (smoothNormalBorderY!=0);
00890 <font class="keywordtype">bool</font> smoothNormalCorner= (smoothNormalBorderX!=0) && (smoothNormalBorderY!=0);
00891
00892
00893 <font class="comment">// Do same thing, but to know if we must compute a displace on an interior, on an edge or on a corner.</font>
00894 sint8 smoothDisplaceBorderX= 0;
00895 sint8 smoothDisplaceBorderY= 0;
00896 <font class="comment">// NB: because OrderS and OrderT >=2, smoothBorderX=-1 and smoothBorderX=1 are exclusive (as smoothBorderY).</font>
00897 <font class="keywordflow">if</font>(so < 0.5) smoothDisplaceBorderX= -1;
00898 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(so > <a class="code" href="classNL3D_1_1CPatch.html#o2">OrderS</a>-0.5) smoothDisplaceBorderX= 1;
00899 <font class="keywordflow">if</font>(to < 0.5) smoothDisplaceBorderY= -1;
00900 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(to > <a class="code" href="classNL3D_1_1CPatch.html#o3">OrderT</a>-0.5) smoothDisplaceBorderY= 1;
00901
00902 <font class="keywordtype">bool</font> smoothDisplaceEdge= (smoothDisplaceBorderX!=0) != (smoothDisplaceBorderY!=0);
00903 <font class="keywordtype">bool</font> smoothDisplaceCorner= (smoothDisplaceBorderX!=0) && (smoothDisplaceBorderY!=0);
00904
00905
00906 <font class="comment">// Compute Displace value.</font>
00907 <font class="comment">//=========================</font>
00908 <font class="keywordtype">float</font> displaceValue;
00909
00910 <font class="keywordflow">if</font>(smoothDisplaceCorner)
00911 displaceValue= <a class="code" href="classNL3D_1_1CPatch.html#z685_6">computeDisplaceCornerSmooth</a>(so, to, smoothDisplaceBorderX, smoothDisplaceBorderY);
00912 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothDisplaceEdge)
00913 displaceValue= <a class="code" href="classNL3D_1_1CPatch.html#z685_5">computeDisplaceEdgeSmooth</a>(so, to, smoothDisplaceBorderX, smoothDisplaceBorderY);
00914 <font class="keywordflow">else</font>
00915 displaceValue= <a class="code" href="classNL3D_1_1CPatch.html#z685_4">computeDisplaceInteriorSmooth</a>(so, to);
00916
00917
00918
00919 <font class="comment">// Compute Displace normal.</font>
00920 <font class="comment">//=========================</font>
00921
00922 <font class="comment">// Evaluate the normal.</font>
00923 CVector displaceNormal;
00924
00925
00926 <font class="comment">// smooth on edges and on corners.</font>
00927 <font class="keywordflow">if</font>(smoothNormalCorner)
00928 displaceNormal= <a class="code" href="classNL3D_1_1CPatch.html#z685_8">computeNormalCornerSmooth</a>(so, to, smoothNormalBorderX, smoothNormalBorderY);
00929 <font class="keywordflow">else</font> <font class="keywordflow">if</font>(smoothNormalEdge)
00930 displaceNormal= <a class="code" href="classNL3D_1_1CPatch.html#z685_7">computeNormalEdgeSmooth</a>(so, to, smoothNormalBorderX, smoothNormalBorderY);
00931 <font class="keywordflow">else</font>
00932 {
00933 <font class="comment">// unpack...</font>
00934 CBezierPatch *bpatch= <a class="code" href="classNL3D_1_1CPatch.html#a45">unpackIntoCache</a>();
00935 <font class="comment">// eval.</font>
00936 displaceNormal= bpatch->evalNormal(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>);
00937 }
00938
00939
00940
00941 <font class="comment">// Final result.</font>
00942 <font class="comment">//=========================</font>
00943 displace= displaceNormal * displaceValue;
00944 }
00945
00946
00947
00948 <font class="comment">// ***************************************************************************</font>
<a name="l00949"></a><a class="code" href="classNL3D_1_1CPatch.html#z668_0">00949</a> <font class="keywordtype">void</font> CPatch::setCornerSmoothFlag(uint corner, <font class="keywordtype">bool</font> smooth)
00950 {
00951 <a class="code" href="debug_8h.html#a6">nlassert</a>(corner<=3);
00952 uint mask= 1<<corner;
00953 <font class="keywordflow">if</font>(smooth)
00954 <a class="code" href="classNL3D_1_1CPatch.html#z668_3">_CornerSmoothFlag</a>|= mask;
00955 <font class="keywordflow">else</font>
00956 <a class="code" href="classNL3D_1_1CPatch.html#z668_3">_CornerSmoothFlag</a>&= ~mask;
00957 }
00958
00959 <font class="comment">// ***************************************************************************</font>
<a name="l00960"></a><a class="code" href="classNL3D_1_1CPatch.html#z668_1">00960</a> <font class="keywordtype">bool</font> CPatch::getCornerSmoothFlag(uint corner)<font class="keyword"> const</font>
00961 <font class="keyword"></font>{
00962 <a class="code" href="debug_8h.html#a6">nlassert</a>(corner<=3);
00963 uint mask= 1<<corner;
00964 <font class="keywordflow">return</font> (<a class="code" href="classNL3D_1_1CPatch.html#z668_3">_CornerSmoothFlag</a>& mask)!=0;
00965 }
00966
00967
00968 } <font class="comment">// NL3D</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|