aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/zone__lighter_8cpp-source.html
blob: 7c3d73fc72d7fc32e6e92254a39dec2c8e9ba0a6 (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
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
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
<!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>zone_lighter.cpp</h1><a href="zone__lighter_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 <font class="preprocessor">#include "<a class="code" href="zone__lighter_8h.html">3d/zone_lighter.h</a>"</font>
00029 <font class="preprocessor">#include "<a class="code" href="landscape_8h.html">3d/landscape.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="patchuv__locator_8h.html">3d/patchuv_locator.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="shape_8h.html">3d/shape.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="mesh_8h.html">3d/mesh.h</a>"</font>
00033 <font class="preprocessor">#include "<a class="code" href="mesh__multi__lod_8h.html">3d/mesh_multi_lod.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="mesh__mrm_8h.html">3d/mesh_mrm.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="transform__shape_8h.html">3d/transform_shape.h</a>"</font>
00036 <font class="preprocessor">#include "<a class="code" href="water__shape_8h.html">3d/water_shape.h</a>"</font>
00037 <font class="preprocessor">#include "<a class="code" href="texture__file_8h.html">3d/texture_file.h</a>"</font>
00038 
00039 
00040 
00041 
00042 
00043 <font class="preprocessor">#include "<a class="code" href="common_8h.html">nel/misc/common.h</a>"</font>
00044 <font class="preprocessor">#include "<a class="code" href="thread_8h.html">nel/misc/thread.h</a>"</font>
00045 <font class="preprocessor">#include "<a class="code" href="path_8h.html">nel/misc/path.h</a>"</font>
00046 <font class="preprocessor">#include "<a class="code" href="file_8h.html">nel/misc/file.h</a>"</font>
00047 <font class="preprocessor">#include "<a class="code" href="aabbox_8h.html">nel/misc/aabbox.h</a>"</font>
00048 
00049 
00050 <font class="comment">// Define this to use hardware soft shadows</font>
00051 <font class="comment">//#define HARDWARE_SOFT_SHADOWS</font>
00052 
00053 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
00054 <font class="preprocessor"></font>
00055 <font class="preprocessor">#include "<a class="code" href="u__driver_8h.html">nel/3d/u_driver.h</a>"</font>
00056 
00057 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
00058 <font class="preprocessor"></font>
00059 
00060 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00061 <font class="preprocessor"></font><font class="preprocessor">#  define WIN32_LEAN_AND_MEAN</font>
00062 <font class="preprocessor"></font><font class="preprocessor">#  include "windows.h"</font>
00063 <font class="preprocessor">#  include "winbase.h"</font>
00064 <font class="preprocessor">#  ifdef min</font>
00065 <font class="preprocessor"></font><font class="preprocessor">#    undef min</font>
00066 <font class="preprocessor"></font><font class="preprocessor">#  endif</font>
00067 <font class="preprocessor"></font><font class="preprocessor">#  ifdef max</font>
00068 <font class="preprocessor"></font><font class="preprocessor">#    undef max</font>
00069 <font class="preprocessor"></font><font class="preprocessor">#  endif</font>
00070 <font class="preprocessor"></font><font class="preprocessor">#endif // NL_OS_WINDOWS</font>
00071 <font class="preprocessor"></font>
00072 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00073 <font class="keyword">using</font> <font class="keyword">namespace </font>NL3D;
00074 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00075 
00076 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
00077 <font class="preprocessor"></font>
00078 UDriver *drv=NULL;
00079 
00080 <font class="preprocessor">#define LIGHT_BUFFER_SIZE 16</font>
00081 <font class="preprocessor"></font>
00082 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
00083 <font class="preprocessor"></font>        
00084 
00085 <font class="comment">// Bad coded: don't set too big else it allocates too much memory.</font>
<a name="l00086"></a><a class="code" href="zone__lighter_8cpp.html#a0">00086</a> <font class="preprocessor">#define NL3D_ZONE_LIGHTER_CUBE_GRID_SIZE 16</font>
00087 <font class="preprocessor"></font>
00088 
00089 <font class="comment">// ***************************************************************************</font>
00090 
00091 
<a name="l00092"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a0">00092</a> CZoneLighter::CZoneLighter () : _PatchComputed ("PatchComputed"), _TriangleListAllocateur(100000)
00093 {
00094         
00095 }
00096         
00097 <font class="comment">// ***************************************************************************</font>
00098 
<a name="l00099"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a2">00099</a> <font class="keywordtype">void</font> CZoneLighter::init ()
00100 {
00101         <font class="comment">// Precalc some values</font>
00102         <font class="keywordflow">for</font> (uint i=0; i&lt;8; i++)
00103         {
00104                 <font class="comment">// Precalc sinP and cosP</font>
00105                 <font class="keywordtype">float</font> sinP=(float)(sin((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i+0.5))-sin((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i-0.5)));
00106                 <font class="keywordtype">float</font> cosP=(float)(cos((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i-0.5))-cos((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*(i+0.5)));
00107 
00108                 <font class="keywordflow">for</font> (uint phi=0; phi&lt;256; phi++)
00109                 {
00110                         <font class="comment">// Real phi</font>
00111                         <font class="keywordtype">float</font> fPhi=(float)((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2)*phi/256.0);
00112 
00113                         <font class="comment">// Tmp result</font>
00114                         <font class="keywordtype">float</font> tmp0=(float)(fPhi-sin(2*fPhi)/2);
00115                         <font class="keywordtype">float</font> tmp1=(float)sin(fPhi);
00116 
00117                         <font class="comment">// Calc K</font>
00118                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o37">_K</a>[phi][i].<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a> (tmp0*sinP, tmp0*cosP, (<font class="keywordtype">float</font>)((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/4)*tmp1*tmp1));
00119                 }
00120         }
00121 
00122 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
00123 <font class="preprocessor"></font>        <font class="keywordflow">if</font> (!drv)
00124         {
00125                 <font class="comment">// Mode</font>
00126                 UDriver::CMode mode (LIGHT_BUFFER_SIZE, LIGHT_BUFFER_SIZE, 32, <font class="keyword">true</font>);
00127                 drv=UDriver::createDriver ();
00128                 drv-&gt;setDisplay (mode);
00129                 drv-&gt;setMatrixMode2D11 ();
00130         }
00131 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
00132 <font class="preprocessor"></font>}
00133 
00134 <font class="comment">// ***************************************************************************</font>
00135 
00136 <font class="comment">// N - NW - W - SW - S - SE - E - NE</font>
<a name="l00137"></a><a class="code" href="zone__lighter_8cpp.html#a5">00137</a> <font class="keyword">static</font> <font class="keyword">const</font> sint <a class="code" href="zone__lighter_8cpp.html#a5">deltaDirection</a>[8][2]=
00138 {
00139         {1, 0},
00140         {1, 1},
00141         {0, 1},
00142         {-1, 1},
00143         {-1, 0},
00144         {-1, -1},
00145         {0, -1},
00146         {1, -1},
00147 };
00148 
00149 <font class="comment">// ***************************************************************************</font>
00150 
<a name="l00151"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c6">00151</a> <font class="keywordtype">float</font> CZoneLighter::calcSkyContribution (sint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, sint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, <font class="keywordtype">float</font> skyIntensity, <font class="keyword">const</font> CVector&amp; normal)<font class="keyword"> const</font>
00152 <font class="keyword"></font>{
00153         <font class="comment">// Sky contribution</font>
00154         <font class="keywordtype">float</font> skyContribution;
00155 
00156         <font class="comment">// Calc k</font>
00157         CVector k (0, 0, 0);
00158 
00159         <font class="comment">// For the height direction</font>
00160         <font class="keywordflow">for</font> (uint i=0; i&lt;8; i++)
00161         {
00162                 <font class="comment">// Get phi for this point</font>
00163                 uint8 phi=<a class="code" href="classNL3D_1_1CZoneLighter.html#c8">getMaxPhi</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>, <a class="code" href="zone__lighter_8cpp.html#a5">deltaDirection</a>[i][0], <a class="code" href="zone__lighter_8cpp.html#a5">deltaDirection</a>[i][1], <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
00164 
00165                 <font class="comment">// Add to k</font>
00166                 k+=<a class="code" href="classNL3D_1_1CZoneLighter.html#o37">_K</a>[phi][i];
00167         }
00168 
00169         <font class="comment">// Finalize sky contribution</font>
00170         skyContribution=(float)(skyIntensity*(normal*k)/(2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>));
00171         <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (skyContribution, 0.f, 1.f);
00172         <font class="keywordflow">return</font> skyContribution;
00173 }
00174 
00175 <font class="comment">// ***************************************************************************</font>
00176 
<a name="l00177"></a><a class="code" href="zone__lighter_8cpp.html#a7">00177</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNL3D.html#a369">NEL3DCalcBase</a> (CVector &amp;direction, CMatrix&amp; <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>)
00178 {
00179         direction.normalize();
00180         CVector         I=(fabs(direction*CVector(1.f,0,0))&gt;0.99)?CVector(0.f,1.f,0.f):CVector(1.f,0.f,0.f);
00181         CVector         K=-direction;
00182         CVector         J=K^I;
00183         J.normalize();
00184         I=J^K;
00185         I.normalize();
00186         <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>.identity();
00187         <a class="code" href="driver__opengl__extension__def_8h.html#a370">matrix</a>.setRot(I,J,K, <font class="keyword">true</font>);
00188 }
00189 
00190 <font class="comment">// ***************************************************************************</font>
00191 
<a name="l00192"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html">00192</a> <font class="keyword">class </font>NL3D::CCalcRunnable : <font class="keyword">public</font> IRunnable
00193 {
00194         <font class="comment">// Members</font>
<a name="l00195"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#o0">00195</a>         uint                    _Process;
<a name="l00196"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#o1">00196</a>         CZoneLighter    *_ZoneLighter;
<a name="l00197"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#o2">00197</a>         <font class="keyword">const</font> CZoneLighter::CLightDesc  *_Description;
00198 
00199 <font class="keyword">public</font>:
<a name="l00200"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#m0">00200</a>         IThread                 *Thread;
00201 
00202 <font class="keyword">public</font>:
00203         <font class="comment">// Ctor</font>
<a name="l00204"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#a0">00204</a>         CCalcRunnable (uint process, CZoneLighter *zoneLighter, <font class="keyword">const</font> CZoneLighter::CLightDesc *description)
00205         {
00206                 _ZoneLighter = zoneLighter;
00207                 _Process = process;
00208                 _Description = description;
00209         }
00210 
00211         <font class="comment">// Run method</font>
<a name="l00212"></a><a class="code" href="classNL3D_1_1CCalcRunnable.html#a1">00212</a>         <font class="keywordtype">void</font> run()
00213         {
00214                 <font class="comment">// Set the processor mask</font>
00215                 uint64 mask = IProcess::getCurrentProcess()-&gt;getCPUMask ();
00216 
00217                 <font class="comment">// Mask must not be NULL</font>
00218                 <a class="code" href="debug_8h.html#a6">nlassert</a> (mask != 0);
00219 
00220                 <font class="keywordflow">if</font> (mask != 0)
00221                 {
00222                         uint i=0;
00223                         uint count = 0;
00224                         <font class="keywordflow">while</font> (1)
00225                         {
00226                                 <font class="keywordflow">if</font> (mask &amp; (1&lt;&lt;i))
00227                                 {
00228                                         <font class="keywordflow">if</font> (count == _Process)
00229                                                 <font class="keywordflow">break</font>;
00230                                         count++;
00231                                 }
00232                                 i++;
00233                                 <font class="keywordflow">if</font> (i==64)
00234                                         i = 0;
00235                         }
00236                         
00237                         <font class="comment">// Set the CPU mask</font>
00238                         Thread-&gt;setCPUMask (1&lt;&lt;i);
00239                 }
00240 
00241                 _ZoneLighter-&gt;processCalc (_Process, *_Description);
00242                 _ZoneLighter-&gt;_ProcessExited++;
00243         }
00244 };
00245 
00246 
00247 <font class="comment">// ***************************************************************************</font>
<a name="l00248"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html">00248</a> <font class="keyword">class </font>NL3D::CCalcLightableShapeRunnable : <font class="keyword">public</font> IRunnable
00249 {
00250 <font class="keyword">public</font>:
<a name="l00251"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#a0">00251</a>         CCalcLightableShapeRunnable(uint process,
00252                                                                 CZoneLighter *zoneLighter,
00253                                                                 <font class="keyword">const</font> CZoneLighter::CLightDesc *description,
00254                                                                 CZoneLighter::TShapeVect *shapeToLit,
00255                                                                 uint firstShape,
00256                                                                 uint lastShape
00257                                                                 )
00258                 : 
00259                   _ZoneLighter(zoneLighter), 
00260                   _Description(description),
00261                   _ShapesToLit(shapeToLit),
00262                   _FirstShape(firstShape),
00263                   _LastShape(lastShape),
00264                   _Process(process)
00265         {
00266         }
<a name="l00267"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#a1">00267</a>         <font class="keywordtype">void</font> run()
00268         {
00269                 _ZoneLighter-&gt;processLightableShapeCalc(_Process, _ShapesToLit, _FirstShape, _LastShape, *_Description);
00270                 _ZoneLighter-&gt;_ProcessExited++;
00271         }
00272 <font class="keyword">private</font>:
<a name="l00273"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o0">00273</a>         CZoneLighter                                            *_ZoneLighter;
<a name="l00274"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o1">00274</a>         <font class="keyword">const</font> CZoneLighter::CLightDesc          *_Description;
<a name="l00275"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o2">00275</a>         CZoneLighter::TShapeVect        *_ShapesToLit;
<a name="l00276"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o4">00276</a>         uint                                                            _FirstShape, _LastShape;
<a name="l00277"></a><a class="code" href="classNL3D_1_1CCalcLightableShapeRunnable.html#o5">00277</a>         uint                                                            _Process;
00278 
00279 };
00280 
00281 <font class="comment">// ***************************************************************************</font>
00282 
<a name="l00283"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a3">00283</a> <font class="keywordtype">void</font> CZoneLighter::light (CLandscape &amp;landscape, CZone&amp; output, uint zoneToLight, <font class="keyword">const</font> CLightDesc&amp; description, std::vector&lt;CTriangle&gt;&amp; obstacles, vector&lt;uint&gt; &amp;listZone)
00284 {
00285         <font class="comment">/*</font>
00286 <font class="comment">         * Lighting algorithm</font>
00287 <font class="comment">         * ------------------</font>
00288 <font class="comment">         *</font>
00289 <font class="comment">         * - Create a quad grid to store shadow casting triangles</font>
00290 <font class="comment">         * - Create a heightfield used for global illumination. Cells are initialized with -FLT_MAX</font>
00291 <font class="comment">         * - Insert each shadow casting triangles in the quad grid and fill the heightfield's cells overlapped by the bounding box of the triangle with</font>
00292 <font class="comment">         * the max height of the triangle if its height is &gt; than the current height in the heightfield's cell.</font>
00293 <font class="comment">         * - </font>
00294 <font class="comment">         */</font>
00295 
00296         <font class="comment">// Backup thread mask</font>
00297         IThread *currentThread = IThread::getCurrentThread ();
00298         uint64 threadMask = currentThread-&gt;getCPUMask();
00299         currentThread-&gt;setCPUMask (1);
00300 
00301         <font class="comment">// Calc the ray basis</font>
00302         <a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>=description.LightDirection;
00303         <a class="code" href="zone__lighter_8cpp.html#a7">NEL3DCalcBase</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>, <a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>);
00304 
00305         <font class="comment">// Zone to light</font>
00306         <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>=zoneToLight;
00307 
00308         <font class="comment">// Landscape </font>
00309         <a class="code" href="classNL3D_1_1CZoneLighter.html#o5">_Landscape</a>=&amp;landscape;
00310 
00311         <font class="comment">// Process count</font>
00312         <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>=description.NumCPU;
00313         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>==0)
00314         {
00315                 <font class="comment">// Create a doomy thread</font>
00316                 IProcess *pProcess=IProcess::getCurrentProcess ();
00317                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o13">_CPUMask</a> = pProcess-&gt;getCPUMask();
00318                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a> = 0;
00319                 uint64 i;
00320                 <font class="keywordflow">for</font> (i=0; i&lt;64; i++)
00321                 {
00322                         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o13">_CPUMask</a>&amp;((uint64)1&lt;&lt;i))
00323                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>++;
00324                 }
00325         }
00326         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>&gt;<a class="code" href="zone__lighter_8h.html#a2">MAX_CPU_PROCESS</a>)
00327                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>=<a class="code" href="zone__lighter_8h.html#a2">MAX_CPU_PROCESS</a>;
00328 
00329         <font class="comment">// Number of CPUS used</font>
00330         printf (<font class="stringliteral">"Number of CPU used: %d\n"</font>, <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>);
00331 
00332         <font class="comment">// Fallof distance</font>
00333         <a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>=description.SoftshadowFallof;
00334 
00335         <font class="comment">// Shadow bias</font>
00336         <a class="code" href="classNL3D_1_1CZoneLighter.html#o6">_ShadowBias</a>=description.ShadowBias;
00337 
00338         <font class="comment">// Resize the shape array</font>
00339         <a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>=description.SoftshadowShapeVertexCount;
00340 
00341         <font class="comment">// Softshadow ?</font>
00342         <a class="code" href="classNL3D_1_1CZoneLighter.html#o7">_Softshadow</a>=description.Softshadow;
00343 
00344         <font class="comment">// Radius of the shape</font>
00345         <a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>=description.SoftshadowBlurSize;
00346         <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>.<a class="code" href="classNLMISC_1_1CMatrix.html#z291_7">getI</a>();
00347         <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>+=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>.<a class="code" href="classNLMISC_1_1CMatrix.html#z291_8">getJ</a>();
00348         <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>.<a class="code" href="classNLMISC_1_1CVector.html#z331_4">normalize</a>();
00349         <a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>*=1.5f*<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>;
00350         
00351         <font class="comment">// Build the shape</font>
00352         uint i;
00353         <font class="keywordflow">for</font> (i=0; i&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>; i++)
00354         {
00355                 <font class="comment">// Shape is a smapled circle</font>
00356                 <font class="keywordtype">float</font> angle=(float)((float)i*2*<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>);
00357                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[i]=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>*CVector (<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>*(<font class="keywordtype">float</font>)cos (angle), <a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>*(<font class="keywordtype">float</font>)sin (angle), 0);
00358         }
00359 
00360         <font class="comment">// Calculate the area of the shape</font>
00361         <a class="code" href="classNL3D_1_1CZoneLighter.html#o16">_ShapeArea</a>=0;
00362         <font class="keywordflow">for</font> (i=0; i&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>; i++)
00363         {
00364                 <font class="comment">// Sum area of each triangle</font>
00365                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o16">_ShapeArea</a>+=(<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[i]^<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[(i+1)%<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m0">NumVertex</a>]).norm();
00366         }
00367 
00368         <font class="comment">// Zone pointer</font>
00369         CZone *pZone=landscape.getZone (<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>);
00370         <font class="keywordflow">if</font> (pZone)
00371         {
00372                 <font class="comment">// Change the quadGrid basis</font>
00373                 CMatrix invRayBasis=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>;
00374                 invRayBasis.<a class="code" href="classNLMISC_1_1CMatrix.html#z293_6">invert</a> ();
00375 
00376                 uint cpu;
00377                 <font class="keywordflow">for</font> (cpu=0; cpu&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; cpu++)
00378                 {
00379                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].changeBase (invRayBasis);
00380 
00381                         <font class="comment">// Init the quadGrid</font>
00382                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].create (description.GridSize, description.GridCellSize);
00383                 }
00384                 
00385                 <font class="comment">// Init the heightfield</font>
00386                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>=description.HeightfieldCellSize;
00387                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>=(sint)(description.HeightfieldSize/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>);
00388                 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>!=0);
00389                 <font class="keyword">const</font> CAABBoxExt &amp;zoneBB=pZone-&gt;getZoneBB();
00390                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>=zoneBB.getCenter ()-CVector (description.HeightfieldSize/2, description.HeightfieldSize/2, 0);
00391                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>.resize (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>, -FLT_MAX);
00392 
00393                 <font class="comment">// Fill the quadGrid and the heightField</font>
00394                 uint size=obstacles.size();
00395                 <font class="keywordflow">for</font> (uint triangleId=0; triangleId&lt;size; triangleId++)
00396                 {
00397                         <font class="comment">// Progress bar</font>
00398                         <font class="keywordflow">if</font> ( (triangleId&amp;0xff) == 0)
00399                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Build quadtree and heightfield"</font>, (<font class="keywordtype">float</font>)triangleId/(<font class="keywordtype">float</font>)size);
00400 
00401                         <font class="comment">// Triangle ref</font>
00402                         CZoneLighter::CTriangle&amp; triangle=obstacles[triangleId];
00403 
00404                         <font class="comment">// Calc the plane</font>
00405                         triangle.Plane.make (triangle.Triangle.V0, triangle.Triangle.V1, triangle.Triangle.V2);
00406 
00407                         <font class="comment">// Calc the clipping plane</font>
00408                         CVector edgeDirection[3];
00409                         CVector point[3];
00410                         point[0]=triangle.Triangle.V0;
00411                         edgeDirection[0]=triangle.Triangle.V1-triangle.Triangle.V0;
00412                         point[1]=triangle.Triangle.V1;
00413                         edgeDirection[1]=triangle.Triangle.V2-triangle.Triangle.V1;
00414                         point[2]=triangle.Triangle.V2;
00415                         edgeDirection[2]=triangle.Triangle.V0-triangle.Triangle.V2;
00416                         
00417                         <font class="comment">// Flip plane ?</font>
00418                         <font class="keywordtype">bool</font> flip=((triangle.Plane.getNormal()*(-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>))&lt;0);
00419 
00420                         <font class="comment">// For each plane</font>
00421                         <font class="keywordflow">for</font> (uint edge=0; edge&lt;3; edge++)
00422                         {
00423                                 <font class="comment">// Plane normal</font>
00424                                 edgeDirection[edge]=edgeDirection[edge]^(-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>);
00425                                 edgeDirection[edge].normalize();
00426                                 <font class="keywordflow">if</font> (flip)
00427                                         edgeDirection[edge]=-edgeDirection[edge];
00428 
00429                                 <font class="comment">// Make a plane</font>
00430                                 triangle.ClippingPlanes[edge].make (edgeDirection[edge], point[edge]);
00431                         }
00432 
00433                         <font class="comment">// Look for the min coordinate, in the RayBasis</font>
00434                         CVector irbMinv;
00435                         CVector         irbV0= invRayBasis * triangle.Triangle.V0;
00436                         CVector         irbV1= invRayBasis * triangle.Triangle.V1;
00437                         CVector         irbV2= invRayBasis * triangle.Triangle.V2;
00438                         irbMinv.minof (irbV0, irbV1);
00439                         irbMinv.minof (irbMinv, irbV2);
00440 
00441                         <font class="comment">// Look for the max coordinate, in the RayBasis</font>
00442                         CVector irbMaxv;
00443                         irbMaxv.maxof (irbV0, irbV1);
00444                         irbMaxv.maxof (irbMaxv, irbV2);
00445 
00446                         <font class="comment">// Insert in the quad grid</font>
00447                         <font class="keywordflow">for</font> (cpu=0; cpu&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; cpu++)
00448                                 <font class="comment">// Set the coord in World Basis.</font>
00449                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].insert (<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a> * irbMinv, <a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a> * irbMaxv, &amp;triangle);
00450 
00451 
00452                         <font class="comment">// Look for the min coordinate, in World Basis</font>
00453                         CVector minv;
00454                         minv.minof (triangle.Triangle.V0, triangle.Triangle.V1);
00455                         minv.minof (minv, triangle.Triangle.V2);
00456 
00457                         <font class="comment">// Look for the max coordinate, in World Basis</font>
00458                         CVector maxv;
00459                         maxv.maxof (triangle.Triangle.V0, triangle.Triangle.V1);
00460                         maxv.maxof (maxv, triangle.Triangle.V2);
00461 
00462 
00463                         <font class="comment">// Lanscape tri ?</font>
00464                         <font class="keywordflow">if</font> (triangle.ZoneId!=0xffffffff)
00465                         {
00466                                 <font class="comment">// Fill the heightfield</font>
00467                                 sint minX=std::max (0, (sint)floor (0.5f+(minv.x-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>));
00468                                 sint maxX=<a class="code" href="bit__set_8cpp.html#a0">std::min</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>, (sint)floor (0.5f+(maxv.x-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>));
00469                                 sint minY=std::max (0, (sint)floor (0.5f+(minv.y-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>));
00470                                 sint maxY=<a class="code" href="bit__set_8cpp.html#a0">std::min</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>, (sint)floor (0.5f+(maxv.y-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>));
00471 
00472                                 <font class="comment">// Calc position in the heightfield</font>
00473                                 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>=minY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>&lt;maxY; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
00474                                 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>=minX; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>&lt;maxX; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
00475                                 {
00476                                         <font class="comment">// Valid position, try to insert it</font>
00477                                         <font class="keywordflow">if</font> (maxv.z&gt;<a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>[<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>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>])
00478                                         {
00479                                                 <font class="comment">// New height in this cell</font>
00480                                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</a>[<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>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>]=maxv.z;
00481                                         }
00482                                 }
00483                         }
00484                 }
00485 
00486                 <font class="comment">// Retrieve the zone to fill its shaded value</font>
00487                 pZone-&gt;retrieve (<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>, <a class="code" href="classNL3D_1_1CZoneLighter.html#o24">_BorderVertices</a>);
00488 
00489                 <font class="comment">// Number of patch</font>
00490                 uint patchCount=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size();
00491 
00492                 <font class="comment">// Bit array to know if the lumel is shadowed</font>
00493                 <font class="keywordflow">if</font> (description.Shadow)
00494                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>.resize (patchCount);
00495 
00496                 <font class="comment">// A lumel vector by patch</font>
00497                 vector&lt;vector&lt;CLumelDescriptor&gt; &gt; lumels;
00498                 lumels.resize (patchCount);
00499 
00500                 <font class="comment">// Build zone informations</font>
00501                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c3">buildZoneInformation</a> (landscape,
00502                                                           listZone,
00503                                                           description.Oversampling!=CLightDesc::NoOverSampling,
00504                                                           description);
00505 
00506         }
00507 
00508         <font class="comment">// Number of patch</font>
00509         uint patchCount=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size();
00510 
00511         <font class="comment">// Reset patch count</font>
00512         {
00513                 CSynchronized&lt;std::vector&lt;bool&gt; &gt;::CAccessor access (&amp;<a class="code" href="classNL3D_1_1CZoneLighter.html#o9">_PatchComputed</a>);
00514                 access.value().resize (0);
00515                 access.value().resize (patchCount, <font class="keyword">false</font>);
00516         }
00517 
00518         <font class="comment">// Patch by thread</font>
00519         uint patchCountByThread = patchCount/<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>;
00520         patchCountByThread++;
00521 
00522         <font class="comment">// Patch to allocate</font>
00523         uint firstPatch=0;
00524         <a class="code" href="classNL3D_1_1CZoneLighter.html#o11">_NumberOfPatchComputed</a> = 0;
00525 
00526         <a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a>=0;
00527 
00528         <font class="comment">// Set the thread state</font>
00529         <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>.resize (<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>);
00530 
00531         <font class="comment">// Launch threads</font>
00532         <font class="keywordflow">for</font> (uint process=1; process&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>; process++)
00533         {
00534                 <font class="comment">// Last patch</font>
00535                 uint lastPatch=firstPatch+patchCountByThread;
00536                 <font class="keywordflow">if</font> (lastPatch&gt;patchCount)
00537                         lastPatch=patchCount;
00538 
00539                 <font class="comment">// Last patch computed</font>
00540                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[process] = firstPatch;
00541 
00542                 <font class="comment">// Create a thread</font>
00543                 CCalcRunnable *runnable = <font class="keyword">new</font> CCalcRunnable (process, <font class="keyword">this</font>, &amp;description);
00544                 IThread *pThread=IThread::create (runnable);
00545                 runnable-&gt;Thread = pThread;
00546                 
00547                 <font class="comment">// New first patch</font>
00548                 firstPatch=lastPatch;
00549 
00550                 <font class="comment">// Launch</font>
00551                 pThread-&gt;start();
00552         }
00553 
00554         <font class="comment">// My thread</font>
00555         uint lastPatch=firstPatch+patchCountByThread;
00556         <font class="keywordflow">if</font> (lastPatch&gt;patchCount)
00557                 lastPatch=patchCount;
00558         <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[0] = firstPatch;
00559         CCalcRunnable thread (0, <font class="keyword">this</font>, &amp;description);
00560         thread.Thread = currentThread;
00561         thread.run();
00562 
00563         <font class="comment">// Wait for others processes</font>
00564         <font class="keywordflow">while</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a>!=<a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>)
00565         {
00566                 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (10);
00567         }
00568 
00569         <font class="comment">// Reset old thread mask</font>
00570         currentThread-&gt;setCPUMask (threadMask);
00571 
00572         <font class="comment">// Progress bar</font>
00573         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.f);
00574 
00575         <font class="comment">// Compute PointLight influences on zone.</font>
00576         <font class="comment">// Some precalc.</font>
00577         <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_0">compilePointLightRT</a>(description.GridSize, description.GridCellSize, obstacles, 
00578                 description.Shadow || description.Softshadow );
00579         <font class="comment">// Influence patchs and get light list of interest</font>
00580         std::vector&lt;CPointLightNamed&gt;   listPointLight;
00581         <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_1">processZonePointLightRT</a>(listPointLight);
00582 
00583 
00584         <font class="comment">// Rebuild the zone</font>
00585 
00586         <font class="comment">// Progress bar</font>
00587         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compress the lightmap"</font>, 0.6f);
00588 
00589         <font class="comment">// Build, with list of lights.</font>
00590         CZoneInfo       zinfo;
00591         zinfo.ZoneId= <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>;
00592         zinfo.Patchs= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>;
00593         zinfo.BorderVertices= <a class="code" href="classNL3D_1_1CZoneLighter.html#o24">_BorderVertices</a>;
00594         zinfo.PointLights= listPointLight;
00595         output.build (zinfo);
00596 
00598         <a class="code" href="classNL3D_1_1CZoneLighter.html#f0">copyTileFlags</a>(output, *(landscape.getZone(zoneToLight)));
00599 
00601         <a class="code" href="classNL3D_1_1CZoneLighter.html#c14">lightShapes</a>(zoneToLight, description);
00602 }
00603 
00604 
00605 <font class="comment">// *************************************************************************************</font>
<a name="l00606"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#f0">00606</a> <font class="keywordtype">void</font> CZoneLighter::copyTileFlags(CZone &amp;destZone, <font class="keyword">const</font> CZone &amp;srcZone)
00607 {
00608         <a class="code" href="debug_8h.html#a6">nlassert</a>(destZone.getZoneId() == srcZone.getZoneId());
00609         <font class="keywordflow">for</font> (sint k = 0; k &lt; srcZone.getNumPatchs(); ++k)
00610         {
00611                 destZone.copyTilesFlags(k, srcZone.getPatch(k));
00612         }
00613 }
00614 
00615 <font class="comment">// ***************************************************************************</font>
<a name="l00616"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c7">00616</a> <font class="keywordtype">float</font> CZoneLighter::getSkyContribution(<font class="keyword">const</font> CVector &amp;pos, <font class="keyword">const</font> CVector &amp;normal, <font class="keywordtype">float</font> skyIntensity)<font class="keyword"> const</font>
00617 <font class="keyword"></font>{       
00618         <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=(pos.x-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>;
00619         <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=(pos.y-<a class="code" href="classNL3D_1_1CZoneLighter.html#o21">_OrigineHeightField</a>.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>;
00620         sint sInt=(sint)(floor (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f));
00621         sint tInt=(sint)(floor (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f));
00622 
00623         <font class="comment">// Bilinear</font>
00624         <font class="keywordtype">float</font> skyContributionTab[2][2];
00625         skyContributionTab[0][0] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt-1, tInt-1, pos.z, skyIntensity, normal);
00626         skyContributionTab[1][0] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt, tInt-1, pos.z, skyIntensity, normal);
00627         skyContributionTab[1][1] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt, tInt, pos.z, skyIntensity, normal);
00628         skyContributionTab[0][1] = <a class="code" href="classNL3D_1_1CZoneLighter.html#c6">calcSkyContribution</a> (sInt-1, tInt, pos.z, skyIntensity, normal);
00629         
00630         <font class="keywordtype">float</font> sFact=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f-sInt;
00631         <font class="keywordtype">float</font> tFact=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f-tInt;
00632         <font class="keywordflow">return</font> (skyContributionTab[0][0]*(1.f-sFact) + skyContributionTab[1][0]*sFact)*(1.f-tFact) +
00633                 (skyContributionTab[0][1]*(1.f-sFact) + skyContributionTab[1][1]*sFact)*tFact;  
00634 }
00635 
00636 
00637 <font class="comment">// ***************************************************************************</font>
<a name="l00638"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c2">00638</a> <font class="keywordtype">void</font> CZoneLighter::processCalc (uint process, <font class="keyword">const</font> CLightDesc&amp; description)
00639 {
00640         <font class="comment">// *** Raytrace each patches</font>
00641 
00642         <font class="comment">// Pointer on the zone</font>
00643         CZone *pZone=<a class="code" href="classNL3D_1_1CZoneLighter.html#o5">_Landscape</a>-&gt;<a class="code" href="classNL3D_1_1CLandscape.html#z481_0">getZone</a> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>);
00644 
00645         <font class="comment">// Get a patch</font>
00646         uint patch = <a class="code" href="classNL3D_1_1CZoneLighter.html#c21">getAPatch</a> (process);
00647         <font class="keywordflow">while</font> (patch != 0xffffffff)
00648         {
00649                 <font class="comment">// For each patch</font>
00650                 <font class="keywordflow">if</font> (description.Shadow)
00651                 {
00652                         <font class="comment">// Shape array</font>
00653                         CMultiShape *shapeArray=<font class="keyword">new</font> CMultiShape;
00654                         CMultiShape *shapeArrayTmp=<font class="keyword">new</font> CMultiShape;
00655                         shapeArray-&gt;Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>);
00656                         shapeArrayTmp-&gt;Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>);
00657 
00658                         <font class="comment">// Lumels</font>
00659                         std::vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch];
00660                 
00661                         <font class="comment">// Lumel count</font>
00662                         uint lumelCount=lumels.size();
00663                         CPatchInfo &amp;patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch];
00664                         <a class="code" href="debug_8h.html#a6">nlassert</a> (patchInfo.Lumels.size()==lumelCount);
00665 
00666                         <font class="comment">// Resize shadow array</font>
00667                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>[patch].resize (lumelCount);
00668 
00669                         <font class="comment">// For each lumel</font>
00670                         <font class="keywordflow">for</font> (uint lumel=0; lumel&lt;lumelCount; lumel++)
00671                         {
00672                                 <font class="keywordtype">float</font> factor=0;
00673                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c9">rayTrace</a> (lumels[lumel].Position, lumels[lumel].Normal, lumels[lumel].S, lumels[lumel].T, patch, factor, *shapeArray, *shapeArrayTmp, process);
00674                                 patchInfo.Lumels[lumel]=(uint)(factor*255);
00675                         }
00676                         <font class="keyword">delete</font> shapeArray;
00677                         <font class="keyword">delete</font> shapeArrayTmp;
00678                 }
00679                 <font class="keywordflow">else</font>
00680                 {
00681                         <font class="comment">// Lumels</font>
00682                         std::vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch];
00683                 
00684                         <font class="comment">// Lumel count</font>
00685                         uint lumelCount=lumels.size();
00686                         CPatchInfo &amp;patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch];
00687                         <a class="code" href="debug_8h.html#a6">nlassert</a> (patchInfo.Lumels.size()==lumelCount);
00688 
00689                         <font class="comment">// For each lumel</font>
00690                         <font class="keywordflow">for</font> (uint lumel=0; lumel&lt;lumelCount; lumel++)
00691                         {
00692                                 <font class="comment">// Not shadowed</font>
00693                                 patchInfo.Lumels[lumel]=255;
00694                         }
00695                 }
00696 
00697                 <font class="comment">// *** Antialising</font>
00698                 
00699                 <font class="comment">// Id of this zone in the array</font>
00700                 uint zoneNumber=<a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>[<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>];
00701 
00702                 <font class="comment">// Enabled ?</font>
00703                 <font class="keywordflow">if</font> ((description.Shadow)&amp;&amp;(description.Oversampling!=CLightDesc::NoOverSampling))
00704                 {
00705                         <font class="comment">// Get a patch pointer</font>
00706                         <font class="keyword">const</font> CPatch *pPatch=(const_cast&lt;const CZone*&gt;(pZone))-&gt;getPatch (patch);
00707 
00708                         <font class="comment">// Get the patch info</font>
00709                         CPatchInfo &amp;patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch];
00710 
00711                         <font class="comment">// Get order of the patch</font>
00712                         uint orderLumelS=pPatch-&gt;getOrderS()&lt;&lt;2;
00713                         uint orderLumelT=pPatch-&gt;getOrderT()&lt;&lt;2;
00714 
00715                         <font class="comment">// ** Pointer on arries</font>
00716                         vector&lt;bool&gt; &amp;binded=<a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zoneNumber][patch];
00717                         vector&lt;bool&gt; &amp;oversampleEdges=<a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch];
00718                         vector&lt;CPatchUVLocator&gt; &amp;locator=<a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zoneNumber][patch];
00719                         std::vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch];
00720 
00721                         <font class="comment">// Shadow array</font>
00722                         vector&lt;uint8&gt; &amp;shadowPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>[patch];
00723 
00724                         <font class="comment">// Go for each lumel</font>
00725                         <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;orderLumelT; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++)
00726                         <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&lt;orderLumelS; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++)
00727                         {
00728                                 <font class="comment">// Over sample this lumel</font>
00729                                 <font class="keywordtype">bool</font> oversample=<font class="keyword">false</font>;
00730                                 uint8 shadowed=shadowPatch[<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>*orderLumelS];
00731 
00732                                 <font class="comment">// Left..</font>
00733                                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==0)
00734                                 {
00735                                         <font class="comment">// Edge test</font>
00736                                         oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 0, <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>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>);
00737                                 }
00738                                 <font class="keywordflow">else</font>
00739                                 {
00740                                         <font class="comment">// Internal test</font>
00741                                         oversample=(shadowed!=shadowPatch[(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>-1)+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderLumelS]);
00742                                 }
00743 
00744                                 <font class="comment">// Bottom..</font>
00745                                 <font class="keywordflow">if</font> (!oversample)
00746                                 {
00747                                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==(orderLumelT-1))
00748                                         {
00749                                                 <font class="comment">// Edge test</font>
00750                                                 oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 1, <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>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>);
00751                                         }
00752                                         <font class="keywordflow">else</font>
00753                                         {
00754                                                 <font class="comment">// Internal test</font>
00755                                                 oversample=(shadowed!=shadowPatch[<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>+1)*orderLumelS]);
00756                                         }
00757 
00758                                         <font class="comment">// Right..</font>
00759                                         <font class="keywordflow">if</font> (!oversample)
00760                                         {
00761                                                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>==(orderLumelS-1))
00762                                                 {
00763                                                         <font class="comment">// Edge test</font>
00764                                                         oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 2, <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>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>);
00765                                                 }
00766                                                 <font class="keywordflow">else</font>
00767                                                 {
00768                                                         <font class="comment">// Internal test</font>
00769                                                         oversample=(shadowed!=shadowPatch[(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1)+<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>*orderLumelS]);
00770                                                 }
00771 
00772                                                 <font class="comment">// Top..</font>
00773                                                 <font class="keywordflow">if</font> (!oversample)
00774                                                 {
00775                                                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>==0)
00776                                                         {
00777                                                                 <font class="comment">// Edge test</font>
00778                                                                 oversample=<a class="code" href="classNL3D_1_1CZoneLighter.html#c13">isLumelOnEdgeMustBeOversample</a> (patch, 3, <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>, binded, oversampleEdges, locator, shadowed, <a class="code" href="classNL3D_1_1CZoneLighter.html#o8">_ShadowArray</a>);
00779                                                         }
00780                                                         <font class="keywordflow">else</font>
00781                                                         {
00782                                                                 <font class="comment">// Internal test</font>
00783                                                                 oversample=(shadowed!=shadowPatch[<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>-1)*orderLumelS]);
00784                                                         }
00785                                                 }
00786                                         }
00787                                 }
00788 
00789                                 <font class="comment">// Must oversample ?</font>
00790                                 <font class="keywordflow">if</font> (oversample)
00791                                 {
00792                                         <font class="comment">// LumelId</font>
00793                                         uint lumel=<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>*orderLumelS;
00794 
00795                                         <font class="comment">// Lighting</font>
00796                                         <font class="keywordtype">float</font> factor=0;
00797 
00798                                         <font class="comment">// Number of ray clipped</font>
00799                                         uint tested=0;
00800 
00801                                         <font class="comment">// For each triangle</font>
00802                                         CTriangleList *list=lumels[lumel].TriangleList;
00803                                         <font class="keywordflow">while</font> (list!=NULL)
00804                                         {
00805                                                 <font class="comment">// Raytrace this triangle                                                       </font>
00806                                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (list-&gt;Triangle, lumels[lumel].Normal, description.Oversampling, lumels[lumel].S, lumels[lumel].T, factor, tested, patch);
00807 
00808                                                 <font class="comment">// Next triangle</font>
00809                                                 list=list-&gt;Next;
00810                                         }
00811 
00812                                         <font class="comment">// Set new shadow value</font>
00813                                         <a class="code" href="debug_8h.html#a6">nlassert</a> (tested!=0);
00814                                         <font class="keywordflow">if</font> (tested!=0)
00815                                                 patchInfo.Lumels[lumel]=(uint)(255.f*factor/(float)tested);
00816                                 }
00817                         }
00818                 }
00819 
00820                 <font class="comment">// *** Lighting</font>
00821                 
00822                 <font class="comment">// Get the patch info</font>
00823                 CPatchInfo &amp;patchInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[patch];
00824 
00825                 <font class="comment">// ** Pointer on arries</font>
00826                 std::vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch];
00827 
00828                 <font class="comment">// Go for light each lumel</font>
00829                 <font class="keywordflow">for</font> (uint lumel=0; lumel&lt;lumels.size(); lumel++)
00830                 {
00831                         <font class="comment">// Sky contribution</font>
00832                         <font class="keywordtype">float</font> skyContribution;
00833                                 
00834                         <font class="keywordflow">if</font> (description.SkyContribution)
00835                         {                                                               
00836                                 skyContribution = <a class="code" href="classNL3D_1_1CZoneLighter.html#c7">getSkyContribution</a>(lumels[lumel].Position, lumels[lumel].Normal, description.SkyIntensity);
00837                         }
00838                         <font class="keywordflow">else</font>
00839                         {
00840                                 skyContribution = 0.f;
00841                         }
00842 
00843                         <font class="comment">// Sun contribution</font>
00844                         <font class="keywordtype">float</font> sunContribution;
00845                         <font class="keywordflow">if</font> (description.SunContribution)
00846                         {
00847                                 sunContribution=(-lumels[lumel].Normal*<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)-skyContribution;
00848                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (sunContribution, 0.f, 1.f);
00849                         }
00850                         <font class="keywordflow">else</font>
00851                                 sunContribution=0;
00852 
00853                         <font class="comment">// Final lighting</font>
00854                         sint finalLighting=(sint)(255.f*(((float)patchInfo.Lumels[lumel])*sunContribution/255.f+skyContribution));
00855                         <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (finalLighting, 0, 255);
00856                         patchInfo.Lumels[lumel]=finalLighting;
00857                 }
00858 
00859                 <font class="comment">// Next patch</font>
00860                 patch = <a class="code" href="classNL3D_1_1CZoneLighter.html#c21">getAPatch</a> (process);
00861         }
00862 }
00863 
00864 <font class="comment">// ***************************************************************************</font>
00865 
<a name="l00866"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c8">00866</a> uint8 CZoneLighter::getMaxPhi (sint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, sint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, sint deltaS, sint deltaT, <font class="keywordtype">float</font> heightPos)<font class="keyword"> const</font>
00867 <font class="keyword"></font>{
00868         <font class="comment">// Start position</font>
00869         <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+=deltaS;
00870         <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=deltaT;
00871 
00872         <font class="comment">// Distance increment</font>
00873         <font class="keywordtype">float</font> stepDistance=CVector (deltaS*<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>, deltaT*<a class="code" href="classNL3D_1_1CZoneLighter.html#o22">_HeightfieldCellSize</a>,0).norm ();
00874 
00875         <font class="comment">// Current distance</font>
00876         <font class="keywordtype">float</font> distance=stepDistance;
00877 
00878         <font class="comment">// Max height</font>
00879         <font class="keywordtype">float</font> maxHeight=0;
00880         <font class="keywordtype">float</font> maxTanTeta=0;
00881 
00882         <font class="comment">// For all the line</font>
00883         <font class="keywordflow">while</font> ((s&lt;_HeightFieldCellCount)&amp;&amp;(t&lt;_HeightFieldCellCount)&amp;&amp;(s&gt;=0)&amp;&amp;(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&gt;=0))
00884         {
00885                 <font class="comment">// Get height</font>
00886                 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>=<a class="code" href="classNL3D_1_1CZoneLighter.html#o19">_HeightField</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>*<a class="code" href="classNL3D_1_1CZoneLighter.html#o20">_HeightFieldCellCount</a>];
00887                 <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>-=heightPos;
00888 
00889                 <font class="comment">// Better ?</font>
00890                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>&gt;maxHeight)
00891                 {
00892                         <font class="comment">// Calc sin teta</font>
00893                         <font class="keywordtype">float</font> tanTeta=<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>/distance;
00894                         <a class="code" href="debug_8h.html#a6">nlassert</a> (tanTeta&gt;=0);
00895 
00896                         <font class="comment">// Better ?</font>
00897                         <font class="keywordflow">if</font> (tanTeta&gt;maxTanTeta)
00898                         {
00899                                 <font class="comment">// New max height</font>
00900                                 maxHeight=<a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>;
00901                                 maxTanTeta=tanTeta;
00902                         }
00903                 }
00904                 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+=deltaS;
00905                 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+=deltaT;
00906                 distance+=stepDistance;
00907         }
00908 
00909         <font class="comment">// return phi</font>
00910         <font class="keywordtype">float</font> teta=(float)atan (maxTanTeta);
00911         <a class="code" href="debug_8h.html#a6">nlassert</a> (teta&gt;=0);
00912         <a class="code" href="debug_8h.html#a6">nlassert</a> (teta&lt;=<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2);
00913         <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (teta, 0.f, (<font class="keywordtype">float</font>)<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2);
00914         sint <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>=(sint)((<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2-teta)*256/(<a class="code" href="namespaceNLMISC.html#a7">Pi</a>/2));
00915         <a class="code" href="namespaceNLMISC.html#a215">clamp</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>, 0, 255);
00916         <font class="keywordflow">return</font> (uint8)<a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00917 }
00918 
00919 <font class="comment">// ***************************************************************************</font>
00920 
<a name="l00921"></a><a class="code" href="zone__lighter_8cpp.html#a1">00921</a> <font class="preprocessor">#define AllFront 0</font>
<a name="l00922"></a><a class="code" href="zone__lighter_8cpp.html#a2">00922</a> <font class="preprocessor"></font><font class="preprocessor">#define AllBack 1</font>
<a name="l00923"></a><a class="code" href="zone__lighter_8cpp.html#a3">00923</a> <font class="preprocessor"></font><font class="preprocessor">#define Clipped 2</font>
00924 <font class="preprocessor"></font>
00925 <font class="comment">// ***************************************************************************</font>
00926 
<a name="l00927"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c12">00927</a> <font class="keywordtype">void</font> CZoneLighter::testRaytrace (<font class="keyword">const</font> CVector&amp; position, <font class="keyword">const</font> CVector&amp; normal, <font class="keyword">const</font> CPlane &amp;plane, <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 patchId, CMultiShape &amp;shape, CMultiShape &amp;shapeTmp, uint cpu)
00928 {
00929          <font class="comment">// Clear the selection of the quad tree</font>
00930         <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].clearSelection ();
00931 
00932         <font class="comment">// Light position</font>
00933         CVector lightPos=position-(<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>*1000.f);
00934 
00935         <font class="comment">// Select an element with the X axis as a 3d ray</font>
00936         <a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].select (lightPos-<a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>, lightPos+<a class="code" href="classNL3D_1_1CZoneLighter.html#o2">_RayAdd</a>);
00937 
00938         <font class="comment">// Tmp</font>
00939         CShape back;
00940         CShape front;
00941         CShape copy;
00942 
00943 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
00944 <font class="preprocessor"></font>
00945         <font class="comment">// Vector unit</font>
00946         <font class="keywordtype">float</font> unit=2*<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>;
00947 
00948         <font class="comment">// Make a scale matrix</font>
00949         CMatrix lumelScale;
00950         lumelScale.identity ();
00951         lumelScale.scale (unit);
00952 
00953         <font class="comment">// Get the ray basis</font>
00954         CMatrix lumelBasis=<a class="code" href="classNL3D_1_1CZoneLighter.html#o1">_RayBasis</a>*lumelScale;
00955 
00956         <font class="comment">// Change origine in the top left corner</font>
00957         lumelBasis.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_6">setPos</a> (position-lumelBasis.getI()/2-lumelBasis.getJ()/2);
00958 
00959         <font class="comment">// Inverse this matrix</font>
00960         lumelBasis.invert ();
00961 
00962 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
00963 <font class="preprocessor"></font>
00964         <font class="comment">// For each triangle selected</font>
00965         CQuadGrid&lt;const CTriangle*&gt;::CIterator it=<a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].begin();
00966         <font class="keywordflow">while</font> (it!=<a class="code" href="classNL3D_1_1CZoneLighter.html#o0">_QuadGrid</a>[cpu].end())
00967         {
00968                 <font class="comment">// Source vector</font>
00969                 CVector source=position;
00970 
00971                 <font class="comment">// Same triangle ?</font>
00972                 <font class="keywordflow">if</font> (
00973                         ((*it)-&gt;PatchId==patchId)&amp;&amp;
00974                         ((*it)-&gt;ZoneId==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)&amp;&amp;
00975                         ((*it)-&gt;StartS&lt;=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>)&amp;&amp;
00976                         ((*it)-&gt;StartT&lt;=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)&amp;&amp;
00977                         ((*it)-&gt;EndS&gt;=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>)&amp;&amp;
00978                         ((*it)-&gt;EndT&gt;=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>)
00979                         )
00980                         source+=(normal*<a class="code" href="classNL3D_1_1CZoneLighter.html#o6">_ShadowBias</a>);
00981 
00982                 <font class="comment">// Blur ?</font>
00983                 <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CZoneLighter.html#o7">_Softshadow</a>)
00984                 {
00985                         <font class="comment">// Hit position</font>
00986                         CVector hit;
00987 
00988                         <font class="comment">// Intersect</font>
00989                         <font class="keywordflow">if</font> ((*it)-&gt;Triangle.intersect (source, lightPos, hit, (*it)-&gt;Plane))
00990                         {
00991                                 <font class="comment">// Clear the shape list</font>
00992                                 shape.Shapes.resize (0);
00993                                 <font class="keywordflow">break</font>;
00994                         }
00995                 }
00996                 <font class="keywordflow">else</font>
00997                 {
00998                         <font class="comment">// Triangle clippable ?</font>
00999                         <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> &amp;triangle=(*it)-&gt;Triangle;
01000 
01001                         <font class="comment">// Clip the ray over the triangle</font>
01002                         <font class="keywordtype">float</font> edgeFactor[3]=
01003                         {
01004                                 ((((triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>+triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>)/2) - source)*-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>,
01005                                 ((((triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>+triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>)/2) - source)*-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>,
01006                                 ((((triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>+triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>)/2) - source)*-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>)/<a class="code" href="classNL3D_1_1CZoneLighter.html#o18">_FallofDistance</a>,
01007                         };
01008                         <font class="keywordtype">float</font> oOEdgeFactor[3];
01009                         <font class="keywordtype">bool</font> scaleEdge[3];
01010                         uint edgeFlags[3];
01011                         <font class="keywordtype">bool</font> oneNotBack=<font class="keyword">false</font>;
01012                         uint i;
01013                         <font class="keywordflow">for</font> (i=0; i&lt;3; i++)
01014                         {
01015                                 <font class="comment">// Edge factor</font>
01016                                 <font class="keywordflow">if</font> (edgeFactor[i]&lt;0)
01017                                         <font class="comment">// Polygon behing</font>
01018                                         <font class="keywordflow">break</font>;
01019                                 <font class="keywordflow">if</font> (edgeFactor[i]&gt;1)
01020                                 {
01021                                         scaleEdge[i]=<font class="keyword">false</font>;
01022                                         edgeFactor[i]=1;
01023                                 }
01024                                 <font class="keywordflow">else</font>
01025                                 {
01026                                         scaleEdge[i]=<font class="keyword">true</font>;
01027                                         oOEdgeFactor[i]=1/edgeFactor[i];
01028                                 }
01029 
01030                                 <font class="comment">// Distance from clipping plane</font>
01031                                 <font class="keywordtype">float</font> distance=(*it)-&gt;ClippingPlanes[i]*source;
01032 
01033                                 <font class="comment">// Clipping distance</font>
01034                                 <font class="keywordtype">float</font> clipDist=edgeFactor[i]*<a class="code" href="classNL3D_1_1CZoneLighter.html#o17">_ShapeRadius</a>;
01035 
01036                                 <font class="comment">// Clip this distance</font>
01037                                 <font class="keywordflow">if</font> (distance&lt;-clipDist)
01038                                 {
01039                                         <font class="comment">// Back</font>
01040                                         edgeFlags[i]=<a class="code" href="zone__lighter_8cpp.html#a2">AllBack</a>;
01041                                 }
01042                                 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (distance&gt;clipDist)
01043                                         <font class="comment">// Front</font>
01044                                         <font class="keywordflow">break</font>;
01045                                 <font class="keywordflow">else</font>
01046                                 {
01047                                         <font class="comment">// Clipped</font>
01048                                         edgeFlags[i]=<a class="code" href="zone__lighter_8cpp.html#a3">Clipped</a>;
01049                                         oneNotBack=<font class="keyword">true</font>;
01050                                 }
01051                         }
01052 
01053                         <font class="comment">// Not front clipped</font>
01054                         <font class="keywordflow">if</font> (i==3)
01055                         {
01056 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
01057 <font class="preprocessor"></font>                                <font class="comment">// Transform this triangle in lumel basis</font>
01058                                 CVector <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[3] = { lumelBasis*triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>, lumelBasis*triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>, lumelBasis*triangle.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a> };
01059 
01060                                 <font class="comment">// Draw the triangle</font>
01061                                 drv-&gt;drawTriangle (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, CRGBA(0, 0, 0, 2));
01062                                 drv-&gt;drawTriangle (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>, CRGBA(0, 0, 0, 2));
01063 
01064 <font class="preprocessor">#else // HARDWARE_SOFT_SHADOWS</font>
01065 <font class="preprocessor"></font>                                <font class="comment">// All back ?</font>
01066                                 <font class="keywordflow">if</font> (oneNotBack)
01067                                 {
01068                                         uint backupSize=shape.Shapes.size();
01069                                         <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&lt;backupSize; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++)
01070                                         {
01071                                                 <font class="comment">// Reset out list</font>
01072                                                 shapeTmp.Shapes.resize (0);
01073                                                 back = shape.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>];
01074 
01075                                                 <font class="comment">// Clip this shape with the triangle (3 planes)</font>
01076                                                 <font class="keywordflow">for</font> (i=0; i&lt;3; i++)
01077                                                 {
01078                                                         <font class="comment">// All back ?</font>
01079                                                         <font class="keywordflow">if</font> (edgeFlags[i]==<a class="code" href="zone__lighter_8cpp.html#a2">AllBack</a>)
01080                                                                 <font class="comment">// Yes, next</font>
01081                                                                 <font class="keywordflow">continue</font>;
01082 
01083                                                         <font class="comment">// Security</font>
01084                                                         <font class="keywordflow">if</font> (back.NumVertex &gt; (<a class="code" href="zone__lighter_8h.html#a0">SHAPE_VERTICES_MAX</a>-10) )
01085                                                                 <font class="keywordflow">break</font>;
01086 
01087                                                         <font class="comment">// Scale down this shape</font>
01088                                                         <font class="keywordflow">if</font> (scaleEdge[i])
01089                                                                 back.scale (source, edgeFactor[i]);
01090 
01091                                                         <font class="comment">// Copy the back buffer</font>
01092                                                         copy=back;
01093 
01094                                                         <font class="comment">// Clipping plane</font>
01095                                                         <font class="keyword">const</font> CPlane &amp;clippingPlane=(*it)-&gt;ClippingPlanes[i];
01096 
01097                                                         <font class="comment">// Reset back and front</font>
01098                                                         back.NumVertex=0;
01099                                                         front.NumVertex=0;
01100 
01101                                                         <font class="comment">// Clip</font>
01102                                                         <font class="keywordflow">if</font>(copy.NumVertex&gt;2)
01103                                                         {
01104                                                                 <font class="comment">// Previous vertex</font>
01105                                                                 uint prev=copy.NumVertex-1;
01106 
01107                                                                 <font class="comment">// Previous front ?</font>
01108                                                                 <font class="keywordtype">bool</font> previousFront=(clippingPlane*copy.Vertices[prev] &gt;= 0);
01109 
01110                                                                 <font class="comment">// For each vertex</font>
01111                                                                 <font class="keywordflow">for</font> (uint cur=0;cur&lt;copy.NumVertex;cur++)
01112                                                                 {
01113                                                                         <font class="comment">// Current vertex front ?</font>
01114                                                                         <font class="keywordtype">bool</font> currentFront=(clippingPlane*copy.Vertices[cur] &gt;= 0);
01115                                                                         <font class="keywordflow">if</font> ( currentFront )
01116                                                                         {
01117                                                                                 <font class="comment">// Previous vertex back ?</font>
01118                                                                                 <font class="keywordflow">if</font> ( !previousFront )
01119                                                                                 {
01120                                                                                         <font class="comment">// Ok, intersect</font>
01121                                                                                         front.Vertices[front.NumVertex]= clippingPlane.intersect(copy.Vertices[prev],copy.Vertices[cur]);
01122                                                                                         back.Vertices[back.NumVertex++]= front.Vertices[front.NumVertex];
01123                                                                                         front.NumVertex++;
01124                                                                                 }
01125                                                                                 <font class="comment">// Store new vertex front</font>
01126                                                                                 front.Vertices[front.NumVertex++]=copy.Vertices[cur];
01127                                                                         }
01128                                                                         <font class="keywordflow">else</font>
01129                                                                         {
01130                                                                                 <font class="comment">// Previous vertex front ?</font>
01131                                                                                 <font class="keywordflow">if</font> ( previousFront )
01132                                                                                 {
01133                                                                                         front.Vertices[front.NumVertex]= clippingPlane.intersect(copy.Vertices[prev],copy.Vertices[cur]);
01134                                                                                         back.Vertices[back.NumVertex++]= front.Vertices[front.NumVertex];
01135                                                                                         front.NumVertex++;
01136                                                                                 }
01137                                                                                 back.Vertices[back.NumVertex++]=copy.Vertices[cur];
01138                                                                         }
01139                                                                         prev=cur;
01140                                                                         previousFront=currentFront;
01141                                                                 }
01142                                                         }
01143 
01144                                                         <font class="comment">// Scale up this shape</font>
01145                                                         <font class="keywordflow">if</font> (scaleEdge[i])
01146                                                         {
01147                                                                 back.scale (source, oOEdgeFactor[i]);
01148                                                                 front.scale (source, oOEdgeFactor[i]);
01149                                                         }
01150 
01151                                                         <font class="comment">// Some vertices front ?</font>
01152                                                         <font class="keywordflow">if</font> (front.NumVertex!=0)
01153                                                         {
01154                                                                 <font class="comment">// Front vertices ?</font>
01155                                                                 <font class="keywordflow">if</font> (back.NumVertex==0)
01156                                                                         <font class="comment">// Nothing else to clip</font>
01157                                                                         <font class="keywordflow">break</font>;
01158                                                         }
01159                                                         <font class="keywordflow">else</font>
01160                                                         {
01161                                                                 <font class="comment">// All vertices are back</font>
01162                                                                 <font class="comment">// Pass entire triangle to next plane</font>
01163                                                                 <font class="keywordflow">continue</font>;
01164                                                         }
01165 
01166                                                         <font class="comment">// Code is clipped</font>
01167                                                         <font class="comment">// res is the front shape, so it is out</font>
01168                                                         <font class="comment">// Last plane ?</font>
01169                                                         shapeTmp.Shapes.push_back (front);
01170                                                 }
01171                                                 <font class="keywordflow">if</font> (i==3)
01172                                                 {
01173                                                         <font class="comment">// Merge list..</font>
01174                                                         <font class="keywordflow">if</font> (shapeTmp.Shapes.empty())
01175                                                         {
01176                                                                 <font class="comment">// Erase this entry</font>
01177                                                                 shape.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>].NumVertex=0;
01178                                                         }
01179                                                         <font class="keywordflow">else</font>
01180                                                         {
01181                                                                 <font class="comment">// Copy first element</font>
01182                                                                 shape.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>]=shapeTmp.Shapes[0];
01183 
01184                                                                 <font class="comment">// Insert others</font>
01185                                                                 uint size=shapeTmp.Shapes.size();
01186                                                                 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=1; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;size; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++)
01187                                                                 {
01188                                                                         <font class="comment">// Append new shapes</font>
01189                                                                         shape.Shapes.push_back (shapeTmp.Shapes[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>]);
01190                                                                 }
01191                                                         }
01192                                                 }
01193                                         }
01194                                 }
01195                                 <font class="keywordflow">else</font>
01196                                 {
01197                                         <font class="comment">// Clear all the ray</font>
01198                                         shape.Shapes.resize (0);
01199                                 }
01200 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
01201 <font class="preprocessor"></font>                        }
01202                 }
01203 
01204                 <font class="comment">// Next</font>
01205                 it++;
01206         }
01207 }
01208 
01209 <font class="comment">// ***************************************************************************</font>
01210 
<a name="l01211"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c9">01211</a> <font class="keywordtype">void</font> CZoneLighter::rayTrace (<font class="keyword">const</font> CVector&amp; position, <font class="keyword">const</font> CVector&amp; normal, <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 patchId, <font class="keywordtype">float</font> &amp;factor, CMultiShape &amp;shape, CMultiShape &amp;shapeTmp, uint cpu)
01212 {
01213         <font class="comment">// Resize the shape list</font>
01214         shape.Shapes.resize (1);
01215 
01216         <font class="comment">// Ref on the cshape</font>
01217         CShape &amp;shp=shape.Shapes[0];
01218 
01219         <font class="comment">// Copy the shape</font>
01220         shp=<a class="code" href="classNL3D_1_1CZoneLighter.html#o15">_Shape</a>;
01221 
01222         <font class="comment">// Translate the shape</font>
01223         sint j;
01224         <font class="keywordflow">for</font> (j=0; j&lt;(sint)shp.NumVertex; j++)
01225         {
01226                 shp.<a class="code" href="classNL3D_1_1CZoneLighter_1_1CShape.html#m1">Vertices</a>[j]+=position;
01227         }
01228 
01229         <font class="comment">// Build a clipping plane</font>
01230         CPlane plane;
01231         plane.make (-<a class="code" href="classNL3D_1_1CZoneLighter.html#o3">_LightDirection</a>, position);
01232 
01233 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
01234 <font class="preprocessor"></font>
01235         <font class="comment">// Clear all pixels in green</font>
01236         drv-&gt;clearRGBABuffer (CRGBA (0, 255, 0, 0));
01237 
01238 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
01239 <font class="preprocessor"></font>
01240         <font class="comment">// Go!</font>
01241         <a class="code" href="classNL3D_1_1CZoneLighter.html#c12">testRaytrace</a> (position, normal, plane, <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>, patchId, shape, shapeTmp, cpu);
01242 
01243 <font class="preprocessor">#ifdef HARDWARE_SOFT_SHADOWS</font>
01244 <font class="preprocessor"></font>        
01245         <font class="comment">// Download frame buffer</font>
01246         <font class="keyword">static</font> CBitmap bitmap;
01247         drv-&gt;getBufferPart (bitmap, CRect (0, 0, LIGHT_BUFFER_SIZE, LIGHT_BUFFER_SIZE));
01248         <a class="code" href="debug_8h.html#a6">nlassert</a> (bitmap.getWidth()==LIGHT_BUFFER_SIZE);
01249         <a class="code" href="debug_8h.html#a6">nlassert</a> (bitmap.getHeight()==LIGHT_BUFFER_SIZE);
01250 
01251         <font class="comment">// Pixels</font>
01252         bitmap.convertToType (CBitmap::RGBA);
01253 
01254         <font class="comment">// RGBA pointer</font>
01255         CRGBA *pixels=(CRGBA*)&amp;bitmap.getPixels ()[0];
01256 
01257         <font class="comment">// Average pixel</font>
01258         factor=0;
01259         <font class="keywordflow">for</font> (uint p=0; p&lt;LIGHT_BUFFER_SIZE*LIGHT_BUFFER_SIZE; p++)
01260         {
01261                 factor+=pixels[p].G;
01262         }
01263         factor/=(float)(255*LIGHT_BUFFER_SIZE*LIGHT_BUFFER_SIZE);
01264 
01265 <font class="preprocessor">#else // HARDWARE_SOFT_SHADOWS</font>
01266 <font class="preprocessor"></font>        <font class="comment">// Calc the surface ratio</font>
01267         uint size=shape.Shapes.size();
01268         <font class="keywordflow">for</font> (uint i=0; i&lt;size; i++)
01269         {
01270                 <font class="comment">// For each shape</font>
01271                 CShape &amp;vect=shape.Shapes[i];
01272 
01273                 <font class="keywordflow">for</font> (j=1; j&lt;(sint)vect.NumVertex-1; j++)
01274                 {
01275                         <font class="comment">// Sum the area</font>
01276                         factor+=((vect.Vertices[j]-vect.Vertices[0])^(vect.Vertices[j+1]-vect.Vertices[0])).norm();
01277                 }
01278         }
01279 
01280         factor/=<a class="code" href="classNL3D_1_1CZoneLighter.html#o16">_ShapeArea</a>;
01281 <font class="preprocessor">#endif // HARDWARE_SOFT_SHADOWS</font>
01282 <font class="preprocessor"></font>}
01283 
01284 <font class="comment">// ***************************************************************************</font>
01285 
<a name="l01286"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c11">01286</a> <font class="keywordtype">void</font> CZoneLighter::rayTraceTriangle (<font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a>&amp; toOverSample, CVector&amp; normal, uint order, <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="keywordtype">float</font> &amp;factor, uint &amp;tested, uint patch)
01287 {
01288         <font class="comment">// Ok ?</font>
01289         <font class="keywordflow">if</font> (order==0)
01290         {
01291                 <font class="comment">// Ray !</font>
01292                 tested++;
01293                 <font class="comment">//rayTrace (-_LightDirection+(toOverSample.V0+toOverSample.V1+toOverSample.V2)/3, normal, s, t, patch, factor);</font>
01294         }
01295         <font class="keywordflow">else</font>
01296         {
01297                 <font class="comment">// Subdivide the triangle</font>
01298                 CVector v0V1=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>;
01299                 v0V1+=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>;
01300                 v0V1/=2;
01301                 CVector v0V2=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>;
01302                 v0V2+=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>;
01303                 v0V2/=2;
01304                 CVector v1V2=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>;
01305                 v1V2+=toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>;
01306                 v1V2/=2;
01307                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m0">V0</a>, v0V1, v0V2), normal, order-1, <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>, factor, tested, patch);
01308                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m1">V1</a>, v1V2, v0V1), normal, order-1, <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>, factor, tested, patch);
01309                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (toOverSample.<a class="code" href="classNLMISC_1_1CTriangle.html#m2">V2</a>, v0V2, v1V2), normal, order-1, <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>, factor, tested, patch);
01310                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c11">rayTraceTriangle</a> (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0V1, v1V2, v0V2), normal, order-1, <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>, factor, tested, patch);
01311         }
01312 }
01313 
01314 <font class="comment">// ***************************************************************************</font>
01315 
<a name="l01316"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c13">01316</a> <font class="keywordtype">bool</font> CZoneLighter::isLumelOnEdgeMustBeOversample (uint patch, uint edge, sint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>, sint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>, <font class="keyword">const</font> vector&lt;bool&gt; &amp;binded, 
01317                                                                                                   <font class="keyword">const</font> vector&lt;bool&gt; &amp;oversampleEdges, vector&lt;CPatchUVLocator&gt; &amp;locator, 
01318                                                                                                   uint8 shadowed, vector&lt;vector&lt;uint8&gt; &gt;&amp; shadowBuffer)
01319 {
01320         <font class="comment">// Must force oversampling of this edge ?</font>
01321         <font class="keywordflow">if</font> (oversampleEdges[edge])
01322                 <font class="keywordflow">return</font> <font class="keyword">true</font>;
01323         <font class="keywordflow">else</font>
01324         {
01325                 <font class="comment">// binded ?</font>
01326                 <font class="keywordflow">if</font> (binded[edge])
01327                 {
01328                         <font class="comment">// Lumel coord</font>
01329                         CVector2f lumelCoord (((<font class="keywordtype">float</font>)(<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[edge])+0.5f)/4.f, ((<font class="keywordtype">float</font>)(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[edge])+0.5f)/4.f);
01330                         uint otherPatch=locator[edge].selectPatch(lumelCoord);
01331 
01332                         <font class="comment">// Get uv</font>
01333                         CVector2f neighborUV;
01334                         CPatch *patchOut;
01335                         locator[edge].locateUV (lumelCoord, otherPatch, patchOut, neighborUV);
01336                         
01337                         <font class="comment">// Is the same shadowed flag ?</font>
01338                         sint ss=(sint)(neighborUV.x*4.f);
01339                         sint tt=(sint)(neighborUV.y*4.f);
01340                         <font class="keywordflow">return</font> (shadowBuffer[patchOut-&gt;getPatchId()][ss+(patchOut-&gt;getOrderS()&lt;&lt;2)*tt]!=shadowed);
01341                 }
01342                 <font class="keywordflow">else</font>
01343                 {
01344                         <font class="comment">// Not oversample if not binded</font>
01345                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
01346                 }
01347         }
01348 }
01349 
01350 <font class="comment">// ***************************************************************************</font>
01351 
<a name="l01352"></a><a class="code" href="zone__lighter_8cpp.html#a8">01352</a> <font class="keywordtype">float</font> <a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
01353 {
01354  <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
01355  <font class="comment">// cubic tq f(0)=0, f'(0)=0, f(1)=1, f'(1)=0.</font>
01356  <font class="keywordtype">float</font> x2=<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
01357  <font class="keywordtype">float</font> x3=x2*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
01358  <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= -2*x3 + 3*x2;
01359  <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
01360 }
01361 
01362 <font class="comment">// ***************************************************************************</font>
01363 
<a name="l01364"></a><a class="code" href="zone__lighter_8cpp.html#a9">01364</a> <font class="keywordtype">float</font> <a class="code" href="zone__lighter_8cpp.html#a9">easineasoutC2</a>(<font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
01365 {
01366  <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
01367  <font class="comment">// 5-nome tq f(0)=0, f'(0)=0, f''(0)=0, f(1)=1, f'(1)=0, f''(1)=0.</font>
01368  <font class="keywordtype">float</font> x3=<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
01369  <font class="keywordtype">float</font> x4=x3*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
01370  <font class="keywordtype">float</font> x5=x4*<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
01371  <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>= 6*x5 -15*x4 +10*x3;
01372  <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>;
01373 }
01374 
01375 <font class="comment">// ***************************************************************************</font>
01376 
01377 
<a name="l01378"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#r0">01378</a> sint16 CZoneLighter::_GetNormalDeltaS[4]={ -1, 0, 1, 0 };
<a name="l01379"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#r1">01379</a> sint16 CZoneLighter::_GetNormalDeltaT[4]={ 0, 1, 0, -1 };
01380 
01381 <font class="comment">// ***************************************************************************</font>
01382 
<a name="l01383"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c10">01383</a> <font class="keywordtype">void</font> CZoneLighter::getNormal (<font class="keyword">const</font> CPatch *pPatch, sint16 lumelS, sint16 lumelT, vector&lt;CPatchUVLocator&gt; &amp;locator, 
01384                                                                  <font class="keyword">const</font> vector&lt;CPatch::CBindInfo&gt; &amp;bindInfo, <font class="keyword">const</font> vector&lt;bool&gt; &amp;binded, set&lt;uint64&gt;&amp; visited, 
01385                                                                  <font class="keywordtype">float</font> deltaS, <font class="keywordtype">float</font> deltaT, uint rotation, <font class="keyword">const</font> CBezierPatch &amp;bezierPatch, uint lastEdge)
01386 {
01387         <font class="comment">// Build a desc srructure</font>
01388         uint64 <a class="code" href="driver__opengl__extension__def_8h.html#a356">id</a>=(uint64)lumelS|(((uint64)lumelT)&lt;&lt;16)|(((uint64)pPatch-&gt;getPatchId())&lt;&lt;32)|(((uint64)pPatch-&gt;getZone()-&gt;getZoneId())&lt;&lt;48);
01389 
01390         <font class="comment">// Insert it</font>
01391         <font class="keywordflow">if</font> (visited.insert (id).second)
01392         {
01393                 <font class="comment">// Clip</font>
01394                 <font class="keywordtype">float</font> sqDist=deltaS*deltaS+deltaT*deltaT;
01395                 <font class="keywordflow">if</font> ( sqDist &lt; 1 )
01396                 {
01397                         <font class="comment">// Continue...</font>
01398 
01399                         sint orderSx4=pPatch-&gt;getOrderS()&lt;&lt;2;
01400                         sint orderTx4=pPatch-&gt;getOrderT()&lt;&lt;2;
01401 
01402                         sint16 _GetNormalBorderS[4]={ 0, -10, 1, -10 };
01403                         sint16 _GetNormalBorderT[4]={ -10, 1, -10, 0 };
01404                         _GetNormalBorderS[2]=orderSx4-1;
01405                         _GetNormalBorderT[1]=orderTx4-1;
01406 
01407                         <font class="comment">// Add normal</font>
01408                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>+=bezierPatch.evalNormal ( ((<font class="keywordtype">float</font>)lumelS+0.5f)/(<font class="keywordtype">float</font>)orderSx4, ((<font class="keywordtype">float</font>)lumelT+0.5f)/(<font class="keywordtype">float</font>)orderTx4 );
01409 
01410                         <font class="comment">// For the four neighbors</font>
01411                         <font class="keywordflow">for</font> (uint edge=0; edge&lt;4; edge++)
01412                         {
01413                                 <font class="comment">// Not last edge ?</font>
01414                                 <font class="keywordflow">if</font> (edge!=lastEdge)
01415                                 {
01416                                         <font class="comment">// Direction</font>
01417                                         uint globalDirection=(edge+(4-rotation))&amp;0x3;
01418 
01419                                         <font class="comment">// Neighbor</font>
01420                                         <font class="keywordflow">if</font> ( (lumelS==_GetNormalBorderS[edge]) || (lumelT==_GetNormalBorderT[edge]) )
01421                                         {
01422                                                 <font class="comment">// Binded ?</font>
01423                                                 <font class="keywordtype">bool</font> bind=binded[edge];
01424                                                 <font class="keywordtype">bool</font> smooth=pPatch-&gt;getSmoothFlag (edge);
01425                                                 <font class="keywordflow">if</font> (bind&amp;&amp;smooth)
01426                                                 {
01427                                                         <font class="comment">// Lumel coord</font>
01428                                                         CVector2f lumelCoord ( ((<font class="keywordtype">float</font>)(lumelS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[edge])+0.5f)/4, 
01429                                                                 ((<font class="keywordtype">float</font>)(lumelT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[edge])+0.5f)/4 );
01430 
01431                                                         <font class="comment">// Get neighbor pixel</font>
01432                                                         uint otherPatch=locator[edge].selectPatch(lumelCoord);
01433 
01434                                                         <font class="comment">// Get uv</font>
01435                                                         CVector2f neighborUV;
01436                                                         CPatch *patchOut;
01437                                                         locator[edge].locateUV (lumelCoord, otherPatch, patchOut, neighborUV);
01438 
01439                                                         <font class="comment">// New coordinates</font>
01440                                                         sint16 newLumelS=(sint16)(4.f*neighborUV.x);
01441                                                         sint16 newLumelT=(sint16)(4.f*neighborUV.y);
01442 
01443                                                         <font class="comment">// Zone id</font>
01444                                                         uint16 patchId=patchOut-&gt;getPatchId();
01445                                                         uint16 zoneId=<a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>[patchOut-&gt;getZone()-&gt;getZoneId ()];
01446 
01447                                                         <font class="comment">// Get edge</font>
01448                                                         uint newEdge=0;
01449                                                         uint i;
01450                                                         <font class="keywordflow">for</font> (i=0; i&lt;=(uint)bindInfo[edge].NPatchs; i++)
01451                                                         {
01452                                                                 <font class="comment">// Good patch ?</font>
01453                                                                 <font class="keywordflow">if</font> (bindInfo[edge].Next[i]==patchOut)
01454                                                                 {
01455                                                                         <font class="comment">// Get its edge</font>
01456                                                                         newEdge=bindInfo[edge].Edge[i];
01457                                                                         <font class="keywordflow">break</font>;
01458                                                                 }
01459                                                         }
01460                                                         
01461                                                         <font class="comment">// Rotation </font>
01462                                                         uint newRotation=(2-edge+rotation+newEdge)&amp;0x3;
01463 
01464                                                         <font class="comment">// Must found it</font>
01465                                                         <a class="code" href="debug_8h.html#a6">nlassert</a> (i!=(uint)bindInfo[edge].NPatchs);
01466 
01467                                                         <font class="comment">// Get the bezier patch</font>
01468                                                         CBezierPatch &amp;NewBezierPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zoneId][patchId];
01469 
01470                                                         <font class="comment">// Next lumel</font>
01471                                                         <a class="code" href="classNL3D_1_1CZoneLighter.html#c10">getNormal</a> (patchOut, newLumelS, newLumelT, <a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zoneId][patchId], <a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zoneId][patchId], 
01472                                                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zoneId][patchId], visited, deltaS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[globalDirection], 
01473                                                                 deltaT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[globalDirection], newRotation, NewBezierPatch, newEdge);
01474                                                 }
01475                                         }
01476                                         <font class="keywordflow">else</font>
01477                                         {
01478                                                 <font class="comment">// Left internal</font>
01479                                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c10">getNormal</a> (pPatch, lumelS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[edge], lumelT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[edge], locator, bindInfo, binded, visited, 
01480                                                         deltaS+<a class="code" href="classNL3D_1_1CZoneLighter.html#r0">_GetNormalDeltaS</a>[globalDirection], deltaT+<a class="code" href="classNL3D_1_1CZoneLighter.html#r1">_GetNormalDeltaT</a>[globalDirection], rotation, bezierPatch, (edge+2)&amp;0x3);
01481                                         }
01482                                 }
01483                         }
01484                 }
01485         }
01486 }
01487 
01488 <font class="comment">// ***************************************************************************</font>
01489 
<a name="l01490"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a4">01490</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (CLandscape &amp;landscape, vector&lt;uint&gt; &amp;listZone, uint order, std::vector&lt;CTriangle&gt;&amp; triangleArray)
01491 {
01492         <font class="comment">// Set all to refine</font>
01493         <a class="code" href="classNL3D_1_1CZoneLighter.html#c4">excludeAllPatchFromRefineAll</a> (landscape, listZone, <font class="keyword">false</font>);
01494 
01495         <font class="comment">// Setup the landscape</font>
01496         landscape.setThreshold (0);
01497         landscape.setTileMaxSubdivision (order);
01498 
01499         <font class="comment">// Refine it</font>
01500         landscape.refineAll (CVector (0, 0, 0));
01501 
01502         <font class="comment">// Dump tesselated triangles</font>
01503         std::vector&lt;const CTessFace*&gt; leaves;
01504         landscape.getTessellationLeaves(leaves);
01505 
01506         <font class="comment">// Number of leaves</font>
01507         uint leavesCount=leaves.size();
01508 
01509         <font class="comment">// Reserve the array</font>
01510         triangleArray.reserve (triangleArray.size()+leavesCount);
01511 
01512         <font class="comment">// Scan each leaves</font>
01513         <font class="keywordflow">for</font> (uint leave=0; leave&lt;leavesCount; leave++)
01514         {
01515                 <font class="comment">// Leave</font>
01516                 <font class="keyword">const</font> CTessFace *face=leaves[leave];
01517 
01518                 <font class="comment">// Start and end coordinate</font>
01519                 <font class="keywordtype">float</font> startS=<a class="code" href="bit__set_8cpp.html#a0">min</a> (<a class="code" href="bit__set_8cpp.html#a0">min</a> (face-&gt;PVBase.getS(), face-&gt;PVLeft.getS()), face-&gt;PVRight.getS());
01520                 <font class="keywordtype">float</font> endS=max (max (face-&gt;PVBase.getS(), face-&gt;PVLeft.getS()), face-&gt;PVRight.getS());
01521                 <font class="keywordtype">float</font> startT=<a class="code" href="bit__set_8cpp.html#a0">min</a> (<a class="code" href="bit__set_8cpp.html#a0">min</a> (face-&gt;PVBase.getT(), face-&gt;PVLeft.getT()), face-&gt;PVRight.getT());
01522                 <font class="keywordtype">float</font> endT=max (max (face-&gt;PVBase.getT(), face-&gt;PVLeft.getT()), face-&gt;PVRight.getT());
01523 
01524                 <font class="comment">// Add a triangle</font>
01525                 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (face-&gt;VBase-&gt;EndPos, face-&gt;VLeft-&gt;EndPos, face-&gt;VRight-&gt;EndPos), 
01526                         face-&gt;Patch-&gt;getZone()-&gt;getZoneId(), face-&gt;Patch-&gt;getPatchId(), startS ,endS, startT, endT));
01527         }
01528 
01529         <font class="comment">// Setup the landscape</font>
01530         landscape.setThreshold (1000);
01531         landscape.setTileMaxSubdivision (0);
01532 
01533         <font class="comment">// Remove all triangles</font>
01534         landscape.refineAll (CVector (0, 0, 0));
01535         landscape.refineAll (CVector (0, 0, 0));
01536         landscape.refineAll (CVector (0, 0, 0));
01537         landscape.refineAll (CVector (0, 0, 0));
01538         landscape.refineAll (CVector (0, 0, 0));
01539         landscape.refineAll (CVector (0, 0, 0));
01540         landscape.refineAll (CVector (0, 0, 0));
01541         landscape.refineAll (CVector (0, 0, 0));
01542         landscape.refineAll (CVector (0, 0, 0));
01543         landscape.refineAll (CVector (0, 0, 0));
01544 }
01545 
01546 <font class="comment">// ***************************************************************************</font>
01547 
<a name="l01548"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a5">01548</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (<font class="keyword">const</font> IShape &amp;shape, <font class="keyword">const</font> CMatrix&amp; modelMT, std::vector&lt;CTriangle&gt;&amp; triangleArray)
01549 {
01550         <font class="comment">// Cast to CMesh</font>
01551         <font class="keyword">const</font> CMesh *mesh=dynamic_cast&lt;const CMesh*&gt;(&amp;shape);
01552 
01553         <font class="comment">// Cast to CMeshMultiLod</font>
01554         <font class="keyword">const</font> CMeshMultiLod *meshMulti=dynamic_cast&lt;const CMeshMultiLod*&gt;(&amp;shape);
01555 
01556         <font class="comment">// Cast to CMeshMultiLod</font>
01557         <font class="keyword">const</font> CMeshMRM *meshMRM=dynamic_cast&lt;const CMeshMRM*&gt;(&amp;shape);
01558 
01559         <font class="comment">// It is a mesh ?</font>
01560         <font class="keywordflow">if</font> (mesh)
01561         {
01562                 <font class="comment">// Add its triangles</font>
01563                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (mesh-&gt;getMeshGeom (), modelMT, triangleArray);
01564         }
01565         <font class="comment">// It is a CMeshMultiLod ?</font>
01566         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (meshMulti)
01567         {
01568                 <font class="comment">// Get the first geommesh</font>
01569                 <font class="keyword">const</font> IMeshGeom *meshGeom=&amp;meshMulti-&gt;getMeshGeom (0);
01570 
01571                 <font class="comment">// Dynamic cast</font>
01572                 <font class="keyword">const</font> CMeshGeom *geomMesh=dynamic_cast&lt;const CMeshGeom*&gt;(meshGeom);
01573                 <font class="keywordflow">if</font> (geomMesh)
01574                 {
01575                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (*geomMesh, modelMT, triangleArray);
01576                 }
01577 
01578                 <font class="comment">// Dynamic cast</font>
01579                 <font class="keyword">const</font> CMeshMRMGeom *mrmGeomMesh=dynamic_cast&lt;const CMeshMRMGeom*&gt;(meshGeom);
01580                 <font class="keywordflow">if</font> (mrmGeomMesh)
01581                 {
01582                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (*mrmGeomMesh, modelMT, triangleArray);
01583                 }
01584         }
01585         <font class="comment">// It is a CMeshMultiLod ?</font>
01586         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (meshMRM)
01587         {
01588                 <font class="comment">// Get the first lod mesh geom</font>
01589                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a4">addTriangles</a> (meshMRM-&gt;getMeshGeom (), modelMT, triangleArray);
01590         }
01591 }
01592 
01593 <font class="comment">// ***************************************************************************</font>
01594 
<a name="l01595"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c0">01595</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (<font class="keyword">const</font> CMeshGeom &amp;meshGeom, <font class="keyword">const</font> CMatrix&amp; modelMT, std::vector&lt;CTriangle&gt;&amp; triangleArray)
01596 {
01597         <font class="comment">// Get the vertex buffer</font>
01598         <font class="keyword">const</font> CVertexBuffer &amp;vb=meshGeom.getVertexBuffer();
01599 
01600         <font class="comment">// For each matrix block</font>
01601         uint numBlock=meshGeom.getNbMatrixBlock();
01602         <font class="keywordflow">for</font> (uint block=0; block&lt;numBlock; block++)
01603         {
01604                 <font class="comment">// For each render pass</font>
01605                 uint numRenderPass=meshGeom.getNbRdrPass(block);
01606                 <font class="keywordflow">for</font> (uint pass=0; pass&lt;numRenderPass; pass++)
01607                 {
01608                         <font class="comment">// Get the primitive block</font>
01609                         <font class="keyword">const</font> CPrimitiveBlock &amp;primitive=meshGeom.getRdrPassPrimitiveBlock ( block, pass);
01610 
01611                         <font class="comment">// Dump triangles</font>
01612                         <font class="keyword">const</font> uint32* triIndex=primitive.getTriPointer ();
01613                         uint numTri=primitive.getNumTri ();
01614                         uint tri;
01615                         <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
01616                         {
01617                                 <font class="comment">// Vertex</font>
01618                                 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3]));
01619                                 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+1]));
01620                                 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+2]));
01621 
01622                                 <font class="comment">// Make a triangle</font>
01623                                 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2)));
01624                         }
01625 
01626                         <font class="comment">// Dump quad</font>
01627                         triIndex=primitive.getQuadPointer ();
01628                         numTri=primitive.getNumQuad ();
01629                         <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
01630                         {
01631                                 <font class="comment">// Vertex</font>
01632                                 CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4]));
01633                                 CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+1]));
01634                                 CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+2]));
01635                                 CVector v3=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+3]));
01636 
01637                                 <font class="comment">// Make 2 triangles</font>
01638                                 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2)));
01639                                 triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v2, v3)));
01640                         }
01641                 }
01642         }
01643 }
01644 
01645 <font class="comment">// ***************************************************************************</font>
01646 
<a name="l01647"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c1">01647</a> <font class="keywordtype">void</font> CZoneLighter::addTriangles (<font class="keyword">const</font> CMeshMRMGeom &amp;meshGeom, <font class="keyword">const</font> CMatrix&amp; modelMT, std::vector&lt;CTriangle&gt;&amp; triangleArray)
01648 {
01649         <font class="comment">// Get the vertex buffer</font>
01650         <font class="keyword">const</font> CVertexBuffer &amp;vb=meshGeom.getVertexBuffer();
01651 
01652         <font class="comment">// For each render pass</font>
01653         uint numRenderPass=meshGeom.getNbRdrPass(0);
01654         <font class="keywordflow">for</font> (uint pass=0; pass&lt;numRenderPass; pass++)
01655         {
01656                 <font class="comment">// Get the primitive block</font>
01657                 <font class="keyword">const</font> CPrimitiveBlock &amp;primitive=meshGeom.getRdrPassPrimitiveBlock ( 0, pass);
01658 
01659                 <font class="comment">// Dump triangles</font>
01660                 <font class="keyword">const</font> uint32* triIndex=primitive.getTriPointer ();
01661                 uint numTri=primitive.getNumTri ();
01662                 uint tri;
01663                 <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
01664                 {
01665                         <font class="comment">// Vertex</font>
01666                         CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3]));
01667                         CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+1]));
01668                         CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*3+2]));
01669 
01670                         <font class="comment">// Make a triangle</font>
01671                         triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2)));
01672                 }
01673 
01674                 <font class="comment">// Dump quad</font>
01675                 triIndex=primitive.getQuadPointer ();
01676                 numTri=primitive.getNumQuad ();
01677                 <font class="keywordflow">for</font> (tri=0; tri&lt;numTri; tri++)
01678                 {
01679                         <font class="comment">// Vertex</font>
01680                         CVector v0=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4]));
01681                         CVector v1=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+1]));
01682                         CVector v2=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+2]));
01683                         CVector v3=modelMT*(*(CVector*)vb.getVertexCoordPointer (triIndex[tri*4+3]));
01684 
01685                         <font class="comment">// Make 2 triangles</font>
01686                         triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v1, v2)));
01687                         triangleArray.push_back (CTriangle (<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (v0, v2, v3)));
01688                 }
01689         }
01690 }
01691 
01692 <font class="comment">// ***************************************************************************</font>
01693 
<a name="l01694"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c4">01694</a> <font class="keywordtype">void</font> CZoneLighter::excludeAllPatchFromRefineAll (CLandscape &amp;landscape, vector&lt;uint&gt; &amp;listZone, <font class="keywordtype">bool</font> exclude)
01695 {
01696         <font class="comment">// For each zone</font>
01697         <font class="keywordflow">for</font> (uint zone=0; zone&lt;listZone.size(); zone++)
01698         {
01699                 <font class="comment">// Get num patches</font>
01700                 uint patchCount=landscape.getZone(listZone[zone])-&gt;getNumPatchs();
01701 
01702                 <font class="comment">// For each patches</font>
01703                 <font class="keywordflow">for</font> (uint patch=0; patch&lt;patchCount; patch++)
01704                 {
01705                         <font class="comment">// Exclude all the patches from refine all</font>
01706                         landscape.excludePatchFromRefineAll (listZone[zone], patch, exclude);
01707                 }
01708         }
01709 }
01710 
01711 <font class="comment">// ***************************************************************************</font>
01712 
<a name="l01713"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c3">01713</a> <font class="keywordtype">void</font> CZoneLighter::buildZoneInformation (CLandscape &amp;landscape, <font class="keyword">const</font> vector&lt;uint&gt; &amp;listZone, <font class="keywordtype">bool</font> oversampling, <font class="keyword">const</font> CLightDesc &amp;lightDesc)
01714 {
01715         <font class="comment">// Bool visit</font>
01716         vector&lt;vector&lt;uint&gt; &gt; visited;
01717 
01718         <font class="comment">// Zone count</font>
01719         uint zoneCount=listZone.size();
01720 
01721         <font class="comment">// Resize arries</font>
01722         <a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>.resize (zoneCount);
01723         <a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>.resize (zoneCount);
01724         <a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>.resize (zoneCount);
01725         <a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>.resize (zoneCount);
01726 
01727         <font class="comment">// For each zone</font>
01728         <font class="keywordflow">for</font> (uint zone=0; zone&lt;zoneCount; zone++)
01729         {
01730                 <font class="comment">// Get num patches</font>
01731                 uint patchCount=landscape.getZone(listZone[zone])-&gt;getNumPatchs();
01732 
01733                 <font class="comment">// Insert zone id</font>
01734                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>.insert (map&lt;uint, uint&gt;::value_type (listZone[zone], zone));
01735 
01736                 <font class="comment">// This is the zone to light ?</font>
01737                 <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)
01738                 {
01739                         <font class="comment">// Resize the arraies</font>
01740                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>.resize(patchCount);
01741 <font class="comment">//                      _BezierPatch.resize(patchCount);</font>
01742                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>.resize(patchCount);
01743                         visited.resize(patchCount);
01744                 }
01745 
01746                 <font class="comment">// Common arries</font>
01747                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zone].resize(patchCount);
01748                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zone].resize(patchCount);
01749                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zone].resize(patchCount);
01750                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zone].resize(patchCount);
01751 
01752                 <font class="comment">// For each patch</font>
01753                 uint patch;
01754                 <font class="keywordflow">for</font> (patch=0; patch&lt;patchCount; patch++)
01755                 {
01756                         <font class="comment">// Get a patch pointer</font>
01757                         <font class="keyword">const</font> CPatch* pPatch=(const_cast&lt;const CZone*&gt;(landscape.getZone(listZone[zone])))-&gt;getPatch (patch);
01758 
01759                         <font class="comment">// Progress bar</font>
01760                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Scan all patches"</font>, (<font class="keywordtype">float</font>)patch/(<font class="keywordtype">float</font>)patchCount);
01761 
01762                         <font class="comment">// Get pointer on arries</font>
01763                         vector&lt;bool&gt; &amp;binded=<a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zone][patch];
01764                         vector&lt;CPatch::CBindInfo&gt; &amp;bindInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zone][patch];
01765                         vector&lt;CPatchUVLocator&gt; &amp;locator=<a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zone][patch];
01766                         CBezierPatch &amp;bezierPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zone][patch];
01767                         binded.resize (4, <font class="keyword">false</font>);
01768                         bindInfo.resize (4);
01769                         locator.resize (4);
01770 
01771                         <font class="comment">// Contruct the patch</font>
01772                         bezierPatch=*pPatch-&gt;unpackIntoCache();
01773 
01774                         <font class="comment">// Same zone ?</font>
01775                         <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)
01776                         {
01777                                 <font class="comment">// oversample this edge</font>
01778                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch].resize (4, <font class="keyword">false</font>);
01779                         }
01780 
01781                         <font class="comment">// *** Build bind info</font>
01782 
01783                         <font class="comment">// *** Build neighboorhood information</font>
01784                         uint edge;
01785                         <font class="keywordflow">for</font> (edge=0; edge&lt;4; edge++)
01786                         {
01787                                 <font class="comment">// Bond neighbor</font>
01788                                 pPatch-&gt;getBindNeighbor (edge, bindInfo[edge]);
01789 
01790                                 <font class="comment">// Patch binded</font>
01791                                 <font class="keywordflow">if</font> (bindInfo[edge].NPatchs&gt;0)
01792                                 {
01793                                         <font class="comment">// This edeg is binded</font>
01794                                         binded[edge]=<font class="keyword">true</font>;
01795 
01796                                         <font class="comment">// Same zone ?</font>
01797                                         <font class="keywordflow">if</font> ((listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)&amp;&amp;(bindInfo[edge].Zone-&gt;getZoneId()!=<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>))
01798                                         {
01799                                                 <font class="comment">// oversample this edge</font>
01800                                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch][edge]=<font class="keyword">true</font>;
01801                                         }
01802                                         locator[edge].build (pPatch, edge, bindInfo[edge]);
01803                                 }
01804                                 <font class="keywordflow">else</font>
01805                                 {
01806                                         <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)
01807                                         {
01808                                                 <font class="comment">// oversample this edge</font>
01809                                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o30">_OversampleEdges</a>[patch][edge]=<font class="keyword">true</font>;
01810                                         }
01811                                 }
01812                         }
01813 
01814                         <font class="comment">// This is the zone to light ?</font>
01815                         <font class="keywordflow">if</font> (listZone[zone]==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)
01816                         {
01817                                 <font class="comment">// *** Resize lumel array for this patch</font>
01818 
01819                                 <font class="comment">// Get patch order</font>
01820                                 uint orderS=pPatch-&gt;getOrderS();
01821                                 uint orderT=pPatch-&gt;getOrderT();
01822 
01823                                 <font class="comment">// Number of lumels</font>
01824                                 uint lumelCount=orderS*orderT*16;
01825 
01826                                 <font class="comment">// Resize the lumel descriptor</font>
01827                                 CLumelDescriptor descriptor;
01828                                 descriptor.Normal.set (0,0,0);
01829                                 descriptor.Position.set (0,0,0);
01830                                 descriptor.S=0;
01831                                 descriptor.T=0;
01832                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch].resize (lumelCount, descriptor);
01833                                 visited[patch].resize (lumelCount, 0);
01834 
01835                                 <font class="comment">// *** Unexclude this patch</font>
01836 
01837                                 <font class="comment">// Exclude all the patches from refine all</font>
01838                                 landscape.excludePatchFromRefineAll (listZone[zone], patch, <font class="keyword">false</font>);
01839                         }
01840                         <font class="keywordflow">else</font>
01841                         {
01842                                 <font class="comment">// Exclude all the patches from refine all</font>
01843                                 landscape.excludePatchFromRefineAll (listZone[zone], patch, <font class="keyword">true</font>);
01844                         }
01845                 }
01846         }
01847 
01848         <font class="comment">// *** Now tesselate this zone to shadow accuracy</font>
01849 
01850         <font class="comment">// Setup the landscape</font>
01851         landscape.setThreshold (0);
01852         landscape.setTileMaxSubdivision (0);
01853 
01854         <font class="comment">// Refine all</font>
01855         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Refine landscape to shadow accuracy"</font>, 0.5f);
01856         landscape.refineAll (CVector (0, 0, 0));
01857 
01858         <font class="comment">// Get tesselated faces</font>
01859         std::vector&lt;const CTessFace*&gt; leaves;
01860         landscape.getTessellationLeaves(leaves);
01861         
01862 
01863         
01864         
01865         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.size() != 0) <font class="comment">// any water shape in this zone ?</font>
01866         {
01868                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c18">makeQuadGridFromWaterShapes</a>(landscape.getZone(_ZoneToLight)-&gt;getZoneBB().getAABBox());
01869 
01871                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c19">computeTileFlagsForPositionTowardWater</a>(lightDesc, leaves);
01872         }
01873         <font class="keywordflow">else</font>
01874         {
01875                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c20">setTileFlagsToDefault</a>(leaves);
01876         }
01877         
01878 
01879         <font class="comment">// Id of this zone in the array</font>
01880         uint zoneNumber=<a class="code" href="classNL3D_1_1CZoneLighter.html#o31">_ZoneId</a>[<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>];
01881 
01882         <font class="comment">// Scan each leaves</font>
01883         uint leavesCount=leaves.size();
01884         uint leave;
01885         <font class="keywordflow">for</font> (leave=0; leave&lt;leavesCount; leave++)
01886         {
01887                 <font class="comment">// Progress bar</font>
01888                 <font class="keywordflow">if</font> ( (leave&amp;0xff) == 0)
01889                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Precompute lumel position"</font>, (<font class="keywordtype">float</font>)leave/(<font class="keywordtype">float</font>)leavesCount);
01890 
01891                 <font class="comment">// Leave</font>
01892                 <font class="keyword">const</font> CTessFace *face=leaves[leave];
01893 
01894                 <font class="comment">// Get zone id</font>
01895                 <font class="keywordflow">if</font> (face-&gt;Patch-&gt;getZone()-&gt;getZoneId()==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)
01896                 {
01897                         <font class="comment">// Get a patch pointer</font>
01898                         <font class="keyword">const</font> CPatch* pPatch=face-&gt;Patch;
01899 
01900                         <font class="comment">// Get order</font>
01901                         uint orderS=pPatch-&gt;getOrderS();
01902                         uint orderT=pPatch-&gt;getOrderT();
01903 
01904                         <font class="comment">// *** Base Coordinates</font>
01905                         CVector pos[14];
01906                         pos[0]=face-&gt;VBase-&gt;EndPos;             <font class="comment">// p0</font>
01907                         pos[1]=face-&gt;VRight-&gt;EndPos;
01908                         pos[2]=face-&gt;VLeft-&gt;EndPos;             <font class="comment">// p2</font>
01909                         pos[3]=(pos[1]+pos[2])/2;
01910                         pos[4]=(pos[0]+pos[1])/2;                               <font class="comment">// p4</font>
01911                         pos[5]=(pos[0]+pos[2])/2;
01912                         pos[6]=(pos[0]+pos[3])/2;                               <font class="comment">// p6</font>
01913                         pos[7]=(pos[2]+pos[3])/2;
01914                         pos[8]=(pos[1]+pos[3])/2;                               <font class="comment">// p8</font>
01915                         pos[9]=(pos[0]+pos[4])/2;
01916                         pos[10]=(pos[1]+pos[4])/2;                              <font class="comment">// p10</font>
01917                         pos[11]=(pos[0]+pos[5])/2;
01918                         pos[12]=(pos[2]+pos[5])/2;                              <font class="comment">// p12</font>
01919                         pos[13]=(pos[3]+pos[5])/2;
01920                         pos[14]=(pos[3]+pos[4])/2;                              <font class="comment">// p14</font>
01921 
01922                         <font class="keywordtype">float</font> s0=face-&gt;PVBase.getS();
01923                         <font class="keywordtype">float</font> s1=face-&gt;PVRight.getS();
01924                         <font class="keywordtype">float</font> s2=face-&gt;PVLeft.getS();
01925                         <font class="keywordtype">float</font> s3=(s1+s2)/2;
01926                         <font class="keywordtype">float</font> s4=(s0+s1)/2;
01927                         <font class="keywordtype">float</font> s5=(s0+s2)/2;
01928                         <font class="keywordtype">float</font> s6=(s4+s5)/2;
01929                         <font class="keywordtype">float</font> s7=(s2+s3)/2;
01930                         <font class="keywordtype">float</font> s8=(s1+s3)/2;
01931 
01932                         <font class="keywordtype">float</font> t0=face-&gt;PVBase.getT();
01933                         <font class="keywordtype">float</font> t1=face-&gt;PVRight.getT();
01934                         <font class="keywordtype">float</font> t2=face-&gt;PVLeft.getT();
01935                         <font class="keywordtype">float</font> t3=(t1+t2)/2;
01936                         <font class="keywordtype">float</font> t4=(t0+t1)/2;
01937                         <font class="keywordtype">float</font> t5=(t0+t2)/2;
01938                         <font class="keywordtype">float</font> t6=(t4+t5)/2;
01939                         <font class="keywordtype">float</font> t7=(t2+t3)/2;
01940                         <font class="keywordtype">float</font> t8=(t1+t3)/2;
01941 
01942                         <font class="comment">// *** Interpolated value</font>
01943                         CVector interpolatedP[10]=
01944                         {
01945                                 (pos[0]+pos[6])/2,
01946                                 (pos[4]+pos[6])/2,
01947                                 (pos[4]+pos[8])/2,
01948                                 (pos[1]+pos[8])/2,
01949                                 (pos[5]+pos[6])/2,
01950                                 (pos[3]+pos[6])/2,
01951                                 (pos[3]+pos[8])/2,
01952                                 (pos[5]+pos[7])/2,
01953                                 (pos[3]+pos[7])/2,
01954                                 (pos[2]+pos[7])/2,
01955                         };
01956                         
01957                         <font class="keywordtype">float</font> interpolatedS[10]=
01958                         {
01959                                 (s0+s6)/2,
01960                                 (s4+s6)/2,
01961                                 (s4+s8)/2,
01962                                 (s1+s8)/2,
01963                                 (s5+s6)/2,
01964                                 (s3+s6)/2,
01965                                 (s3+s8)/2,
01966                                 (s5+s7)/2,
01967                                 (s3+s7)/2,
01968                                 (s2+s7)/2,
01969                         };
01970                         
01971                         <font class="keywordtype">float</font> interpolatedT[10]=
01972                         {
01973                                 (t0+t6)/2,
01974                                 (t4+t6)/2,
01975                                 (t4+t8)/2,
01976                                 (t1+t8)/2,
01977                                 (t5+t6)/2,
01978                                 (t3+t6)/2,
01979                                 (t3+t8)/2,
01980                                 (t5+t7)/2,
01981                                 (t3+t7)/2,
01982                                 (t2+t7)/2,
01983                         };
01984 
01985                         <font class="keyword">static</font> sint8 triangle[10][2][3]=
01986                         {
01987                                 {{0, 11, 6}, {0, 6, 9}},
01988                                 {{9, 6, 4}, {4, 6, 14}},
01989                                 {{4, 14, 8}, {4, 8, 10}},
01990                                 {{10, 8, 1}, {-1, -1, -1}},
01991                                 {{11, 5, 6}, {5, 13, 6}},
01992                                 {{6, 13, 3}, {6, 3, 14}},
01993                                 {{3, 8, 14}, {-1, -1, -1}},
01994                                 {{5, 12, 7}, {5, 7, 13}},
01995                                 {{7, 3, 13}, {-1, -1, -1}},
01996                                 {{12, 2, 7}, {-1, -1, -1}}
01997                         };
01998 
01999                         <font class="keywordflow">for</font> (uint i=0; i&lt;10; i++)
02000                         {
02001                                 uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=(uint)((float)orderS*4*interpolatedS[i]);
02002                                 uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=(uint)((float)orderT*4*interpolatedT[i]);
02003 
02004                                 <font class="comment">/*nlassert (s&gt;=0);</font>
02005 <font class="comment">                                nlassert (s&lt;orderS*4);</font>
02006 <font class="comment">                                nlassert (t&gt;=0);</font>
02007 <font class="comment">                                nlassert (t&lt;orderT*4);*/</font>
02008 
02009                                 <font class="keywordflow">if</font> ((<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&gt;=0)&amp;&amp;(s&lt;orderS*4)&amp;&amp;(t&gt;=0)&amp;&amp;(<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;orderT*4))
02010                                 {
02011                                         <font class="comment">// Triangle index</font>
02012                                         uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</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>*orderS*4;
02013 
02014                                         <font class="comment">// Ge tthe patch id</font>
02015                                         uint patchId=pPatch-&gt;getPatchId();
02016 
02017                                         <font class="comment">// Get lumel array</font>
02018                                         vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patchId];
02019 
02020                                         <font class="comment">// Visited</font>
02021                                         visited[patchId][<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
02022 
02023                                         <font class="comment">// Position</font>
02024                                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].Position+=interpolatedP[i];
02025 
02026                                         <font class="comment">// Triangle</font>
02027                                         <font class="keywordflow">if</font> (oversampling)
02028                                         {
02029                                                 <font class="comment">// Triangle list</font>
02030                                                 CTriangleList *next=lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList;
02031 
02032                                                 <font class="comment">// What triangle ?</font>
02033                                                 uint numTriangle;
02034                                                 <font class="keywordflow">switch</font> (i)
02035                                                 {
02036                                                 <font class="keywordflow">case</font> 3:
02037                                                 <font class="keywordflow">case</font> 6:
02038                                                 <font class="keywordflow">case</font> 8:
02039                                                 <font class="keywordflow">case</font> 9:
02040                                                         <font class="comment">// Single triangle</font>
02041                                                         numTriangle=1;
02042                                                         <font class="keywordflow">break</font>;
02043                                                 <font class="keywordflow">default</font>:
02044                                                         <font class="comment">// Two triangles</font>
02045                                                         numTriangle=2;
02046                                                         <font class="keywordflow">break</font>;
02047                                                 }
02048 
02049                                                 <font class="comment">// Add triangles</font>
02050                                                 <font class="keywordflow">for</font> (uint tri=0; tri&lt;numTriangle; tri++)
02051                                                 {
02052                                                         <font class="comment">// one triangle</font>
02053                                                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList=<a class="code" href="classNL3D_1_1CZoneLighter.html#o36">_TriangleListAllocateur</a>.<a class="code" href="classNLMISC_1_1CPoolMemory.html#a1">allocate</a> ();
02054                                                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList-&gt;Triangle=<a class="code" href="classNLMISC_1_1CTriangle.html">NLMISC::CTriangle</a> (pos[triangle[i][tri][0]], pos[triangle[i][tri][1]], pos[triangle[i][tri][2]]);
02055                                                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].TriangleList-&gt;Next=next;
02056                                                 }
02057                                         }
02058                                 }
02059                         }
02060                 }
02061         }
02062 
02063         <font class="comment">// *** Now, finalise patch informations for shadow source positions</font>
02064 
02065         <font class="comment">// For each patches</font>
02066         uint patchCount=landscape.getZone(_ZoneToLight)-&gt;getNumPatchs();
02067         uint patch;
02068         <font class="keywordflow">for</font> (patch=0; patch&lt;patchCount; patch++)
02069         {
02070                 <font class="comment">// Info</font>
02071                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Finalize lumel positions"</font>, (<font class="keywordtype">float</font>)patch/(<font class="keywordtype">float</font>)patchCount);
02072 
02073                 <font class="comment">// *** Resize lumel array for this patch</font>
02074 
02075                 <font class="comment">// Get a patch pointer</font>
02076                 <font class="keyword">const</font> CPatch* pPatch=(const_cast&lt;const CZone*&gt;(landscape.getZone(<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)))-&gt;getPatch (patch);
02077                 uint orderS=pPatch-&gt;getOrderS();
02078                 uint orderT=pPatch-&gt;getOrderT();
02079 
02080                 <font class="comment">// Get lumel array</font>
02081                 vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch];
02082 
02083                 <font class="comment">// *** Compute an interpolated normal</font>
02084 
02085                 <font class="comment">// Renormalize</font>
02086                 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderS));
02087                 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderT));
02088                 uint powerS=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderS);
02089                 uint powerT=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderT);
02090                 uint lumelS=4&lt;&lt;powerS;
02091                 uint lumelT=4&lt;&lt;powerT;
02092 
02093                 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;lumelT; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++)
02094                 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&lt;lumelS; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++)
02095                 {
02096                         <font class="comment">// Lumel index</font>
02097                         uint lumelIndex=<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>*lumelS;
02098 
02099                         <font class="comment">// *** Number of visit</font>
02100                         uint visitedCount=visited[patch][lumelIndex];
02101                         
02102                         <font class="comment">// Some lumel have not been found in tesselation</font>
02103                         <font class="comment">//nlassert ((visitedCount==1)||(visitedCount==2));</font>
02104 
02105                         <font class="comment">// If visited, renormalise other values</font>
02106                         <font class="keywordflow">if</font> (visitedCount)
02107                         {
02108                                 <font class="comment">// Normalise position</font>
02109                                 lumels[lumelIndex].Position/=(float)visitedCount;
02110                         }
02111 
02112                         <font class="comment">// Not visited for next pass</font>
02113                         visited[patch][lumelIndex]=<font class="keyword">false</font>;
02114                 }
02115         }
02116 
02117         <font class="comment">// *** Now tesselate this zone to shadow accuracy</font>
02118 
02119         <font class="comment">// Setup the landscape</font>
02120         landscape.setThreshold (0);
02121         landscape.setTileMaxSubdivision (4);
02122 
02123         <font class="comment">// Refine all</font>
02124         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Refine landscape to lumels"</font>, 0.5f);
02125         landscape.refineAll (CVector (0, 0, 0));
02126 
02127         <font class="comment">// Get tesselated faces</font>
02128         leaves.clear ();
02129         landscape.getTessellationLeaves(leaves);
02130 
02131         <font class="comment">// Scan each leaves</font>
02132         leavesCount=leaves.size();
02133         <font class="keywordflow">for</font> (leave=0; leave&lt;leavesCount; leave++)
02134         {
02135                 <font class="comment">// Progress bar</font>
02136                 <font class="keywordflow">if</font> ( (leave&amp;0xff) == 0)
02137                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Precompute tesselation"</font>, (<font class="keywordtype">float</font>)leave/(<font class="keywordtype">float</font>)leavesCount);
02138 
02139                 <font class="comment">// Leave</font>
02140                 <font class="keyword">const</font> CTessFace *face=leaves[leave];
02141 
02142                 <font class="comment">// Get zone id</font>
02143                 <font class="keywordflow">if</font> (face-&gt;Patch-&gt;getZone()-&gt;getZoneId()==<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)
02144                 {
02145                         <font class="comment">// Get a patch pointer</font>
02146                         <font class="keyword">const</font> CPatch* pPatch=face-&gt;Patch;
02147 
02148                         <font class="comment">// Get order</font>
02149                         uint orderS=pPatch-&gt;getOrderS();
02150                         uint orderT=pPatch-&gt;getOrderT();
02151 
02152                         <font class="comment">// Coordinates</font>
02153                         <font class="keywordtype">float</font> fS=(face-&gt;PVBase.getS()+face-&gt;PVLeft.getS()+face-&gt;PVRight.getS())/3.f;
02154                         <font class="keywordtype">float</font> fT=(face-&gt;PVBase.getT()+face-&gt;PVLeft.getT()+face-&gt;PVRight.getT())/3.f;
02155                         uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=(uint)((float)orderS*4*fS);
02156                         uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=(uint)((float)orderT*4*fT);
02157                         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&gt;=0);
02158                         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&lt;orderS*4);
02159                         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&gt;=0);
02160                         <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;orderT*4);
02161 
02162                         <font class="comment">// Triangle index</font>
02163                         uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</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>*orderS*4;
02164 
02165                         <font class="comment">// Ge tthe patch id</font>
02166                         uint patchId=pPatch-&gt;getPatchId();
02167 
02168                         <font class="comment">// Get lumel array</font>
02169                         vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patchId];
02170 
02171                         <font class="comment">// Visited</font>
02172                         visited[patchId][<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>]++;
02173 
02174                         <font class="comment">// Lumel s and t</font>
02175                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].S+=fS;
02176                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].T+=fT;
02177 
02178                         <font class="comment">// Normal</font>
02179                         CPlane plane;
02180                         plane.make (face-&gt;VBase-&gt;EndPos, face-&gt;VLeft-&gt;EndPos, face-&gt;VRight-&gt;EndPos);
02181                         lumels[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>].Normal+=plane.getNormal();
02182                 }
02183         }
02184 
02185         <font class="comment">// *** Now, finalise patch informations</font>
02186 
02187         <font class="comment">// For each patches</font>
02188         patchCount=landscape.getZone(_ZoneToLight)-&gt;getNumPatchs();
02189         <font class="keywordflow">for</font> (patch=0; patch&lt;patchCount; patch++)
02190         {
02191                 <font class="comment">// Info</font>
02192                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Finalize patches"</font>, (<font class="keywordtype">float</font>)patch/(<font class="keywordtype">float</font>)patchCount);
02193 
02194                 <font class="comment">// *** Resize lumel array for this patch</font>
02195 
02196                 <font class="comment">// Get a patch pointer</font>
02197                 <font class="keyword">const</font> CPatch* pPatch=(const_cast&lt;const CZone*&gt;(landscape.getZone(<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>)))-&gt;getPatch (patch);
02198                 uint orderS=pPatch-&gt;getOrderS();
02199                 uint orderT=pPatch-&gt;getOrderT();
02200 
02201                 <font class="comment">// Get lumel array</font>
02202                 vector&lt;CLumelDescriptor&gt; &amp;lumels=<a class="code" href="classNL3D_1_1CZoneLighter.html#o25">_Lumels</a>[patch];
02203 
02204                 <font class="comment">// *** Compute an interpolated normal</font>
02205 
02206                 <font class="comment">// Get pointer on arries</font>
02207                 vector&lt;bool&gt; &amp;binded=<a class="code" href="classNL3D_1_1CZoneLighter.html#o29">_Binded</a>[zoneNumber][patch];
02208                 vector&lt;CPatchUVLocator&gt; &amp;locator=<a class="code" href="classNL3D_1_1CZoneLighter.html#o27">_Locator</a>[zoneNumber][patch];
02209                 vector&lt;CPatch::CBindInfo&gt; &amp;bindInfo=<a class="code" href="classNL3D_1_1CZoneLighter.html#o28">_BindInfo</a>[zoneNumber][patch];
02210                 CBezierPatch &amp;bezierPatch=<a class="code" href="classNL3D_1_1CZoneLighter.html#o26">_BezierPatch</a>[zoneNumber][patch];
02211 
02212                 <font class="comment">// Renormalize</font>
02213                 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderS));
02214                 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="namespaceNLMISC.html#a225">isPowerOf2</a> (orderT));
02215                 uint powerS=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderS);
02216                 uint powerT=<a class="code" href="namespaceNLMISC.html#a224">getPowerOf2</a> (orderT);
02217                 uint lumelS=4&lt;&lt;powerS;
02218                 uint lumelT=4&lt;&lt;powerT;
02219 
02220                 <font class="comment">// Sample edge normal</font>
02221                 CVector normals[<a class="code" href="patch_8h.html#a1">NL_MAX_TILES_BY_PATCH_EDGE</a>*<a class="code" href="patch_8h.html#a7">NL_LUMEL_BY_TILE</a>+1][4];
02222                 uint sFixed[4] = { 0, 0xffffffff, lumelS-1, 0xffffffff };
02223                 uint tFixed[4] = { 0xffffffff, lumelT-1, 0xffffffff, 0 };
02224                 <font class="keywordtype">float</font> sOri[4] = { 0, -1, (float)lumelS, -1 };
02225                 <font class="keywordtype">float</font> tOri[4] = { -1, (float)lumelT, -1, 0 };
02226                 <font class="keywordflow">for</font> (uint edge=0; edge&lt;4; edge++)
02227                 {
02228                         <font class="comment">// s and t</font>
02229                         uint count=(edge&amp;1)?lumelS:lumelT;
02230                         <font class="keywordflow">for</font> (uint lumel=0; lumel&lt;=count; lumel++)
02231                         {
02232                                 <font class="comment">// Start coordinates</font>
02233                                 <font class="keywordtype">float</font> origineS;
02234                                 <font class="keywordtype">float</font> origineT;
02235                                 uint startS;
02236                                 uint startT;
02237                                 <font class="keywordflow">if</font> (edge&amp;1)
02238                                 {
02239                                         <font class="keywordflow">if</font> (lumel==count)
02240                                                 startS=count-1;
02241                                         <font class="keywordflow">else</font>
02242                                                 startS=lumel;
02243                                         startT=tFixed[edge];
02244                                         origineS=(float)lumel;
02245                                         origineT=tOri[edge];
02246                                 }
02247                                 <font class="keywordflow">else</font>
02248                                 {
02249                                         <font class="keywordflow">if</font> (lumel==count)
02250                                                 startT=count-1;
02251                                         <font class="keywordflow">else</font>
02252                                                 startT=lumel;
02253                                         startS=sFixed[edge];
02254                                         origineT=(float)lumel;
02255                                         origineS=sOri[edge];
02256                                 }
02257                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>=CVector::Null;
02258                                 set&lt;uint64&gt; visitedLumels;
02259                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c10">getNormal</a> (pPatch, startS, startT, locator, bindInfo, binded, visitedLumels, 
02260                                         startS+0.5f-origineS, startT+0.5f-origineT, 0, bezierPatch);
02261                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>.<a class="code" href="classNLMISC_1_1CVector.html#z331_4">normalize</a> ();
02262                                 normals[lumel][edge]=<a class="code" href="classNL3D_1_1CZoneLighter.html#o33">_GetNormalNormal</a>;
02263                         }
02264 
02265                         <font class="comment">// Smooth the corners</font>
02266 <font class="preprocessor">#define BLUR_SIZE 4</font>
02267 <font class="preprocessor"></font>                        <font class="keywordflow">for</font> (uint i=1; i&lt;BLUR_SIZE; i++)
02268                         {
02269                                 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=(float)i/BLUR_SIZE;
02270                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02271                                 normals[i][edge]=normals[0][edge]*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)+normals[i][edge]*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>;
02272                                 normals[i][edge].normalize();
02273                                 normals[count-i][edge]=normals[count][edge]*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)+normals[count-i][edge]*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>;
02274                                 normals[count-i][edge].normalize();
02275                         }
02276                 }
02277                 
02278                 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;lumelT; <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>++)
02279                 <font class="keywordflow">for</font> (uint <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&lt;lumelS; <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>++)
02280                 {
02281                         <font class="comment">// Lumel index</font>
02282                         uint lumelIndex=<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>*lumelS;
02283 
02284                         <font class="comment">// *** Calc the smoothed normal</font>
02285                         
02286                         <font class="comment">// For each edge</font>
02287                         CVector normalS=bezierPatch.evalNormal (((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f)/(<font class="keywordtype">float</font>)lumelS, ((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f)/(<font class="keywordtype">float</font>)lumelT);
02288                         <font class="keywordtype">float</font> sFactor=0;
02289                         CVector normalT=normalS;
02290                         <font class="keywordtype">float</font> tFactor=0;
02291                         <font class="keywordtype">bool</font> sGood=<font class="keyword">false</font>, tGood=<font class="keyword">false</font>;
02292                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&lt;BLUR_SIZE)
02293                         {
02294                                 sGood=<font class="keyword">true</font>;
02295                                 <font class="comment">// Average the two normals</font>
02296                                 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>][0];
02297                                 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+1][0];
02298                                 average/=2;
02299 
02300                                 <font class="comment">// Blend</font>
02301                                 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f;
02302                                 sFactor=BLUR_SIZE-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>;
02303                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>/=BLUR_SIZE;
02304                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02305                                 normalS=(normalS*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>));
02306                                 normalS.normalize();
02307                         }
02308                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>&gt;=lumelS-BLUR_SIZE)
02309                         {
02310                                 sGood=<font class="keyword">true</font>;
02311                                 <font class="comment">// Average the two normals</font>
02312                                 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>][2];
02313                                 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+1][2];
02314                                 average/=2;
02315 
02316                                 <font class="comment">// Blend</font>
02317                                 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f;
02318                                 sFactor=BLUR_SIZE-(lumelS-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02319                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=(lumelS-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)/BLUR_SIZE;
02320                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02321                                 normalS=(normalS*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>));
02322                                 normalS.normalize();
02323                         }
02324                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&lt;BLUR_SIZE)
02325                         {
02326                                 tGood=<font class="keyword">true</font>;
02327                                 <font class="comment">// Average the two normals</font>
02328                                 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>][3];
02329                                 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1][3];
02330                                 average/=2;
02331 
02332                                 <font class="comment">// Blend</font>
02333                                 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f;
02334                                 tFactor=BLUR_SIZE-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>;
02335                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>/=BLUR_SIZE;
02336                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02337                                 normalT=(normalT*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>));
02338                                 normalT.normalize();
02339                         }
02340                         <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>&gt;=lumelT-BLUR_SIZE)
02341                         {
02342                                 tGood=<font class="keyword">true</font>;
02343                                 <font class="comment">// Average the two normals</font>
02344                                 CVector average=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>][1];
02345                                 average+=normals[<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+1][1];
02346                                 average/=2;
02347 
02348                                 <font class="comment">// Blend</font>
02349                                 <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f;
02350                                 tFactor=BLUR_SIZE-(lumelT-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02351                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=((lumelT)-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>)/BLUR_SIZE;
02352                                 <a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>=<a class="code" href="zone__lighter_8cpp.html#a8">easineasout</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>);
02353                                 normalT=(normalT*<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>+average*(1-<a class="code" href="driver__opengl__extension__def_8h.html#a415">value</a>));
02354                                 normalT.normalize();
02355                         }
02356 
02357                         <font class="comment">// The smooth normal</font>
02358                         CVector smoothNormal;
02359 
02360                         <font class="keywordflow">if</font> ((sGood)&amp;&amp;(tGood))
02361                         {
02362                                 <font class="keywordflow">if</font> ((sFactor!=BLUR_SIZE)||(tFactor!=BLUR_SIZE))
02363                                         smoothNormal=normalS*(BLUR_SIZE-tFactor)+normalT*(BLUR_SIZE-sFactor);
02364                                 <font class="keywordflow">else</font>
02365                                         smoothNormal=normalS+normalT;
02366                         }
02367                         <font class="keywordflow">else</font> <font class="keywordflow">if</font> (sGood)
02368                                 smoothNormal=normalS;
02369                         <font class="keywordflow">else</font>
02370                                 smoothNormal=normalT;
02371 
02372                         <font class="comment">// Normalize it</font>
02373                         smoothNormal.normalize();
02374 
02375                         <font class="comment">// The pure normal</font>
02376                         CVector purNormal=bezierPatch.evalNormal (((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>+0.5f)/(<font class="keywordtype">float</font>)lumelS, ((<font class="keywordtype">float</font>)<a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>+0.5f)/(<font class="keywordtype">float</font>)lumelT);
02377 
02378                         <font class="comment">// Normalize the noisy normal</font>
02379                         lumels[lumelIndex].Normal.normalize();
02380 
02381                         <font class="comment">// Final normal</font>
02382                         lumels[lumelIndex].Normal=lumels[lumelIndex].Normal-purNormal+smoothNormal;
02383                         lumels[lumelIndex].Normal.normalize ();
02384 
02385                         <font class="comment">// *** Number of visit</font>
02386                         uint visitedCount=visited[patch][lumelIndex];
02387                         
02388                         <font class="comment">// Some lumel have not been found in tesselation</font>
02389                         <font class="comment">//nlassert (visitedCount==2);</font>
02390 
02391                         <font class="comment">// If visited, renormalise other values</font>
02392                         <font class="keywordflow">if</font> (visitedCount)
02393                         {
02394                                 <font class="comment">// Normalise position</font>
02395                                 lumels[lumelIndex].S/=(float)visitedCount;
02396                                 lumels[lumelIndex].T/=(float)visitedCount;
02397                         }
02398                 }
02399         }
02400 }
02401 
02402 <font class="comment">// ***************************************************************************</font>
02403 
<a name="l02404"></a><a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#a0">02404</a> CZoneLighter::CLightDesc::CLightDesc ()
02405 {
02406         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m0">LightDirection</a>.<a class="code" href="classNLMISC_1_1CVector.html#z332_0">set</a> (1, 1, -1);
02407         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m2">GridSize</a>=512;
02408         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m3">GridCellSize</a>=4;
02409         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m4">HeightfieldSize</a>=200;
02410         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m5">HeightfieldCellSize</a>=20;
02411         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m13">SkyContribution</a>=<font class="keyword">true</font>;
02412         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m14">SkyIntensity</a>=0.25;
02413         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m7">ShadowBias</a>=0.5f;
02414         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m9">SoftshadowBlurSize</a>=1.f;
02415         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m10">SoftshadowFallof</a>=10.f;
02416         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m11">SoftshadowShapeVertexCount</a>=4;
02417         <a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#m1">Oversampling</a>=<a class="code" href="classNL3D_1_1CZoneLighter_1_1CLightDesc.html#s5s3">OverSamplingx32</a>;
02418 }
02419 
02420 <font class="comment">// ***************************************************************************</font>
<a name="l02421"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a6">02421</a> <font class="keywordtype">void</font> CZoneLighter::addLightableShape(IShape *shape, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a>&amp; MT)
02422 {
02423         CShapeInfo lsi;
02424         lsi.MT = MT;
02425         lsi.Shape = shape;
02426         <a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.push_back(lsi);
02427 }
02428 
02429 
02430 <font class="comment">// ***************************************************************************</font>
<a name="l02431"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#d0">02431</a> <font class="keywordtype">bool</font> CZoneLighter::isLightableShape(IShape &amp;shape)
02432 {
02434         <font class="keywordflow">if</font> (dynamic_cast&lt;CWaterShape *&gt;(&amp;shape) != NULL)
02435         {
02436                 <font class="comment">// check that this water surface has a diffuse map that is a CTextureFile (we must be able to save it !)</font>
02437                 CWaterShape *ws = static_cast&lt;CWaterShape *&gt;(&amp;shape);
02438                 <font class="keyword">const</font> ITexture *tex = ws-&gt;getColorMap();
02439                 <font class="keywordflow">if</font> (dynamic_cast&lt;const CTextureFile *&gt;(tex) != NULL)
02440                 {
02441                         <font class="keywordflow">return</font> ws-&gt;isLightMappingEnabled();
02442                 }
02443         }
02444         <font class="keywordflow">return</font> <font class="keyword">false</font>;
02445 }
02446 
02447 <font class="comment">// ***************************************************************************</font>
<a name="l02448"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c14">02448</a> <font class="keywordtype">void</font> CZoneLighter::lightShapes(uint zoneID, <font class="keyword">const</font> CLightDesc&amp; description)
02449 {
02451         <font class="keywordflow">if</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size() == 0) <font class="keywordflow">return</font>;       
02452 
02453         uint numShapePerThread = 1 + (<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size() / <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>);
02454         uint currShapeIndex = 0;
02455         uint process = 0;
02456         <a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a> = 0;
02457 
02458         <a class="code" href="classNL3D_1_1CZoneLighter.html#o39">_NumLightableShapesProcessed</a> = 0;
02459 
02460 
02461         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Processing lightable shapes"</font>, 0);
02462         
02463         <font class="keywordflow">for</font> (uint k = 0; k &lt; <a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size(); ++k, ++process)
02464         {
02465                 uint lastShapeIndex = currShapeIndex + numShapePerThread;
02466                 lastShapeIndex = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size(), lastShapeIndex);             
02467                 IThread *pThread = IThread::create (<font class="keyword">new</font> <a class="code" href="classNL3D_1_1CZoneLighter.html#l1">CCalcLightableShapeRunnable</a>(process, <font class="keyword">this</font>, &amp;description, &amp;<a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>, currShapeIndex, lastShapeIndex));
02468                 pThread-&gt;start();
02469                 currShapeIndex = lastShapeIndex;
02470         }
02471 
02473         <font class="keywordflow">while</font> (<a class="code" href="classNL3D_1_1CZoneLighter.html#o14">_ProcessExited</a> != <a class="code" href="classNL3D_1_1CZoneLighter.html#o12">_ProcessCount</a>)
02474         {
02475                 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (10);
02476         }
02477 
02478 }
02479 
02480 
02481 
02482 <font class="comment">// ***************************************************************************</font>
02483 
<a name="l02484"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c15">02484</a> <font class="keywordtype">void</font> CZoneLighter::processLightableShapeCalc (uint process,
02485                                                                                           TShapeVect *shapesToLit,
02486                                                                                           uint firstShape,
02487                                                                                           uint lastShape,
02488                                                                                           <font class="keyword">const</font> CLightDesc&amp; description)
02489 {
02490         CMultiShape *shapeArray=<font class="keyword">new</font> CMultiShape;
02491         CMultiShape *shapeArrayTmp=<font class="keyword">new</font> CMultiShape;
02492         shapeArray-&gt;Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>);
02493         shapeArrayTmp-&gt;Shapes.reserve (<a class="code" href="zone__lighter_8h.html#a1">SHAPE_MAX</a>);
02494 
02495         <font class="comment">// for each lightable shape</font>
02496         <font class="keywordflow">for</font> (uint k = firstShape; k &lt; lastShape; ++k)
02497         {               
02498                 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#d0">isLightableShape</a>(* (*shapesToLit)[k].Shape)); <font class="comment">// make sure it is a lightable shape             </font>
02499                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c16">lightSingleShape</a>((*shapesToLit)[k], *shapeArray, *shapeArrayTmp, description, process); 
02500         }
02501 
02502         <font class="keyword">delete</font> shapeArray;
02503         <font class="keyword">delete</font> shapeArrayTmp;   
02504 }
02505 
02506 
02507 <font class="comment">// ***************************************************************************</font>
<a name="l02508"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c16">02508</a> <font class="keywordtype">void</font> CZoneLighter::lightSingleShape(CShapeInfo &amp;si, CMultiShape &amp;shape, CMultiShape &amp;shapeTmp, <font class="keyword">const</font> CLightDesc&amp; description, uint cpu)
02509 {
02511         <font class="keywordflow">if</font> (dynamic_cast&lt;CWaterShape *&gt;(si.Shape))
02512         {
02513                 <a class="code" href="classNL3D_1_1CZoneLighter.html#c17">lightWater</a>(* static_cast&lt;CWaterShape *&gt;(si.Shape), si.MT, shape, shapeTmp, description, cpu);
02514                 
02515         }
02516         ++<a class="code" href="classNL3D_1_1CZoneLighter.html#o39">_NumLightableShapesProcessed</a>;
02517         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Processing lightable shapes"</font>, (<font class="keywordtype">float</font>) <a class="code" href="classNL3D_1_1CZoneLighter.html#o39">_NumLightableShapesProcessed</a> / <a class="code" href="classNL3D_1_1CZoneLighter.html#o38">_LightableShapes</a>.size());
02518         <font class="keywordflow">return</font>; 
02519 }
02520 
02521 
02522 
02523 <font class="comment">// ***************************************************************************</font>
02524 <font class="comment">// utility function to get the directory of a fileName</font>
<a name="l02525"></a><a class="code" href="zone__lighter_8cpp.html#a10">02525</a> <font class="keyword">static</font> std::string <a class="code" href="zone__lighter_8cpp.html#a10">getDir</a> (<font class="keyword">const</font> std::string&amp; path)
02526 {
02527         <font class="keywordtype">char</font> tmpPath[512];
02528         strcpy (tmpPath, path.c_str());
02529         <font class="keywordtype">char</font>* slash=strrchr (tmpPath, <font class="charliteral">'/'</font>);
02530         <font class="keywordflow">if</font> (!slash)
02531         {
02532                 slash=strrchr (tmpPath, <font class="charliteral">'\\'</font>);
02533         }
02534 
02535         <font class="keywordflow">if</font> (!slash)
02536                 <font class="keywordflow">return</font> <font class="stringliteral">""</font>;
02537 
02538         slash++;
02539         *slash=0;
02540         <font class="keywordflow">return</font> tmpPath;
02541 }
02542 
02543 
02544 <font class="comment">// ***************************************************************************</font>
02545 <font class="comment">// utility function to get a file name fdrom a path</font>
<a name="l02546"></a><a class="code" href="zone__lighter_8cpp.html#a11">02546</a> <font class="keyword">static</font> std::string <a class="code" href="zone__lighter_8cpp.html#a11">getName</a> (<font class="keyword">const</font> std::string&amp; path)
02547 {
02548         std::string dir=<a class="code" href="zone__lighter_8cpp.html#a10">getDir</a> (path);
02549 
02550         <font class="keywordtype">char</font> tmpPath[512];
02551         strcpy (tmpPath, path.c_str());
02552 
02553         <font class="keywordtype">char</font> *name=tmpPath;
02554         <a class="code" href="debug_8h.html#a6">nlassert</a> (dir.length()&lt;=strlen(tmpPath));
02555         name+=dir.length();
02556 
02557         <font class="keywordtype">char</font>* point=strrchr (name, <font class="charliteral">'.'</font>);
02558         <font class="keywordflow">if</font> (point)
02559                 *point=0;
02560 
02561         <font class="keywordflow">return</font> name;
02562 }
02563 
02564 
02565 <font class="comment">// ***************************************************************************</font>
02566 <font class="comment">// utility function to get the extension of a fileName</font>
<a name="l02567"></a><a class="code" href="zone__lighter_8cpp.html#a12">02567</a> <font class="keyword">static</font> std::string <a class="code" href="zone__lighter_8cpp.html#a12">getExt</a> (<font class="keyword">const</font> std::string&amp; path)
02568 {
02569         std::string dir = <a class="code" href="zone__lighter_8cpp.html#a10">getDir</a> (path);
02570         std::string name = <a class="code" href="zone__lighter_8cpp.html#a11">getName</a> (path);
02571 
02572         <font class="keywordtype">char</font> tmpPath[512];
02573         strcpy (tmpPath, path.c_str());
02574 
02575         <font class="keywordtype">char</font> *ext=tmpPath;
02576         <a class="code" href="debug_8h.html#a6">nlassert</a> (dir.length()+name.length()&lt;=strlen(tmpPath));
02577         ext+=dir.length()+name.length();
02578 
02579         <font class="keywordflow">return</font> ext;
02580 }
02581 
02582 
02583 <font class="comment">// ***************************************************************************</font>
<a name="l02584"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c17">02584</a> <font class="keywordtype">void</font> CZoneLighter::lightWater(CWaterShape &amp;ws, <font class="keyword">const</font> CMatrix &amp;MT, CMultiShape &amp;shape, CMultiShape &amp;shapeTmp, <font class="keyword">const</font> CLightDesc&amp; description, uint cpu)
02585 {       
02586         <font class="keywordflow">try</font>
02587         {       
02589                 CTextureFile *diffuseTex = NLMISC::safe_cast&lt;CTextureFile *&gt;(ws.getColorMap());
02590                 std::string texFileName = CPath::lookup(diffuseTex-&gt;getFileName());
02591                 diffuseTex-&gt;generate();
02592                 <font class="keyword">const</font> uint <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a> = diffuseTex-&gt;getWidth();
02593                 <font class="keyword">const</font> uint <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a> = diffuseTex-&gt;getHeight();    
02594                 
02596                 <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> worldSpaceToUVs;
02597                 <a class="code" href="classNLMISC_1_1CVector2f.html">NLMISC::CVector2f</a> col0, col1, pos;
02598                 ws.getColorMapMat(col0, col1, pos);
02599                 worldSpaceToUVs.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_1">setRot</a>(<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(col0.<a class="code" href="classNLMISC_1_1CVector2f.html#m0">x</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, col0.<a class="code" href="classNLMISC_1_1CVector2f.html#m1">y</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, 0),
02600                                                            <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(col1.<a class="code" href="classNLMISC_1_1CVector2f.html#m0">x</a> * width, col1.<a class="code" href="classNLMISC_1_1CVector2f.html#m1">y</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, 0),
02601                                                            <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>);
02602                 worldSpaceToUVs.<a class="code" href="classNLMISC_1_1CMatrix.html#z290_6">setPos</a>(<a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>(pos.<a class="code" href="classNLMISC_1_1CVector2f.html#m0">x</a> * width, pos.<a class="code" href="classNLMISC_1_1CVector2f.html#m1">y</a> * <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>, 0));              
02603 
02605                 <a class="code" href="classNLMISC_1_1CPolygon.html">NLMISC::CPolygon</a> p;
02606                 ws.getShapeInWorldSpace(p);
02607 
02608                 <font class="keywordtype">float</font> minU, maxU;
02609                 <font class="keywordtype">float</font> minV, maxV;
02610 
02611                 <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> uvs = worldSpaceToUVs * p.<a class="code" href="classNLMISC_1_1CPolygon.html#m0">Vertices</a>[0];
02612                 minU = maxU = uvs.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>;
02613                 minV = maxV = uvs.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>;
02614 
02615 
02616                 <font class="keywordflow">for</font> (uint k = 1; k &lt; (uint) p.<a class="code" href="classNLMISC_1_1CPolygon.html#a2">getNumVertices</a>(); ++k)
02617                 {
02618                         uvs = worldSpaceToUVs * p.<a class="code" href="classNLMISC_1_1CPolygon.html#m0">Vertices</a>[k];
02619                         minU = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, minU);
02620                         minV = <a class="code" href="bit__set_8cpp.html#a0">std::min</a>(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, minV);
02621                         maxU = std::max(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, maxU);
02622                         maxV = std::max(uvs.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>, maxV);   
02623                 }
02624                 
02625                 
02626         
02627 
02628                 sint iMinU = (sint) minU;
02629                 sint iMaxU = (sint) maxU;
02630                 sint iMinV = (sint) minV;
02631                 sint iMaxV = (sint) maxV;
02632 
02633                 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMinU, 0, (sint) width);
02634                 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMaxU, 0, (sint) width);
02635                 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMinV, 0, (sint) <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
02636                 <a class="code" href="namespaceNLMISC.html#a215">NLMISC::clamp</a>(iMaxV, 0, (sint) <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
02637 
02638                 <font class="comment">// matrix to go from uv space to worldspace</font>
02639                 <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> UVSpaceToWorldSpace = worldSpaceToUVs.<a class="code" href="classNLMISC_1_1CMatrix.html#z293_7">inverted</a>();
02640 
02641                 std::vector&lt;uint8&gt; &amp;pixs8 = diffuseTex-&gt;getPixels();
02642                 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> *rgbPixs = (<a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> *) &amp;pixs8[0];
02643 
02644         
02646                 <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> = iMinU; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> &lt; iMaxU; ++<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>)
02647                 {
02648                         <font class="keywordflow">for</font> (sint <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> = iMinV; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> &lt; iMaxV; ++<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>)
02649                         {
02650                                 <font class="keywordtype">float</font> factor;
02651                                 <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> pos = UVSpaceToWorldSpace * <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a>( <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> + 0.5f, <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> + 0.5f, 0 ) 
02652                                         + description.WaterShadowBias * <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>;
02653                                 <font class="keywordflow">if</font> (description.Shadow)
02654                                 {
02655                                         <a class="code" href="classNL3D_1_1CZoneLighter.html#c9">rayTrace</a>(pos, <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>, 0, 0, -1, factor, shape, shapeTmp, cpu);
02656                                 }
02657                                 <font class="keywordflow">else</font>
02658                                 {
02659                                         factor = - <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a> * description.LightDirection;
02660                                 }
02661                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(factor, 0.f, 1.f);
02662                                 factor = factor * description.WaterDiffuse + description.WaterAmbient;
02663                                 <font class="keywordflow">if</font> (description.SkyContributionForWater)
02664                                 {
02665                                         factor += <a class="code" href="classNL3D_1_1CZoneLighter.html#c7">getSkyContribution</a>(pos, <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>, description.SkyIntensity);
02666                                 }
02667                                 <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(factor, 0.f, 1.f);
02668                                 uint intensity = (uint8) (255 * factor);
02669                                 <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> srcCol(intensity,
02670                                                                          intensity,
02671                                                                          intensity,
02672                                                                           255);
02673 
02674                                 <font class="keywordflow">if</font> (!description.ModulateWaterColor)
02675                                 {
02676                                         rgbPixs[<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> * width] = srcCol;
02677                                 }
02678                                 <font class="keywordflow">else</font>
02679                                 {
02680                                         <a class="code" href="classNLMISC_1_1CRGBA.html">NLMISC::CRGBA</a> &amp;col = rgbPixs[<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> * width];
02681                                         col.<a class="code" href="classNLMISC_1_1CRGBA.html#a9">modulateFromColor</a>(col, srcCol);
02682                                 }
02683                         }
02684                 }
02685         
02687                 <font class="keywordflow">if</font> (<a class="code" href="zone__lighter_8cpp.html#a12">getExt</a>(texFileName) != <font class="stringliteral">".tga"</font>)
02688                 {
02689                         <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Zone lighter : error when lighting a water surface : input bitmap is not a tga file"</font>);
02690                 }
02691                 <font class="keywordflow">else</font>
02692                 {
02693                         <font class="keywordflow">try</font>
02694                         {
02695                                 COFile of;
02696                                 of.open(texFileName);
02697                                 diffuseTex-&gt;writeTGA(of, 24);
02698                                 of.close();
02699                         }
02700                         <font class="keywordflow">catch</font> (<a class="code" href="classNLMISC_1_1Exception.html">NLMISC::Exception</a> &amp;)
02701                         {
02702                                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Zone lighter : while lighting a water shape, writing %s failed! "</font>, texFileName.c_str());
02703                         }
02704                 }
02705         }
02706         <font class="keywordflow">catch</font>(<a class="code" href="classNLMISC_1_1Exception.html">NLMISC::Exception</a> &amp;e)
02707         {
02708                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Water shape lighting failed !"</font>);
02709                 <a class="code" href="debug_8h.html#a2">nlwarning</a>(e.what());
02710         }
02711 }
02712 
<a name="l02714"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#a7">02714</a> <font class="keywordtype">void</font> CZoneLighter::addWaterShape(CWaterShape *shape, <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMatrix.html">NLMISC::CMatrix</a> &amp;MT)
02715 {
02717         CShapeInfo ci;
02718         ci.Shape = shape;
02719         ci.MT = MT;
02720         <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.push_back(ci);
02721 }
02722 
<a name="l02724"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c18">02724</a> <font class="keywordtype">void</font> CZoneLighter::makeQuadGridFromWaterShapes(<a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> zoneBBox)
02725 {
02726         <font class="keywordflow">if</font> (!<a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.size()) <font class="keywordflow">return</font>;
02727 
02728         <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> tmpBox;
02729 
02731         <font class="keyword">const</font> uint numCells = 16;
02732 
02734         <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>  = zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>().x - zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_0">getMin</a>().x;
02735         <font class="keywordtype">float</font> <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a> = zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>().y - zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_0">getMin</a>().y;
02736 
02737         <font class="keywordtype">float</font> dim = std::max(<a class="code" href="driver__opengl__extension__def_8h.html#a389">width</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a390">height</a>);
02738 
02739 
02741         <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.create(numCells, dim / numCells);
02742         
02743 
02744         uint count = 0, totalCount = <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.size();
02745 
02747         <font class="keywordflow">for</font> (TShapeVect::iterator it = <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.begin(); it != <a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>.end(); ++it, ++count)
02748         {
02750                 it-&gt;Shape-&gt;getAABBox(tmpBox);
02751                 <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> currBB = <a class="code" href="classNLMISC_1_1CAABBox.html#z266_3">NLMISC::CAABBox::transformAABBox</a>(it-&gt;MT, tmpBox);
02752 
02754                 <font class="keywordflow">if</font> (zoneBBox.<a class="code" href="classNLMISC_1_1CAABBox.html#z265_4">intersect</a>(currBB))
02755                 {
02756                         <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.insert(currBB.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_0">getMin</a>(), currBB.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>(), NLMISC::safe_cast&lt;CWaterShape *&gt;(it-&gt;Shape));
02757                 }
02758                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Building quadtree from water surfaces"</font>, (<font class="keywordtype">float</font>) count / totalCount);
02759         }
02760 
02762         <a class="code" href="namespaceNLMISC.html#a222">NLMISC::contReset</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o40">_WaterShapes</a>);
02763 }
02764 
02765 
02766 <font class="comment">//==================================================================</font>
02767 
<a name="l02769"></a><a class="code" href="structCTileOfPatch.html">02769</a> <font class="keyword">struct </font><a class="code" href="structCTileOfPatch.html">CTileOfPatch</a>
02770 {
<a name="l02771"></a><a class="code" href="structCTileOfPatch.html#m0">02771</a>         uint8           TileId;
<a name="l02772"></a><a class="code" href="structCTileOfPatch.html#m1">02772</a>         CPatch          *Patch;
02773         <a class="code" href="structCTileOfPatch.html">CTileOfPatch</a>();
<a name="l02774"></a><a class="code" href="structCTileOfPatch.html#a1">02774</a>         <a class="code" href="structCTileOfPatch.html">CTileOfPatch</a>(uint8 tileId, CPatch *patch) : TileId(tileId), Patch(patch)
02775         {               
02776         }       
02777 };
02778 
02779 
02780 
02781 <font class="comment">// ***************************************************************************</font>
02782 <font class="comment">// ***************************************************************************</font>
02783 <font class="comment">// Static point lights.</font>
02784 <font class="comment">// ***************************************************************************</font>
02785 <font class="comment">// ***************************************************************************</font>
02786 
02787 
02788 <font class="comment">// ***************************************************************************</font>
<a name="l02789"></a><a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#a0">02789</a> CZoneLighter::CPointLightRT::CPointLightRT()
02790 {
02791         <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m4">RefCount</a>= 0;
02792 }
02793 
02794 
02795 <font class="comment">// ***************************************************************************</font>
<a name="l02796"></a><a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#a1">02796</a> <font class="keywordtype">bool</font>    CZoneLighter::CPointLightRT::testRaytrace(<font class="keyword">const</font> CVector &amp;<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>)
02797 {
02798         CVector dummy;
02799 
02800         <font class="keywordflow">if</font>(!<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m2">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#a2">include</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>))
02801                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
02802 
02803         <font class="comment">// If Ambient light, just skip</font>
02804         <font class="keywordflow">if</font>(<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m0">PointLight</a>.getType()== CPointLight::AmbientLight)
02805                 <font class="keywordflow">return</font> <font class="keyword">false</font>;
02806 
02807         <font class="comment">// If SpotLight verify in angle radius.</font>
02808         <font class="keywordflow">if</font>(<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m0">PointLight</a>.getType()== CPointLight::SpotLight)
02809         {
02810                 <font class="keywordtype">float</font>   att= <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m0">PointLight</a>.computeLinearAttenuation(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
02811                 <font class="keywordflow">if</font> (att==0)
02812                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
02813         }
02814 
02815         <font class="comment">// Select in the cubeGrid</font>
02816         <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.select(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
02817         <font class="comment">// For all faces selected</font>
02818         <font class="keywordflow">while</font>(!<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.isEndSel())
02819         {
02820                 <font class="keyword">const</font> CTriangle *tri= <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.getSel();
02821 
02822                 <font class="comment">// If intersect, the point is occluded.</font>
02823                 <font class="keywordflow">if</font>( tri-&gt;Triangle.intersect(<a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m2">BSphere</a>.<a class="code" href="classNLMISC_1_1CBSphere.html#m0">Center</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>, dummy, tri-&gt;getPlane()) )
02824                         <font class="keywordflow">return</font> <font class="keyword">false</font>;
02825 
02826                 <font class="comment">// next</font>
02827                 <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPointLightRT.html#m3">FaceCubeGrid</a>.nextSel();
02828         }
02829 
02830         <font class="comment">// Ok the point is visilbe from the light</font>
02831         <font class="keywordflow">return</font> <font class="keyword">true</font>;
02832 }
02833 
02834 
02835 <font class="comment">// ***************************************************************************</font>
<a name="l02836"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#z922_0">02836</a> <font class="keywordtype">void</font>                    CZoneLighter::addStaticPointLight(<font class="keyword">const</font> CPointLightNamed &amp;pln)
02837 {
02838         <font class="comment">// build the plRT.</font>
02839         CPointLightRT   plRT;
02840         plRT.PointLight= pln;
02841         <font class="comment">// compute plRT.OODeltaAttenuation</font>
02842         plRT.OODeltaAttenuation= pln.getAttenuationEnd() - pln.getAttenuationBegin();
02843         <font class="keywordflow">if</font>(plRT.OODeltaAttenuation &lt;=0 )
02844                 plRT.OODeltaAttenuation= 0;
02845         <font class="keywordflow">else</font>
02846                 plRT.OODeltaAttenuation= 1.0f / plRT.OODeltaAttenuation;
02847         <font class="comment">// compute plRT.BSphere</font>
02848         plRT.BSphere.Center= pln.getPosition();
02849         plRT.BSphere.Radius= pln.getAttenuationEnd();
02850         <font class="comment">// NB: FaceCubeGrid will be computed during light()</font>
02851 
02852         <font class="comment">// add the plRT</font>
02853         <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.push_back(plRT);
02854 
02855 }
02856 
02857 
02858 <font class="comment">// ***************************************************************************</font>
<a name="l02859"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#z923_0">02859</a> <font class="keywordtype">void</font>                    CZoneLighter::compilePointLightRT(uint gridSize, <font class="keywordtype">float</font> gridCellSize, std::vector&lt;CTriangle&gt;&amp; obstacles, <font class="keywordtype">bool</font> doShadow)
02860 {
02861         uint    i;
02862 
02863         <font class="comment">// Fill the quadGrid of Lights.</font>
02864         <font class="comment">// ===========</font>
02865         <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.create(gridSize, gridCellSize);
02866         <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size();i++)
02867         {
02868                 CPointLightRT   &amp;plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i];
02869 
02870                 <font class="comment">// Compute the bbox of the light</font>
02871                 CAABBox         bbox;
02872                 bbox.setCenter(plRT.BSphere.Center);
02873                 <font class="keywordtype">float</font>   hl= plRT.BSphere.Radius;
02874                 bbox.setHalfSize(CVector(hl,hl,hl));
02875 
02876                 <font class="comment">// Insert the pointLight in the quadGrid.</font>
02877                 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.insert(bbox.getMin(), bbox.getMax(), &amp;plRT);
02878         }
02879 
02880 
02881         <font class="comment">// Append triangles to cubeGrid ??</font>
02882         <font class="keywordflow">if</font>(doShadow)
02883         {
02884                 <font class="comment">// For all obstacles, Fill a quadGrid.</font>
02885                 <font class="comment">// ===========</font>
02886                 CQuadGrid&lt;CTriangle*&gt;   obstacleGrid;
02887                 obstacleGrid.create(gridSize, gridCellSize);
02888                 uint    size= obstacles.size();
02889                 <font class="keywordflow">for</font>(i=0; i&lt;size; i++)
02890                 {
02891                         <font class="comment">// bbox of triangle</font>
02892                         CAABBox bbox;
02893                         bbox.setCenter(obstacles[i].Triangle.V0);
02894                         bbox.extend(obstacles[i].Triangle.V1);
02895                         bbox.extend(obstacles[i].Triangle.V2);
02896                         <font class="comment">// insert triangle in quadGrid.</font>
02897                         obstacleGrid.insert(bbox.getMin(), bbox.getMax(), &amp;obstacles[i]);
02898                 }
02899 
02900 
02901                 <font class="comment">// For all PointLights, fill his CubeGrid</font>
02902                 <font class="comment">// ===========</font>
02903                 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size();i++)
02904                 {
02905                         <font class="comment">// progress</font>
02906                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.5f*i / (<font class="keywordtype">float</font>)(<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size()-1));
02907 
02908                         CPointLightRT   &amp;plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i];
02909                         <font class="comment">// Create the cubeGrid</font>
02910                         plRT.FaceCubeGrid.create(plRT.PointLight.getPosition(), <a class="code" href="zone__lighter_8cpp.html#a0">NL3D_ZONE_LIGHTER_CUBE_GRID_SIZE</a>);
02911 
02912                         <font class="comment">// AmbiantLIghts: do nothing.</font>
02913                         <font class="keywordflow">if</font>(plRT.PointLight.getType()!=CPointLight::AmbientLight)
02914                         {
02915                                 <font class="comment">// Select only obstacle Faces around the light. Other are not usefull</font>
02916                                 CAABBox bbox;
02917                                 bbox.setCenter(plRT.PointLight.getPosition());
02918                                 <font class="keywordtype">float</font>   hl= plRT.PointLight.getAttenuationEnd();
02919                                 bbox.setHalfSize(CVector(hl,hl,hl));
02920                                 obstacleGrid.select(bbox.getMin(), bbox.getMax());
02921 
02922                                 <font class="comment">// For all faces, fill the cubeGrid.</font>
02923                                 CQuadGrid&lt;CTriangle*&gt;::CIterator        itObstacle;
02924                                 itObstacle= obstacleGrid.begin();
02925                                 <font class="keywordflow">while</font>( itObstacle!=obstacleGrid.end() )
02926                                 {
02927                                         CTriangle       &amp;tri= *(*itObstacle);
02928                                         <font class="comment">// Test BackFace culling. Only faces which are BackFace the point light are inserted.</font>
02929                                         <font class="comment">// This is to avoid AutoOccluding problems</font>
02930                                         <font class="keywordflow">if</font>( tri.getPlane() * plRT.BSphere.Center &lt; 0)
02931                                         {
02932                                                 <font class="comment">// Insert the triangle in the CubeGrid</font>
02933                                                 plRT.FaceCubeGrid.insert( tri.Triangle, &amp;tri);
02934                                         }
02935 
02936                                         itObstacle++;
02937                                 }
02938                         }
02939 
02940                         <font class="comment">// Compile the CubeGrid.</font>
02941                         plRT.FaceCubeGrid.compile();
02942 
02943                         <font class="comment">// And Reset RefCount.</font>
02944                         plRT.RefCount= 0;
02945                 }
02946         }
02947         <font class="comment">// else, just build empty grid</font>
02948         <font class="keywordflow">else</font>
02949         {
02950                 <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size();i++)
02951                 {
02952                         <font class="comment">// progress</font>
02953                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.5f*i / (<font class="keywordtype">float</font>)(<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size()-1));
02954 
02955                         CPointLightRT   &amp;plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i];
02956                         <font class="comment">// Create a dummy empty cubeGrid =&gt; no rayTrace :)</font>
02957                         plRT.FaceCubeGrid.create(plRT.PointLight.getPosition(), 4);
02958 
02959                         <font class="comment">// Compile the CubeGrid.</font>
02960                         plRT.FaceCubeGrid.compile();
02961 
02962                         <font class="comment">// And Reset RefCount.</font>
02963                         plRT.RefCount= 0;
02964                 }
02965         }
02966 
02967 }
02968 
02969 
02970 <font class="comment">// ***************************************************************************</font>
<a name="l02971"></a><a class="code" href="structNL3D_1_1CZoneLighter_1_1CPredPointLightToPoint.html#a0">02971</a> <font class="keywordtype">bool</font>    CZoneLighter::CPredPointLightToPoint::operator() (CPointLightRT *pla, CPointLightRT *plb)<font class="keyword"> const</font>
02972 <font class="keyword"></font>{
02973         <font class="keywordtype">float</font>   ra= (pla-&gt;BSphere.Center - <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPredPointLightToPoint.html#m0">Point</a>).norm();
02974         <font class="keywordtype">float</font>   rb= (plb-&gt;BSphere.Center - <a class="code" href="structNL3D_1_1CZoneLighter_1_1CPredPointLightToPoint.html#m0">Point</a>).norm();
02975         <font class="keywordtype">float</font>   infA= (pla-&gt;PointLight.getAttenuationEnd() - ra) * pla-&gt;OODeltaAttenuation;
02976         <font class="keywordtype">float</font>   infB= (plb-&gt;PointLight.getAttenuationEnd() - rb) * plb-&gt;OODeltaAttenuation;
02977         <font class="comment">// return which light impact the most.</font>
02978         <font class="comment">// If same impact</font>
02979         <font class="keywordflow">if</font>(infA==infB)
02980                 <font class="comment">// return nearest</font>
02981                 <font class="keywordflow">return</font> ra &lt; rb;
02982         <font class="keywordflow">else</font>
02983                 <font class="comment">// return better impact</font>
02984                 <font class="keywordflow">return</font>  infA &gt; infB;
02985 }
02986 
02987 <font class="comment">// ***************************************************************************</font>
<a name="l02988"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#z923_1">02988</a> <font class="keywordtype">void</font>                    CZoneLighter::processZonePointLightRT(vector&lt;CPointLightNamed&gt; &amp;listPointLight)
02989 {
02990         uint    i;
02991         vector&lt;CPointLightRT*&gt;          lightInfs;
02992         lightInfs.reserve(1024);
02993 
02994         <font class="comment">// clear result list</font>
02995         listPointLight.clear();
02996 
02997         <font class="comment">// zoneToLight</font>
02998         CZone   *zoneToLight= <a class="code" href="classNL3D_1_1CZoneLighter.html#o5">_Landscape</a>-&gt;<a class="code" href="classNL3D_1_1CLandscape.html#z481_0">getZone</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>);
02999         <font class="keywordflow">if</font>(!zoneToLight)
03000                 <font class="keywordflow">return</font>;
03001 
03002         <font class="comment">// Build patchForPLs</font>
03003         <font class="comment">//===========</font>
03004         vector&lt;CPatchForPL&gt;             patchForPLs;
03005         patchForPLs.resize(<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size());
03006         <font class="keywordflow">for</font>(i=0; i&lt;patchForPLs.size(); i++)
03007         {
03008                 <font class="comment">// Get OrderS/OrderT</font>
03009                 patchForPLs[i].OrderS= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[i].OrderS;
03010                 patchForPLs[i].OrderT= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[i].OrderT;
03011                 <font class="comment">// resize TileLightInfluences</font>
03012                 uint    <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= patchForPLs[i].WidthTLI= patchForPLs[i].OrderS/2 +1 ;
03013                 uint    h= patchForPLs[i].HeightTLI= patchForPLs[i].OrderT/2 +1;
03014                 patchForPLs[i].TileLightInfluences.resize(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h);
03015         }
03016 
03017 
03018         <font class="comment">// compute each TileLightInfluence</font>
03019         <font class="comment">//===========</font>
03020         <font class="keywordflow">for</font>(i=0; i&lt;patchForPLs.size(); i++)
03021         {
03022                 <font class="comment">// progress</font>
03023                 <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Compute Influences of PointLights"</font>, 0.5f + 0.5f*i / (<font class="keywordtype">float</font>)patchForPLs.size());
03024 
03025                 CPatchForPL             &amp;pfpl= patchForPLs[i];
03026                 <font class="keyword">const</font> CPatch    *patch= const_cast&lt;const CZone*&gt;(zoneToLight)-&gt;getPatch(i);
03027 
03028                 uint    <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>;
03029                 <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;pfpl.HeightTLI; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
03030                 {
03031                         <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;pfpl.WidthTLI; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
03032                         {
03033                                 <font class="comment">// compute the point and normal (normalized) where the TLI lies.</font>
03034                                 <font class="comment">//---------</font>
03035                                 CVector         pos, normal;
03036                                 <font class="keywordtype">float</font>           <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>;
03037                                 <a class="code" href="driver__opengl__extension__def_8h.html#a383">s</a>= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a> / (pfpl.WidthTLI-1);
03038                                 <a class="code" href="driver__opengl__extension__def_8h.html#a384">t</a>= (float)<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a> / (pfpl.HeightTLI-1);
03039                                 <font class="comment">// Compute the Vertex, with Noise information (important for accurate raytracing).</font>
03040                                 pos= patch-&gt;computeVertex(<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>);
03041                                 <font class="comment">// Use UnNoised normal from BezierPatch, because the lighting does not need to be so precise.</font>
03042                                 CBezierPatch    *bp= patch-&gt;unpackIntoCache();
03043                                 normal= bp-&gt;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>);
03044                                 
03045 
03046                                 <font class="comment">// Compute Which light influences him.</font>
03047                                 <font class="comment">//---------</font>
03048                                 lightInfs.clear();
03049                                 <font class="comment">// Search possible lights around the position.</font>
03050                                 <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.select(pos, pos);
03051                                 <font class="comment">// For all of them, get the ones which touch this point.</font>
03052                                 CQuadGrid&lt;CPointLightRT*&gt;::CIterator    it= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.begin();
03053                                 <font class="keywordflow">while</font>(it != <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_3">_StaticPointLightQuadGrid</a>.end())
03054                                 {
03055                                         CPointLightRT   *pl= *it;
03056 
03057                                         <font class="comment">// a light influence a TLI only if this one is FrontFaced to the light !!</font>
03058                                         <font class="keywordflow">if</font>( ( pl-&gt;BSphere.Center - pos ) * normal &gt; 0)
03059                                         {
03060                                                 <font class="comment">// Add 5cm else it fails in some case where ( pl-&gt;BSphere.Center - pos ) * normal is </font>
03061                                                 <font class="comment">// nearly 0 and the point should be occluded.</font>
03062                                                 <font class="keyword">const</font> <font class="keywordtype">float</font>     deltaY= 0.05f;
03063                                                 CVector posToRT= pos + normal * deltaY;
03064                                                 <font class="comment">// Test if really in the radius of the light, if no occlusion, and if in SpotAngle</font>
03065                                                 <font class="keywordflow">if</font>( pl-&gt;testRaytrace(posToRT) )
03066                                                 {
03067                                                         <font class="comment">// Ok, add the light to the lights which influence the TLI </font>
03068                                                         lightInfs.push_back(pl);
03069                                                 }
03070                                         }
03071 
03072                                         <font class="comment">// next</font>
03073                                         it++;
03074                                 }
03075 
03076                                 <font class="comment">// Choose the Best ones.</font>
03077                                 <font class="comment">//---------</font>
03078                                 CPredPointLightToPoint  predPLTP;
03079                                 predPLTP.Point= pos;
03080                                 <font class="comment">// sort.</font>
03081                                 sort(lightInfs.begin(), lightInfs.end(), predPLTP);
03082                                 <font class="comment">// truncate.</font>
03083                                 lightInfs.resize( <a class="code" href="bit__set_8cpp.html#a0">min</a>(lightInfs.size(), (uint)CTileLightInfluence::NumLightPerCorner) );
03084 
03085 
03086                                 <font class="comment">// For each of them, fill TLI</font>
03087                                 <font class="comment">//---------</font>
03088                                 CTileLightInfUnpack             tli;
03089                                 uint                                    lightInfId;
03090                                 <font class="keywordflow">for</font>(lightInfId=0; lightInfId&lt;lightInfs.size(); lightInfId++)
03091                                 {
03092                                         CPointLightRT   *pl= lightInfs[lightInfId];
03093 
03094                                         <font class="comment">// copy light.</font>
03095                                         tli.Light[lightInfId]= pl;
03096                                         <font class="comment">// Compute light Diffuse factor.</font>
03097                                         CVector         dir= pl-&gt;BSphere.Center - pos;
03098                                         dir.normalize();
03099                                         tli.LightFactor[lightInfId]= dir * normal;
03100                                         <a class="code" href="namespaceNLMISC.html#a215">clamp</a>(tli.LightFactor[lightInfId], 0.f, 1.f);
03101                                         <font class="comment">// modulate by light attenuation.</font>
03102                                         tli.LightFactor[lightInfId]*= pl-&gt;PointLight.computeLinearAttenuation(pos);
03103 
03104                                         <font class="comment">// Inc RefCount of the light.</font>
03105                                         pl-&gt;RefCount++;
03106                                 }
03107                                 <font class="comment">// Reset any empty slot to NULL.</font>
03108                                 <font class="keywordflow">for</font>(; lightInfId&lt;CTileLightInfluence::NumLightPerCorner; lightInfId++)
03109                                 {
03110                                         tli.Light[lightInfId]= NULL;
03111                                 }
03112 
03113 
03114                                 <font class="comment">// Set TLI in patch.</font>
03115                                 <font class="comment">//---------</font>
03116                                 pfpl.TileLightInfluences[<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*pfpl.WidthTLI + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>]= tli;
03117                         }
03118                 }
03119         }
03120 
03121 
03122         <font class="comment">// compress and setup _PatchInfo with compressed data.</font>
03123         <font class="comment">//===========</font>
03124         uint    plId= 0;
03125         <font class="comment">// Process each pointLights</font>
03126         <font class="keywordflow">for</font>(i=0; i&lt;<a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>.size(); i++)
03127         {
03128                 CPointLightRT   &amp;plRT= <a class="code" href="classNL3D_1_1CZoneLighter.html#z923_2">_StaticPointLights</a>[i];
03129                 <font class="comment">// If this light is used.</font>
03130                 <font class="keywordflow">if</font>(plRT.RefCount &gt; 0)
03131                 {
03132                         <font class="comment">// Must Copy it into Zone.</font>
03133                         listPointLight.push_back(plRT.PointLight);
03134                         plRT.DstId= plId++;
03135                         <font class="comment">// If index &gt;= 255, too many lights (NB: =&gt; because 255 is a NULL code).</font>
03136                         <font class="keywordflow">if</font>(plId&gt;=0xFF)
03137                         {
03138                                 <font class="keywordflow">throw</font> Exception(<font class="stringliteral">"Too many Static Point Lights influence the zone!!"</font>);
03139                         }
03140                 }
03141         }
03142 
03143         <font class="comment">// For each patch, compress TLI in PatchInfo.</font>
03144         <font class="keywordflow">for</font>(i=0; i&lt;patchForPLs.size(); i++)
03145         {
03146                 CPatchForPL             &amp;pfpl= patchForPLs[i];
03147                 CPatchInfo              &amp;pInfo= <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>[i];
03148 
03149                 uint    <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>= pfpl.WidthTLI;
03150                 uint    h= pfpl.HeightTLI;
03151 
03152                 <font class="comment">// Fill  pInfo.TileLightInfluences</font>
03153                 pInfo.TileLightInfluences.resize(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>*h);
03154                 uint    <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>;
03155                 <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;h; <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>++)
03156                 {
03157                         <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;<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>; <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>++)
03158                         {
03159                                 uint    tliId= <a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>*<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a> + <a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>;
03160                                 <font class="comment">// For all light slot</font>
03161                                 <font class="keywordflow">for</font>(uint lightId= 0; lightId&lt;CTileLightInfluence::NumLightPerCorner; lightId++)
03162                                 {
03163                                         CTileLightInfUnpack             &amp;tliSrc= pfpl.TileLightInfluences[tliId];
03164                                         CTileLightInfluence             &amp;tliDst= pInfo.TileLightInfluences[tliId];
03165                                         <font class="keywordflow">if</font>(tliSrc.Light[lightId] == NULL)
03166                                         {
03167                                                 <font class="comment">// Mark as unused.</font>
03168                                                 tliDst.Light[lightId]= 0xFF;
03169                                         }
03170                                         <font class="keywordflow">else</font>
03171                                         {
03172                                                 <font class="comment">// Get index.</font>
03173                                                 tliDst.Light[lightId]= tliSrc.Light[lightId]-&gt;DstId;
03174                                                 <font class="comment">// Get Diffuse Factor.</font>
03175                                                 tliDst.setDiffuseLightFactor(lightId, (uint8)(tliSrc.LightFactor[lightId]*255));
03176                                         }
03177                                 }
03178                         }
03179                 }
03180 
03181         }
03182 
03183 }
03184 
03187 <font class="comment">// TileFlagsForPositionTowardWater</font>
03190 <font class="comment"></font>
03191 
03192 <font class="comment">//==================================================================</font>
<a name="l03194"></a><a class="code" href="zone__lighter_8cpp.html#a13">03194</a> <font class="comment">static inline bool operator &lt; (const CTileOfPatch &amp;lhs, const CTileOfPatch &amp;rhs)</font>
03195 {
03196         <font class="keywordflow">return</font> lhs.Patch == rhs.Patch  ?
03197                    lhs.TileId &lt; rhs.TileId :
03198                    lhs.Patch  &lt; rhs.Patch;      
03199 };
03200 
<a name="l03202"></a><a class="code" href="zone__lighter_8cpp.html#a6">03202</a> <font class="keyword">typedef</font> std::map&lt;CTileOfPatch, NLMISC::CAABBox&gt; <a class="code" href="zone__lighter_8cpp.html#a6">TTileOfPatchMap</a>;
03203 
<a name="l03205"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c19">03205</a> <font class="keywordtype">void</font> CZoneLighter::computeTileFlagsForPositionTowardWater(<font class="keyword">const</font> CLightDesc &amp;lightDesc,
03206                                                                                                                   std::vector&lt;const CTessFace*&gt; &amp;tessFaces                                                                                                                
03207                                                                                                                   )
03208 {       
03209         uint numTileAbove     = 0;
03210         uint numTileBelow     = 0;
03211         uint numTileIntersect = 0;
03212         
03214         <a class="code" href="zone__lighter_8cpp.html#a6">TTileOfPatchMap</a> tiles;
03215 
03217         <font class="comment">//  First, build the bbox for all tiles  //</font>
03219 <font class="comment"></font>
03220         uint triCount = 0, totalTriCount = tessFaces.size();    
03221 
03222         <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">"Dealing with %d tessFaces"</font>, tessFaces.size());
03223         <font class="keywordflow">for</font> (std::vector&lt;const CTessFace*&gt;::iterator it = tessFaces.begin(); it != tessFaces.end(); ++it, ++triCount)
03224         {
03226                 <font class="keywordflow">if</font> ((*it)-&gt;Patch-&gt;getZone()-&gt;getZoneId() != <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) <font class="keywordflow">continue</font>;
03228                 <font class="keywordflow">if</font> ((*it)-&gt;Patch-&gt;Tiles[(*it)-&gt;TileId].getVegetableState() == CTileElement::VegetableDisabled)
03229                         <font class="keywordflow">continue</font>;
03230 
03231                 <a class="code" href="structCTileOfPatch.html">CTileOfPatch</a> top((*it)-&gt;TileId, (*it)-&gt;Patch);
03232                 TTileOfPatchMap::iterator tileIt = tiles.find(top);
03233 
03235                 <font class="keywordflow">if</font> (tileIt == tiles.end()) <font class="comment">// first time ?</font>
03236                 {
03238                         <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> b;
03239                         b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_3">setMinMax</a>((*it)-&gt;VBase-&gt;EndPos, (*it)-&gt;VLeft-&gt;EndPos);
03240                         b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)-&gt;VRight-&gt;EndPos);
03241                         b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>(b.<a class="code" href="classNLMISC_1_1CAABBox.html#z264_1">getMax</a>() + lightDesc.VegetableHeight * <a class="code" href="classNLMISC_1_1CVector.html#p3">NLMISC::CVector::K</a>); <font class="comment">// adds vegetable height                 </font>
03242                         tiles[top] = b;
03243                 }
03244                 <font class="keywordflow">else</font> <font class="comment">// extends the bbox with the given face</font>
03245                 {
03246                         <a class="code" href="classNLMISC_1_1CAABBox.html">NLMISC::CAABBox</a> &amp;b = tileIt-&gt;second;                    
03247                         b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)-&gt;VBase-&gt;EndPos);
03248                         b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)-&gt;VRight-&gt;EndPos);
03249                         b.<a class="code" href="classNLMISC_1_1CAABBox.html#z263_4">extend</a>((*it)-&gt;VLeft-&gt;EndPos);
03250                 }
03251 
03252                 <font class="keywordflow">if</font> ((triCount % 100) == 0)
03253                 {
03254                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Building bbox from tiles"</font>, (<font class="keywordtype">float</font>) triCount / totalTriCount);
03255                 }
03256         }
03257 
03258         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Building bbox from tiles"</font>, 1.f);
03259 
03260 
03261 
03263         <font class="comment">// Now, check each tile bbox against water shapes //</font>
03265 <font class="comment">        NLMISC::CPolygon   waterPoly;</font>
03266         <a class="code" href="classNLMISC_1_1CPolygon2D.html">NLMISC::CPolygon2D</a> tilePoly;
03267         tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>.resize(4);
03268 
03269         uint tileCount = 0, totalTileCount = tiles.size();      
03270 
03271         <font class="keywordflow">for</font> (TTileOfPatchMap::iterator tileIt = tiles.begin(); tileIt != tiles.end(); ++tileIt, ++tileCount)
03272         {
03273                 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> v0 = tileIt-&gt;second.getMin();
03274                 <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> v1 = tileIt-&gt;second.getMax();
03275 
03277                 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[0].set(v0.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v0.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); 
03278                 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[1].set(v1.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v0.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); 
03279                 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[2].set(v1.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v1.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); 
03280                 tilePoly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#m0">Vertices</a>[3].set(v0.<a class="code" href="classNLMISC_1_1CVector.html#m0">x</a>, v1.<a class="code" href="classNLMISC_1_1CVector.html#m1">y</a>); 
03281 
03283                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.clearSelection();
03284                 <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.select(tileIt-&gt;second.getMin(), tileIt-&gt;second.getMax());
03285 
03286                 CTileElement &amp;te = tileIt-&gt;first.Patch-&gt;Tiles[tileIt-&gt;first.TileId]; <font class="comment">// alias to the current tile element</font>
03287 
03289                 TWaterShapeQuadGrid::CIterator qgIt;
03290                 <font class="keywordflow">for</font> (qgIt = <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.begin(); qgIt != <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.end(); ++qgIt)
03291                 {
03292                         
03293                         (*qgIt)-&gt;getShapeInWorldSpace(waterPoly);
03294                         <a class="code" href="classNLMISC_1_1CPolygon2D.html">NLMISC::CPolygon2D</a> poly(waterPoly);
03295                         <font class="keywordflow">if</font> (poly.<a class="code" href="classNLMISC_1_1CPolygon2D.html#a8">intersect</a>(tilePoly)) <font class="comment">// above or below a water surface ?               </font>
03296                         {
03298                                 <font class="keywordtype">float</font> waterHeight = waterPoly.Vertices[0].z;
03299 
03300                                 <font class="keywordflow">if</font> (v1.<a class="code" href="classNLMISC_1_1CVector.html#m2">z</a> &lt; waterHeight)
03301                                 {
03302                                         <font class="comment">// below</font>
03303                                         te.setVegetableState(CTileElement::UnderWater);
03304                                         <font class="comment">//nlassert(te.getVegetableState() == CTileElement::UnderWater);</font>
03305                                         ++ numTileBelow;
03306                                 }
03307                                 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (v0. <a class="code" href="driver__opengl__extension__def_8h.html#a366">z</a> &gt; waterHeight)
03308                                 {
03309                                         <font class="comment">// above</font>
03310                                         te.setVegetableState(CTileElement::AboveWater);
03311                                         <font class="comment">//nlassert(te.getVegetableState() == CTileElement::AboveWater);</font>
03312                                         ++ numTileAbove;
03313                                 }
03314                                 <font class="keywordflow">else</font>
03315                                 {
03316                                         <font class="comment">// intersect water</font>
03317                                         te.setVegetableState(CTileElement::IntersectWater);
03318                                         <font class="comment">//nlassert(te.getVegetableState() == CTileElement::IntersectWater);</font>
03319                                         ++ numTileIntersect;
03320                                 }
03321                                 <font class="keywordflow">break</font>;
03322                         }
03323                 }
03324 
03325                 <font class="keywordflow">if</font> (qgIt == <a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>.end()) <font class="comment">// no intersection found ? if yes it's above water</font>
03326                 {
03327                         te.setVegetableState(CTileElement::AboveWater); 
03328                         <font class="comment">//nlassert(te.getVegetableState() == CTileElement::AboveWater);</font>
03329                         ++ numTileAbove;
03330                 }
03331 
03332                 <font class="keywordflow">if</font> ((tileCount % 50) == 0)
03333                 {
03334                         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Computing tile position towards water"</font>, (<font class="keywordtype">float</font>) tileCount / totalTileCount);
03335                 }
03336         }
03337 
03338         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a>(<font class="stringliteral">"Computing tile position towards water"</font>, 1.f);
03339 
03340         <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">" %d tiles are above water."</font>, numTileAbove);
03341         <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">" %d tiles are below water."</font>, numTileBelow);
03342         <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">" %d tiles intersect water."</font>, numTileIntersect);
03343 
03344 
03345 
03347         <a class="code" href="namespaceNLMISC.html#a222">NLMISC::contReset</a>(<a class="code" href="classNL3D_1_1CZoneLighter.html#o41">_WaterShapeQuadGrid</a>);
03348 }
03349 
<a name="l03351"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c20">03351</a> <font class="keywordtype">void</font> CZoneLighter::setTileFlagsToDefault(std::vector&lt;const CTessFace*&gt; &amp;tessFaces)
03352 {
03354         <font class="keywordflow">for</font> (std::vector&lt;const CTessFace*&gt;::iterator it = tessFaces.begin(); it != tessFaces.end(); ++it)
03355         {
03356                 <font class="keywordflow">if</font> ((*it)-&gt;Patch-&gt;getZone()-&gt;getZoneId() != <a class="code" href="classNL3D_1_1CZoneLighter.html#o4">_ZoneToLight</a>) <font class="keywordflow">continue</font>;
03357                 CTileElement &amp;te = (*it)-&gt;Patch-&gt;Tiles[(*it)-&gt;TileId];
03358                 <font class="keywordflow">if</font> (te.getVegetableState() != CTileElement::VegetableDisabled)
03359                 {
03360                         te.setVegetableState(CTileElement::AboveWater);
03361                 }
03362         }
03363 }
03364 
03365 
<a name="l03367"></a><a class="code" href="classNL3D_1_1CZoneLighter.html#c21">03367</a> uint CZoneLighter::getAPatch (uint process)
03368 {
03369         <font class="comment">// Accessor</font>
03370         CSynchronized&lt;std::vector&lt;bool&gt; &gt;::CAccessor access (&amp;<a class="code" href="classNL3D_1_1CZoneLighter.html#o9">_PatchComputed</a>);
03371 
03372         <font class="comment">// Current index</font>
03373         uint <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[process];
03374         uint firstIndex = <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>;
03375 
03376         <font class="keywordflow">if</font> (access.value().size() == 0)
03377                 <font class="comment">// no more patches</font>
03378                 <font class="keywordflow">return</font> 0xffffffff;
03379 
03380         <font class="keywordflow">while</font> (access.value()[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>])
03381         {
03382                 <font class="comment">// Next patch</font>
03383                 <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>++;
03384 
03385                 <font class="comment">// First ?</font>
03386                 <font class="keywordflow">if</font> (firstIndex == <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>)
03387                         <font class="comment">// no more patches</font>
03388                         <font class="keywordflow">return</font> 0xffffffff;
03389 
03390                 <font class="comment">// Last patch ?</font>
03391                 <font class="keywordflow">if</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> == <a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size())
03392                         <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a> = 0;
03393         }
03394 
03395         <font class="comment">// Visited</font>
03396         access.value()[<a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>] = <font class="keyword">true</font>;
03397 
03398         <font class="comment">// Last index</font>
03399         <a class="code" href="classNL3D_1_1CZoneLighter.html#o10">_LastPatchComputed</a>[process] = <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>;
03400         <a class="code" href="classNL3D_1_1CZoneLighter.html#o11">_NumberOfPatchComputed</a>++;
03401 
03402         <font class="comment">// Print</font>
03403         <a class="code" href="classNL3D_1_1CZoneLighter.html#a8">progress</a> (<font class="stringliteral">"Lighting patches"</font>, (<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CZoneLighter.html#o11">_NumberOfPatchComputed</a>/(<font class="keywordtype">float</font>)<a class="code" href="classNL3D_1_1CZoneLighter.html#o23">_PatchInfo</a>.size());
03404 
03405         <font class="comment">// Return the index</font>
03406         <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a358">index</a>;
03407 }
</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>