/usr/include/plib/ssg.h is in libplib-dev 1.8.5-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
PLIB - A Suite of Portable Game Libraries
Copyright (C) 1998,2002 Steve Baker
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information visit http://plib.sourceforge.net
$Id: ssg.h 2126 2007-10-02 00:49:30Z fayjf $
*/
#ifndef _INCLUDED_SSG_H_
#define _INCLUDED_SSG_H_
#include <stdio.h>
#include "sg.h"
#ifdef UL_MAC_OSX
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
#endif
#include "ssgconf.h"
#ifndef _SSG_PUBLIC
#define _SSG_PUBLIC protected
#endif
extern int sgebug ;
enum ssgCullResult
{
SSG_OUTSIDE = SG_OUTSIDE,
SSG_INSIDE = SG_INSIDE,
SSG_STRADDLE = SG_STRADDLE
} ;
#define SSG_MAXPATH 50
#define SSGTRAV_CULL 1
#define SSGTRAV_ISECT 2
#define SSGTRAV_HOT 4
#define SSGTRAV_LOS 8
class ssgList ;
class ssgKidList ;
class ssgBase ;
class ssgEntity ;
class ssgLeaf ;
class ssgVTable ;
class ssgVtxTable ;
class ssgVtxArray ;
class ssgTween ;
class ssgBranch ;
class ssgInvisible ;
class ssgBaseTransform ;
class ssgTransform ;
class ssgTexTrans ;
class ssgCutout ;
class ssgSelector ;
class ssgRangeSelector ;
class ssgTimedSelector ;
class ssgTweenController ;
class ssgRoot ;
void ssgDeRefDelete ( ssgBase *br ) ;
/*
Think twice before assigning new type bits, it is rather complicated.
Perhaps some kind of automatic assignment would be good?
*/
#define _SSG_BACKWARDS_REFERENCE 0x0000000 /* For SSG format files */
#define _SSG_TYPE_BASE 0x00000001
/* ssgEntities */
#define _SSG_TYPE_ENTITY 0x00000002
#define _SSG_TYPE_LEAF 0x00000020
#define _SSG_TYPE_VTABLE 0x00000080
#define _SSG_TYPE_VTXTABLE 0x00000100
#define _SSG_TYPE_VTXARRAY 0x00000200
#define _SSG_TYPE_BRANCH 0x00000040
#define _SSG_TYPE_BASETRANSFORM 0x00000080
#define _SSG_TYPE_TRANSFORM 0x00001000
#define _SSG_TYPE_TEXTRANS 0x00002000
#define _SSG_TYPE_AXISTRANSFORM 0x00004000
#define _SSG_TYPE_ANIMTRANSFORM 0x00008000
#define _SSG_TYPE_SELECTOR 0x00000100
#define _SSG_TYPE_RANGESELECTOR 0x00001000
#define _SSG_TYPE_TIMEDSELECTOR 0x00002000
#define _SSG_TYPE_TWEEN 0x00008000
#define _SSG_TYPE_TWEENCONTROLLER 0x00010000
#define _SSG_TYPE_ROOT 0x00000200
#define _SSG_TYPE_CUTOUT 0x00000400
#define _SSG_TYPE_INVISIBLE 0x00000800
/* ssgStates */
#define _SSG_TYPE_STATE 0x00000004
#define _SSG_TYPE_SIMPLESTATE 0x00000020
#define _SSG_TYPE_STATESELECTOR 0x00000040
/* ssgSimpleLists */
#define _SSG_TYPE_SIMPLELIST 0x00000008
#define _SSG_TYPE_VERTEXARRAY 0x00000020
#define _SSG_TYPE_NORMALARRAY 0x00000040
#define _SSG_TYPE_TEXCOORDARRAY 0x00000080
#define _SSG_TYPE_COLOURARRAY 0x00000100
#define _SSG_TYPE_INDEXARRAY 0x00000200
#define _SSG_TYPE_TRANSFORMARRAY 0x00000400
#define _SSG_TYPE_INTERLEAVEDARRAY 0x00000800
/* ssgTextures */
#define _SSG_TYPE_TEXTURE 0x00000010
#define SSG_FILE_VERSION 0x01
#define SSG_FILE_MAGIC_NUMBER (('S'<<24)+('S'<<16)+('G'<<8)+SSG_FILE_VERSION)
inline int ssgTypeBase () { return _SSG_TYPE_BASE ; }
inline int ssgTypeEntity () { return _SSG_TYPE_ENTITY | ssgTypeBase () ; }
inline int ssgTypeLeaf () { return _SSG_TYPE_LEAF | ssgTypeEntity () ; }
inline int ssgTypeVTable () { return _SSG_TYPE_VTABLE | ssgTypeLeaf () ; }
inline int ssgTypeVtxTable () { return _SSG_TYPE_VTXTABLE | ssgTypeLeaf () ; }
inline int ssgTypeVtxArray () { return _SSG_TYPE_VTXARRAY | ssgTypeVtxTable() ; }
inline int ssgTypeTween () { return _SSG_TYPE_TWEEN | ssgTypeVtxTable() ; }
inline int ssgTypeBranch () { return _SSG_TYPE_BRANCH | ssgTypeEntity () ; }
inline int ssgTypeTweenController(){ return _SSG_TYPE_TWEENCONTROLLER | ssgTypeBranch() ; }
inline int ssgTypeBaseTransform() { return _SSG_TYPE_BASETRANSFORM | ssgTypeBranch () ; }
inline int ssgTypeTransform () { return _SSG_TYPE_TRANSFORM | ssgTypeBaseTransform () ; }
inline int ssgTypeAnimTransform() { return _SSG_TYPE_ANIMTRANSFORM | ssgTypeTransform () ; }
inline int ssgTypeTexTrans () { return _SSG_TYPE_TEXTRANS | ssgTypeBaseTransform () ; }
inline int ssgTypeAxisTransform() { return _SSG_TYPE_AXISTRANSFORM | ssgTypeTransform () ; }
inline int ssgTypeSelector () { return _SSG_TYPE_SELECTOR | ssgTypeBranch () ; }
inline int ssgTypeRangeSelector() { return _SSG_TYPE_RANGESELECTOR | ssgTypeSelector () ; }
inline int ssgTypeTimedSelector() { return _SSG_TYPE_TIMEDSELECTOR | ssgTypeSelector () ; }
inline int ssgTypeRoot () { return _SSG_TYPE_ROOT | ssgTypeBranch () ; }
inline int ssgTypeCutout () { return _SSG_TYPE_CUTOUT | ssgTypeBranch () ; }
inline int ssgTypeInvisible () { return _SSG_TYPE_INVISIBLE | ssgTypeBranch () ; }
inline int ssgTypeState () { return _SSG_TYPE_STATE | ssgTypeBase () ; }
inline int ssgTypeSimpleState () { return _SSG_TYPE_SIMPLESTATE | ssgTypeState () ; }
inline int ssgTypeStateSelector() { return _SSG_TYPE_STATESELECTOR | ssgTypeSimpleState () ; }
inline int ssgTypeSimpleList () { return _SSG_TYPE_SIMPLELIST | ssgTypeBase () ; }
inline int ssgTypeVertexArray () { return _SSG_TYPE_VERTEXARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeNormalArray () { return _SSG_TYPE_NORMALARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeTexCoordArray() { return _SSG_TYPE_TEXCOORDARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeColourArray () { return _SSG_TYPE_COLOURARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeIndexArray () { return _SSG_TYPE_INDEXARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeTransformArray() { return _SSG_TYPE_TRANSFORMARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeInterleavedArray() { return _SSG_TYPE_INTERLEAVEDARRAY | ssgTypeSimpleList () ; }
inline int ssgTypeTexture () { return _SSG_TYPE_TEXTURE | ssgTypeBase () ; }
/*
It's critical that these numbers don't change without
some pretty pressing need because significant change to
ssgSimpleState.cxx and ssgStateTables.cxx would be needed.
*/
#define SSG_GL_TEXTURE_EN 0
#define SSG_GL_CULL_FACE_EN 1
#define SSG_GL_COLOR_MATERIAL_EN 2
#define SSG_GL_BLEND_EN 3
#define SSG_GL_ALPHA_TEST_EN 4
#define SSG_GL_LIGHTING_EN 5
#define SSG_GL_TEXTURE 6
#define SSG_GL_COLOR_MATERIAL 7
#define SSG_GL_DIFFUSE 8
#define SSG_GL_AMBIENT 9
#define SSG_GL_SPECULAR 10
#define SSG_GL_EMISSION 11
#define SSG_GL_SHININESS 12
#define SSG_GL_ALPHA_TEST 13
#define SSG_GL_SHADE_MODEL 14
#define SSG_CLONE_RECURSIVE 1
#define SSG_CLONE_GEOMETRY 2
#define SSG_CLONE_USERDATA 4
#define SSG_CLONE_STATE 8
#define SSG_CLONE_STATE_RECURSIVE 16
#define SSG_CLONE_TEXTURE 32
int ssgGetFrameCounter () ;
void ssgSetFrameCounter ( int fc ) ;
// Returns GL_TRUE if the OpenGL Extension whose name is *extName
// is supported by the system, or GL_FALSE otherwise.
bool ssgIsExtensionSupported(char *extName);
class ssgList
{
protected:
unsigned int total ; /* The total number of entities in the list */
unsigned int limit ; /* The current limit on number of entities */
unsigned int next ; /* The next entity when we are doing getNext ops */
ssgEntity **entity_list ; /* The list. */
void sizeChk (void) ;
public:
ssgList ( int init_max = 1 ) ;
virtual ~ssgList (void) ;
ssgEntity *getEntity ( unsigned int n )
{
next = n + 1 ;
return ( n >= total ) ? (ssgEntity *) NULL : entity_list [ n ] ;
}
virtual void addEntity ( ssgEntity *entity ) ;
virtual void removeEntity ( unsigned int n ) ;
void removeAllEntities () ;
void removeEntity ( ssgEntity *entity )
{
removeEntity ( searchForEntity ( entity ) ) ;
}
virtual void replaceEntity ( unsigned int n, ssgEntity *new_entity ) ;
void replaceEntity ( ssgEntity *old_entity, ssgEntity *new_entity )
{
replaceEntity ( searchForEntity ( old_entity ), new_entity ) ;
}
int getNumEntities (void) { return total ; }
ssgEntity *getNextEntity (void) { return getEntity ( next ) ; }
int searchForEntity ( ssgEntity *entity ) ;
} ;
class ssgKidList : public ssgList
{
public:
ssgKidList ( int init_max = 1 ) ;
virtual ~ssgKidList (void) ;
void addEntity ( ssgEntity *entity ) ;
void removeEntity ( unsigned int n ) ;
void removeEntity ( ssgEntity *entity )
{
removeEntity ( searchForEntity ( entity ) ) ;
}
void replaceEntity ( unsigned int n, ssgEntity *new_entity ) ;
void replaceEntity ( ssgEntity *old_entity, ssgEntity *new_entity )
{
replaceEntity ( searchForEntity ( old_entity ), new_entity ) ;
}
} ;
class ssgBase
{
int refc ; /* The number of references to this node */
int unique ; /* A unique number for this node */
protected :
int type ;
int spare ; /* This spare field is used in a bunch of short-term hacks */
char *name ;
ssgBase *user_data ;
virtual void copy_from ( ssgBase *src, int clone_flags ) ;
public:
void *operator new ( size_t size ) ;
void operator delete ( void *ptr ) ;
void deadBeefCheck () { assert ( type != (int) 0xDeadBeef ) ; }
virtual void zeroSpareRecursive ();
virtual void zeroSpare () ;
virtual void incSpare () ;
virtual void setSpare ( int ss ) ;
virtual int getSpare () ;
int getUnique () { return unique ; }
ssgBase (void) ;
virtual ~ssgBase (void) ;
void ref () { refc++ ; }
void deRef () { assert ( refc > 0 ) ; refc-- ; }
int getRef() { return refc ; }
virtual ssgBase *clone ( int clone_flags = 0 ) ;
/* Type checking mechanism */
virtual const char *getTypeName(void) ;
int getType (void) { return type ; }
int isA ( int ty ) { return getType() == ty ; }
int isAKindOf ( int ty ) { return ( getType() & ty ) == ty ; }
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
ssgBase *getUserData () { return user_data ; }
void setUserData ( ssgBase *s )
{
ssgDeRefDelete ( user_data ) ;
user_data = s ;
if ( s != NULL )
s -> ref () ;
}
void setName ( const char *nm ) ;
char *getName () { return name ; }
const char *getPrintableName () { return (name == NULL) ? "NoName" : name ; }
} ;
class ssgSimpleList : public ssgBase
{
protected:
unsigned int total ; /* The total number of things in the list */
unsigned int limit ; /* The current limit on number of things */
unsigned int size_of ; /* The size of each thing */
char *list ; /* The list. */
bool own_mem ; /* Do we own the list memory ? */
void sizeChk ( unsigned int n )
{
if ( (total+n) > limit )
{
if ( ! own_mem )
ulSetError( UL_FATAL, "ssgSimpleList: Cannot resize array." );
/* how big should we make the list? */
limit += limit ; /* double it */
if ( limit <= 0 )
limit = 3;
if ( (total+n) > limit )
limit = (total+n) ;
/* re-allocate the list */
char *nlist = new char [ limit * size_of ] ;
memmove ( nlist, list, total * size_of ) ;
delete [] list ;
list = nlist ;
}
}
virtual void copy_from ( ssgSimpleList *src, int clone_flags ) ;
_SSG_PUBLIC:
ssgSimpleList ()
{
type = ssgTypeSimpleList () ;
limit = 0 ;
size_of = 0 ;
total = 0 ;
list = NULL ;
own_mem = true ;
}
public:
ssgSimpleList ( int sz, int init = 3, char* things = 0 )
{
type = ssgTypeSimpleList () ;
limit = init ;
size_of = sz ;
if ( things )
{
total = init ;
list = things ;
own_mem = false ;
}
else
{
total = 0 ;
list = new char [ limit * size_of ] ;
own_mem = true ;
}
}
virtual ssgBase *clone ( int clone_flags = 0 ) ;
virtual ~ssgSimpleList (void)
{
if ( own_mem )
delete [] list ;
list = NULL ;
} ;
char *raw_get ( unsigned int n )
{
return ( n >= total ) ? ((char *) 0) : & list [ n * size_of ] ;
}
void raw_add ( char *thing )
{
sizeChk ( 1 ) ;
memcpy ( & list [ size_of * total++ ], thing, size_of ) ;
} ;
void raw_add ( char *things, unsigned int n )
{
sizeChk ( n ) ;
memcpy ( & list [ size_of * total ], things, size_of * n ) ;
total += n ;
}
void raw_set ( char *thing, unsigned int n )
{
memcpy ( & list [ size_of * n ], thing, size_of ) ;
} ;
void removeLast ()
{
if ( total > 0 )
total-- ;
}
void removeAll ()
{
if ( own_mem )
delete [] list ;
list = NULL ;
limit = total = 0 ;
}
int compare(ssgSimpleList *other, int print_result=TRUE);
int getSizeOf (void) { return size_of ; }
int getNum (void) { return total ; }
void rawSetNum ( unsigned int n ) /* Better know what you're doing!! */
{
total = n ;
}
void setNum ( unsigned int n )
{
if ( total < n )
{
sizeChk ( n ) ;
memset ( & list [ size_of * total ], 0, size_of * (n-total) ) ;
total = n ;
}
}
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual const char *getTypeName(void) ;
} ;
class ssgVertexArray : public ssgSimpleList
{
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgVertexArray ( int init = 3, sgVec3* things = 0 )
: ssgSimpleList ( sizeof(sgVec3), init, (char*)things )
{
type = ssgTypeVertexArray () ;
}
float *get ( unsigned int n ) { return (float *) raw_get ( n ) ; }
void add ( sgVec3 thing ) { raw_add ( (char *) thing ) ; } ;
void set ( sgVec3 thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ;
void set ( float x, float y, float z, unsigned int n )
{ sgVec3 tmp = { x, y, z } ; raw_set ( (char *) tmp, n ) ; } ;
void add ( float x, float y, float z )
{ sgVec3 tmp = { x, y, z } ; raw_add ( (char *) tmp ) ; } ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual const char *getTypeName(void) ;
} ;
class ssgNormalArray : public ssgSimpleList
{
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgNormalArray ( int init = 3, sgVec3* things = 0 )
: ssgSimpleList ( sizeof(sgVec3), init, (char*)things )
{
type = ssgTypeNormalArray () ;
}
float *get ( unsigned int n ) { return (float *) raw_get ( n ) ; }
void add ( sgVec3 thing ) { raw_add ( (char *) thing ) ; } ;
void set ( sgVec3 thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ;
void set ( float x, float y, float z, unsigned int n )
{ sgVec3 tmp = { x, y, z } ; raw_set ( (char *) tmp, n ) ; } ;
void add ( float x, float y, float z )
{ sgVec3 tmp = { x, y, z } ; raw_add ( (char *) tmp ) ; } ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual const char *getTypeName(void) ;
} ;
class ssgTexCoordArray : public ssgSimpleList
{
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTexCoordArray ( int init = 3, sgVec2* things = 0 )
: ssgSimpleList ( sizeof(sgVec2), init, (char*)things )
{
type = ssgTypeTexCoordArray () ;
}
float *get ( unsigned int n ) { return (float *) raw_get ( n ) ; }
void add ( sgVec2 thing ) { raw_add ( (char *) thing ) ; } ;
void set ( sgVec2 thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ;
void set ( float u, float v, unsigned int n )
{ sgVec2 tmp = { u, v } ; raw_set ( (char *) tmp, n ) ; } ;
void add ( float u, float v )
{ sgVec2 tmp = { u, v } ; raw_add ( (char *) tmp ) ; } ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual const char *getTypeName(void) ;
} ;
class ssgColourArray : public ssgSimpleList
{
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgColourArray ( int init = 3, sgVec4* things = 0 )
: ssgSimpleList ( sizeof(sgVec4), init, (char*)things )
{
type = ssgTypeColourArray () ;
}
float *get ( unsigned int n ) { return (float *) raw_get ( n ) ; }
void add ( sgVec4 thing ) { raw_add ( (char *) thing ) ; } ;
void set ( sgVec4 thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ;
void set ( float r, float g, float b, float a, unsigned int n )
{ sgVec4 tmp = { r,g,b,a } ; raw_set ( (char *) tmp, n ) ; } ;
void add ( float r, float g, float b, float a )
{ sgVec4 tmp = { r,g,b,a } ; raw_add ( (char *) tmp ) ; } ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual const char *getTypeName(void) ;
} ;
class ssgIndexArray : public ssgSimpleList
{
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgIndexArray ( int init = 3, short* things = 0 )
: ssgSimpleList ( sizeof(short), init, (char*)things )
{
type = ssgTypeIndexArray () ;
}
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
short *get ( unsigned int n ) { return (short *) raw_get ( n ) ; }
void add ( short thing ) { raw_add ( (char *) &thing ) ; } ;
void set ( short thing, unsigned int n ) { raw_set ( (char *) &thing, n ) ; } ;
virtual const char *getTypeName(void) ;
} ;
class ssgTransformArray : public ssgSimpleList
{
public:
int selection ; /* used to remember last transform selected */
ssgTransformArray ( int init = 3, sgMat4* things = 0 )
: ssgSimpleList ( sizeof(sgMat4), init, (char*)things )
{
type = ssgTypeTransformArray () ;
selection = 0 ;
}
sgMat4 *get ( unsigned int n ) { return (sgMat4 *) raw_get ( n ) ; }
void add ( sgMat4 thing ) { raw_add ( (char *) thing ) ; } ;
virtual const char *getTypeName(void) ;
} ;
class ssgTexture ;
class ssgTextureArray : private ssgSimpleList
{
public:
ssgTextureArray ( int init = 3 )
: ssgSimpleList ( sizeof(ssgTexture*), init )
{
//type = ssgTypeTextureArray () ;
}
int getNum (void) { return total ; }
ssgTexture* get ( unsigned int n )
{ return *( (ssgTexture**) raw_get ( n ) ) ; }
void add ( ssgTexture* thing ) ;
void removeAll () ;
ssgTexture* findByFilename ( const char* fname ) ;
} ;
class ssgSimpleState ;
class ssgSimpleStateArray : private ssgSimpleList
{
void collect_recursive ( ssgEntity *e );
public:
ssgSimpleStateArray ( int init = 3 )
: ssgSimpleList ( sizeof(ssgSimpleState*), init )
{
//type = ssgTypeSimpleStateArray () ;
}
int getNum (void) { return total ; }
ssgSimpleState* get ( unsigned int n )
{
assert(n<total);
return *( (ssgSimpleState**) raw_get ( n ) ) ;
}
void add ( ssgSimpleState* ss ) ;
void removeAll () ;
ssgSimpleState* findMatch ( ssgSimpleState* ss ) ;
void collect ( ssgEntity *e );
int findIndex ( ssgSimpleState* st ) ; //returns -1 if not found
} ;
struct ssgInterleavedArrayElement
{
sgVec2 texCoord ;
sgVec4 colour ;
sgVec3 normal ;
sgVec3 vertex ;
} ;
class ssgInterleavedArray : public ssgSimpleList
{
public:
ssgInterleavedArray ( int init = 3, ssgInterleavedArrayElement* things = 0 )
: ssgSimpleList ( sizeof(ssgInterleavedArrayElement), init, (char*)things )
{
type = ssgTypeInterleavedArray () ;
}
ssgInterleavedArrayElement *get ( unsigned int n ) { return (ssgInterleavedArrayElement *) raw_get ( n ) ; }
void add ( ssgInterleavedArrayElement thing ) { raw_add ( (char *) &thing ) ; } ;
void add ( ssgInterleavedArrayElement *thing ) { raw_add ( (char *) thing ) ; } ;
void set ( ssgInterleavedArrayElement thing, unsigned int n ) { raw_set ( (char *) &thing, n ) ; } ;
void set ( ssgInterleavedArrayElement *thing, unsigned int n ) { raw_set ( (char *) thing, n ) ; } ;
virtual const char *getTypeName(void) ;
} ;
struct ssgTextureInfo
{
unsigned int width ;
unsigned int height ;
unsigned int depth ;
unsigned int alpha ;
} ;
bool ssgLoadTexture ( const char *fname, ssgTextureInfo* info=0 ) ;
bool ssgLoadPNG ( const char *fname, ssgTextureInfo* info ) ;
bool ssgLoadSGI ( const char *fname, ssgTextureInfo* info ) ;
bool ssgLoadBMP ( const char *fname, ssgTextureInfo* info ) ;
bool ssgLoadTGA ( const char *fname, ssgTextureInfo* info ) ;
bool ssgLoadMDLTexture ( const char *fname, ssgTextureInfo* info ) ;
bool ssgLoadPCX ( const char *fname, ssgTextureInfo* info ) ;
void ssgAddTextureFormat ( const char* extension,
bool (*) (const char*, ssgTextureInfo* info) ) ;
int ssgGetNumTexelsLoaded () ;
bool ssgMakeMipMaps ( GLubyte *image, int xsize, int ysize, int zsize, bool freeData = true ) ;
class ssgTexture : public ssgBase
{
protected:
char *filename ;
int own_handle ;
GLuint handle ;
int wrapu, wrapv, mipmap ;
bool has_alpha ;
void alloc_handle () ;
void free_handle () ;
protected:
virtual void copy_from ( ssgTexture *src, int clone_flags ) ;
void setDefaultGlParams(int wrapu, int wrapv, int mipmap);
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTexture () ;
// This constructor loads the texture from file for you:
ssgTexture ( const char *fname, int wrapu = TRUE, int wrapv = TRUE,
int mipmap = TRUE );
// use this constructor if you already have the texture in memory
ssgTexture ( const char *fname, GLubyte *image, int xsize, int ysize, int zsize,
int wrapu = TRUE, int wrapv = TRUE);
virtual ~ssgTexture (void) ;
bool hasAlpha () const { return has_alpha ; }
GLuint getHandle () { return handle ; }
/*
WARNING - setHandle() IS DEPRECATED
BECAUSE IT LEAKS texture handles!
*/
void setHandle ( GLuint handle ) ;
char *getFilename(void) { return filename ; }
void setFilename(const char *fname)
{
delete [] filename ;
if ( fname == NULL )
filename = NULL ;
else
filename = ulStrDup ( fname ) ;
}
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual const char *getTypeName(void) ;
} ;
typedef int (*ssgCallback)( ssgEntity * ) ;
#define SSG_CALLBACK_PREDRAW 1
#define SSG_CALLBACK_POSTDRAW 2
typedef int (*ssgTravCallback)( ssgEntity *entity, int traversal_mask ) ;
#define SSG_CALLBACK_PRETRAV 1
#define SSG_CALLBACK_POSTTRAV 2
class ssgState ;
typedef int (*ssgStateCallback)( ssgState *entity ) ;
#define SSG_CALLBACK_PREAPPLY 3
class ssgState : public ssgBase
{
int translucent ;
int external_property_index ;
ssgStateCallback preApplyCB ;
ssgStateCallback preDrawCB ;
ssgStateCallback postDrawCB ;
protected:
void preApply () ;
void preDraw () ;
public:
virtual void copy_from ( ssgState *src, int clone_flags ) ;
ssgState (void) ;
virtual ~ssgState (void) ;
virtual const char *getTypeName(void) ;
ssgStateCallback getStateCallback ( int cb_type )
{
return ( cb_type == SSG_CALLBACK_PREAPPLY ) ? preApplyCB :
( cb_type == SSG_CALLBACK_PREDRAW ) ? preDrawCB :
postDrawCB ;
}
void setStateCallback ( int cb_type, ssgStateCallback cb )
{
if ( cb_type == SSG_CALLBACK_PREAPPLY )
preApplyCB = cb ;
else
if ( cb_type == SSG_CALLBACK_PREDRAW )
preDrawCB = cb ;
else
postDrawCB = cb ;
}
int getExternalPropertyIndex (void) { return external_property_index ; }
void setExternalPropertyIndex ( int i ) { external_property_index = i ; }
virtual int isTranslucent (void) { return translucent ; }
virtual void setTranslucent (void) { translucent = TRUE ; }
virtual void setOpaque (void) { translucent = FALSE ; }
virtual void force (void) = 0 ;
virtual void apply (void) = 0 ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgSimpleState : public ssgState
{
_SSG_PUBLIC:
int dont_care ;
int enables ;
ssgTexture* texture ;
int mipmap;
int colour_material_mode ;
sgVec4 specular_colour ;
sgVec4 emission_colour ;
sgVec4 ambient_colour ;
sgVec4 diffuse_colour ;
GLenum shade_model ;
float shininess ;
float alpha_clamp ;
ssgSimpleState ( int I_am_current_state ) ;
protected:
public:
virtual void copy_from ( ssgSimpleState *src, int clone_flags ) ;
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgSimpleState (void) ;
virtual ~ssgSimpleState (void) ;
virtual const char *getTypeName(void) ;
virtual void force (void) ;
virtual void apply (void) ;
virtual void care_about ( int mode ) { dont_care &= ~(1<<mode) ; }
virtual void dont_care_about ( int mode ) { dont_care |= (1<<mode) ; }
virtual int getCareAbout ( int mode ) { return dont_care & (1<<mode) ; }
virtual int isEnabled ( GLenum mode ) ;
virtual void disable ( GLenum mode ) ;
virtual void enable ( GLenum mode ) ;
virtual void set ( GLenum mode, int val )
{ val ? enable(mode) : disable(mode) ; }
virtual GLuint getTextureHandle (void)
{
if ( texture != NULL )
return texture -> getHandle () ;
return 0 ;
}
virtual char *getTextureFilename(void)
{
if ( texture != NULL )
return texture -> getFilename () ;
return NULL ;
}
virtual ssgTexture* getTexture (void)
{
return texture ;
}
virtual void setTexture ( ssgTexture *tex )
{
ssgDeRefDelete ( texture ) ;
texture = tex ;
if ( texture != NULL )
{
care_about ( SSG_GL_TEXTURE ) ;
texture -> ref () ;
}
else
{
dont_care_about ( SSG_GL_TEXTURE ) ;
}
}
virtual void setTexture ( const char *fname,
int _wrapu = TRUE, int _wrapv = TRUE, int _mipmap = TRUE )
{
mipmap = _mipmap ;
setTexture ( new ssgTexture ( fname, _wrapu, _wrapv, mipmap ) ) ;
}
/*
WARNING - THIS FORM OF setTexture IS DEPRECATED
BECAUSE IT PREVENTS ssgSave FROM SAVING THE
TEXTURE FILENAME and it LEAKS texture handles!
*/
virtual void setTexture ( GLuint tex )
{
if ( !texture )
setTexture ( new ssgTexture ) ;
texture -> setHandle ( tex ) ;
texture -> setFilename ( NULL ) ;
}
virtual void setTextureFilename ( const char *fname )
{
if ( !texture )
setTexture ( new ssgTexture ) ;
texture -> setFilename ( fname ) ;
}
virtual GLenum getColourMaterial ()
{
return (GLenum) colour_material_mode ;
}
virtual void setColourMaterial ( GLenum which )
{
colour_material_mode = (int) which ;
care_about ( SSG_GL_COLOR_MATERIAL ) ;
}
virtual void setMaterial ( GLenum which, float r, float g,
float b, float a = 1.0f )
{
sgVec4 rgba ;
sgSetVec4 ( rgba, r, g, b, a ) ;
setMaterial ( which, rgba ) ;
}
virtual void setMaterial ( GLenum which, sgVec4 rgba )
{
switch ( which )
{
case GL_EMISSION : sgCopyVec4 ( emission_colour, rgba ) ;
care_about ( SSG_GL_EMISSION ) ;
break ;
case GL_SPECULAR : sgCopyVec4 ( specular_colour, rgba ) ;
care_about ( SSG_GL_SPECULAR ) ;
break ;
case GL_AMBIENT : sgCopyVec4 ( ambient_colour , rgba ) ;
care_about ( SSG_GL_AMBIENT ) ;
break ;
case GL_DIFFUSE : sgCopyVec4 ( diffuse_colour , rgba ) ;
care_about ( SSG_GL_DIFFUSE ) ;
break ;
case GL_AMBIENT_AND_DIFFUSE : // in compliance with glMaterial
sgCopyVec4 ( ambient_colour , rgba ) ;
sgCopyVec4 ( diffuse_colour , rgba ) ;
care_about ( SSG_GL_AMBIENT | SSG_GL_DIFFUSE ) ;
break ;
default : break ;
}
}
virtual float *getMaterial ( GLenum which )
{
switch ( which )
{
case GL_EMISSION : return emission_colour ;
case GL_SPECULAR : return specular_colour ;
case GL_AMBIENT : return ambient_colour ;
case GL_DIFFUSE : return diffuse_colour ;
default: break ;
}
return NULL ;
}
virtual float getShininess (void)
{
return shininess ;
}
virtual void setShininess ( float sh )
{
care_about ( SSG_GL_SHININESS ) ;
shininess = sh ;
}
virtual void setShadeModel ( GLenum model )
{
care_about ( SSG_GL_SHADE_MODEL ) ;
shade_model = model ;
}
virtual void setAlphaClamp ( float clamp )
{
care_about ( SSG_GL_ALPHA_TEST ) ;
alpha_clamp = clamp ;
}
/*int getWrapU();
int getWrapV();*/
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgStateSelector : public ssgSimpleState
{
int nstates ;
int selection ;
_SSG_PUBLIC:
ssgSimpleState **statelist ;
protected:
virtual void copy_from ( ssgStateSelector *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgStateSelector () ;
ssgStateSelector ( int ns ) ;
virtual ~ssgStateSelector (void) ;
virtual const char *getTypeName(void) ;
int getNumSteps ( void ) { return nstates ; }
void selectStep ( unsigned int s ) ;
unsigned int getSelectStep (void) ;
ssgSimpleState *getCurrentStep (void) ;
void setStep ( int i, ssgSimpleState *step ) ;
ssgSimpleState *getStep ( int i ) ;
virtual int isTranslucent (void) ;
virtual void setTranslucent (void) ;
virtual void setOpaque (void) ;
void force (void) ;
void apply (void) ;
void care_about ( int mode ) ;
void dont_care_about ( int mode ) ;
int isEnabled ( GLenum mode ) ;
void disable ( GLenum mode ) ;
void enable ( GLenum mode ) ;
char *getTextureFilename(void) ;
void setTextureFilename(char *fname) ;
void setTexture ( char *fname,
int _wrapu = TRUE,
int _wrapv = TRUE,
int _mipmap = TRUE ) ;
GLuint getTextureHandle (void) ;
void setTexture ( ssgTexture *tex ) ;
/*
WARNING - THIS FORM OF setTexture IS DEPRECATED
BECAUSE IT PREVENTS ssgSave FROM SAVING THE
TEXTURE FILENAME and LEAKS texture handles!
*/
void setTexture ( GLuint tex ) ;
void setColourMaterial(GLenum which);
void setMaterial ( GLenum which, float r, float g,
float b, float a = 1.0f ) ;
void setMaterial ( GLenum which, sgVec4 rgba ) ;
float *getMaterial ( GLenum which ) ;
float getShininess (void) ;
void setShininess ( float sh ) ;
void setShadeModel ( GLenum model ) ;
void setAlphaClamp ( float clamp ) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
struct ssgEntityBinding
{
ssgEntity **entity ;
char *nameOrPath ;
} ;
class ssgEntity : public ssgBase
{
ssgList parents ;
int traversal_mask ;
ssgTravCallback preTravCB ;
ssgTravCallback postTravCB ;
protected:
sgSphere bsphere ;
int bsphere_is_invalid ;
void emptyBSphere () { bsphere.empty () ; }
void visualiseBSphere () ;
void extendBSphere ( sgSphere *s ) { bsphere.extend ( s ) ; }
void extendBSphere ( sgBox *b ) { bsphere.extend ( b ) ; }
void extendBSphere ( sgVec3 v ) { bsphere.extend ( v ) ; }
virtual ssgCullResult cull_test ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual ssgCullResult isect_test ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual ssgCullResult hot_test ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual ssgCullResult los_test ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void copy_from ( ssgEntity *src, int clone_flags ) ;
public:
ssgEntity (void) ;
virtual ~ssgEntity (void) ;
int getTraversalMask () { return traversal_mask ;}
void setTraversalMask ( int t ) { traversal_mask = t ; }
void setTraversalMaskBits ( int t ) { traversal_mask |= t ; }
void clrTraversalMaskBits ( int t ) { traversal_mask &= ~t ; }
ssgTravCallback getTravCallback ( int cb_type )
{
return ( cb_type == SSG_CALLBACK_PRETRAV ) ? preTravCB : postTravCB ;
}
void setTravCallback ( int cb_type, ssgTravCallback cb )
{
if ( cb_type == SSG_CALLBACK_PRETRAV )
preTravCB = cb ;
else
postTravCB = cb ;
}
int preTravTests ( int *test_needed, int which ) ;
void postTravTests ( int which ) ;
virtual void getNetTransform ( sgMat4 xform ) ;
virtual void getLastNetTransform ( sgMat4 xform ) ;
/* for backward compatibility */
virtual ssgCallback getCallback ( int cb_type ) ;
virtual void setCallback ( int cb_type, ssgCallback cb ) ;
virtual ssgEntity* getByName ( char *nm ) ;
virtual ssgEntity* getByPath ( char *path ) ;
int bindEntities ( ssgEntityBinding *bind ) ;
virtual void recalcBSphere (void) = 0 ;
int isDirtyBSphere (void) { return bsphere_is_invalid ; }
void dirtyBSphere () ;
sgSphere *getBSphere ()
{
if ( isDirtyBSphere () )
recalcBSphere () ;
return & bsphere ;
}
virtual int getNumKids (void) { return 0 ; }
int getNumParents () { return parents.getNumEntities () ; }
ssgBranch *getParent ( int p ) { return (ssgBranch *) parents.getEntity ( p ) ; }
ssgBranch *getNextParent () { return (ssgBranch *) parents.getNextEntity () ; }
void addParent ( ssgEntity *entity ) { parents.addEntity ( entity ) ; }
void removeParent ( ssgEntity *entity ) { parents.removeEntity ( entity ) ; }
virtual const char *getTypeName(void) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) = 0 ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) = 0 ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) = 0 ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) = 0 ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual void getStats ( int *num_branches, int *num_leaves, int *num_tris, int *num_vertices ) = 0 ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgLeaf : public ssgEntity
{
int cull_face ;
ssgState *state ;
protected:
GLenum gltype ;
ssgCallback preDrawCB ;
ssgCallback postDrawCB ;
#ifdef _SSG_USE_DLIST
GLuint dlist ;
#endif
virtual void draw_geometry () = 0 ;
int preDraw () ;
virtual void copy_from ( ssgLeaf *src, int clone_flags ) ;
public:
ssgLeaf (void) ;
virtual ~ssgLeaf (void) ;
virtual void drawHighlight ( sgVec4 colour ) = 0 ;
virtual void drawHighlight ( sgVec4 colour, int i ) = 0 ;
virtual void pick ( int baseName ) = 0 ;
#ifdef _SSG_USE_DLIST
void makeDList () ;
void deleteDList () ;
GLuint getDListIndex () { return dlist ; }
#endif
int getExternalPropertyIndex ()
{ return state ? state->getExternalPropertyIndex() : 0 ; }
int isTranslucent () { return state ? state->isTranslucent() : FALSE ; }
int hasState () { return state != NULL ; }
ssgState *getState () { return state ; }
void setState ( ssgState *st ); //~~ T.G. Body extended & moved into CXX file
virtual ssgCallback getCallback ( int cb_type )
{
return ( cb_type == SSG_CALLBACK_PREDRAW ) ? preDrawCB : postDrawCB ;
}
virtual void setCallback ( int cb_type, ssgCallback cb )
{
if ( cb_type == SSG_CALLBACK_PREDRAW )
preDrawCB = cb ;
else
postDrawCB = cb ;
}
virtual void setPrimitiveType ( GLenum ty ) { gltype = ty ; }
virtual GLenum getPrimitiveType () { return gltype ; }
/* For backwards compatibility only -- DEPRECATED */
GLenum getGLtype () { return getPrimitiveType() ; }
virtual int getNumVertices () { return 0 ; }
virtual int getNumNormals () { return 0 ; }
virtual int getNumColours () { return 0 ; }
virtual int getNumTexCoords () { return 0 ; }
virtual float *getVertex ( int i ) = 0 ;
virtual float *getNormal ( int i ) = 0 ;
virtual float *getColour ( int i ) = 0 ;
virtual float *getTexCoord ( int i ) = 0 ;
virtual int getNumTriangles () = 0 ;
virtual void getTriangle ( int n, short *v1, short *v2, short *v3 ) = 0 ;
virtual int getNumLines () = 0 ;
virtual void getLine ( int n, short *v1, short *v2 ) = 0 ;
virtual void transform ( const sgMat4 m ) = 0 ;
void setCullFace ( int cf ) { cull_face = cf ; }
int getCullFace () { return cull_face ; }
virtual void recalcBSphere () = 0 ;
virtual const char *getTypeName(void) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual void getStats ( int *num_branches, int *num_leaves, int *num_tris, int *num_vertices ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void isect_triangles ( sgSphere *s, sgMat4 m, int test_needed ) = 0 ;
virtual void hot_triangles ( sgVec3 s, sgMat4 m, int test_needed ) = 0 ;
virtual void los_triangles ( sgVec3 s, sgMat4 m, int test_needed ) = 0 ;
virtual void draw () = 0 ;
} ;
extern sgVec3 _ssgVertex000 ;
extern sgVec4 _ssgColourWhite ;
extern sgVec3 _ssgNormalUp ;
extern sgVec2 _ssgTexCoord00 ;
extern short _ssgIndex0 ;
extern float _ssgGlobTime ; // used by ssgAnimTransform. Has to be set by the appliation!
class ssgVTable : public ssgLeaf
{
protected:
sgBox bbox ;
int indexed ;
sgVec3 *vertices ; int num_vertices ; unsigned short *v_index ;
sgVec3 *normals ; int num_normals ; unsigned short *n_index ;
sgVec2 *texcoords ; int num_texcoords ; unsigned short *t_index ;
sgVec4 *colours ; int num_colours ; unsigned short *c_index ;
virtual void draw_geometry () ;
virtual void copy_from ( ssgVTable *src, int clone_flags ) ;
_SSG_PUBLIC:
int isIndexed () { return indexed ; }
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgVTable () ;
ssgVTable ( GLenum ty,
int nv, unsigned short *vi, sgVec3 *vl,
int nn, unsigned short *ni, sgVec3 *nl,
int nt, unsigned short *ti, sgVec2 *tl,
int nc, unsigned short *ci, sgVec4 *cl ) ;
ssgVTable ( GLenum ty,
int nv, sgVec3 *vl,
int nn, sgVec3 *nl,
int nt, sgVec2 *tl,
int nc, sgVec4 *cl ) ;
virtual void drawHighlight ( sgVec4 colour ) ;
virtual void drawHighlight ( sgVec4 colour, int i ) ;
virtual void pick ( int baseName ) ;
virtual void transform ( const sgMat4 m ) ;
int getNumVertices () { return num_vertices ; }
int getNumNormals () { return num_normals ; }
int getNumColours () { return num_colours ; }
int getNumTexCoords () { return num_texcoords ; }
int getNumTriangles () ;
void getTriangle ( int n, short *v1, short *v2, short *v3 ) ;
int getNumLines () ;
void getLine ( int n, short *v1, short *v2 ) ;
void getColourList ( void **list, unsigned short **idx )
{
*list = colours ;
*idx = c_index ;
}
void getTexCoordList ( void **list, unsigned short **idx )
{
*list = texcoords ;
*idx = t_index ;
}
void getNormalList ( void **list, unsigned short **idx )
{
*list = normals ;
*idx = n_index ;
}
void getVertexList ( void **list, unsigned short **idx )
{
*list = vertices ;
*idx = v_index ;
}
float *getVertex (int i){ if(i>=num_vertices)i=num_vertices-1;
return (num_vertices<=0) ? _ssgVertex000 :
((indexed)?vertices [v_index[i]]:vertices [i]);}
float *getColour (int i){ if(i>=num_colours)i=num_colours-1;
return (num_colours<=0) ? _ssgColourWhite :
((indexed)?colours [c_index[i]]:colours [i]);}
float *getNormal (int i){ if(i>=num_normals)i=num_normals-1;
return (num_normals<=0) ? _ssgNormalUp :
((indexed)?normals [n_index[i]]:normals [i]);}
float *getTexCoord(int i){ if(i>=num_texcoords)i=num_texcoords-1;
return (num_texcoords<=0) ? _ssgTexCoord00 :
((indexed)?texcoords[t_index[i]]:texcoords[i]);}
virtual ~ssgVTable (void) ;
virtual const char *getTypeName(void) ;
virtual void recalcBSphere () ;
virtual void draw () ;
virtual void isect_triangles ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot_triangles ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los_triangles ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgVtxTable : public ssgLeaf
{
protected:
sgBox bbox ;
virtual void draw_geometry () ;
virtual void copy_from ( ssgVtxTable *src, int clone_flags ) ;
_SSG_PUBLIC:
ssgVertexArray *vertices ;
ssgNormalArray *normals ;
ssgTexCoordArray *texcoords ;
ssgColourArray *colours ;
public:
int compare(ssgVtxTable *other, int print_result=TRUE);
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgVtxTable () ;
ssgVtxTable ( GLenum ty, ssgVertexArray *vl,
ssgNormalArray *nl,
ssgTexCoordArray *tl,
ssgColourArray *cl ) ;
void textureMe(float uP, float vP)
{ texcoords = new ssgTexCoordArray;
for(int i=vertices->getNum()-1; i>=0; i--)
{ sgVec2 v;
v[0] = uP; v[1] = vP;
texcoords->add(v);
}
}
virtual void drawHighlight ( sgVec4 colour ) ;
virtual void drawHighlight ( sgVec4 colour, int i ) ;
virtual void pick ( int baseName ) ;
virtual void transform ( const sgMat4 m ) ;
ssgVertexArray *getVertices () { return vertices ; }
ssgNormalArray *getNormals () { return normals ; }
ssgTexCoordArray *getTexCoords () { return texcoords ; }
ssgColourArray *getColours () { return colours ; }
virtual void setVertices ( ssgVertexArray *vl ) ;
virtual void setNormals ( ssgNormalArray *nl ) ;
virtual void setTexCoords ( ssgTexCoordArray *tl ) ;
virtual void setColours ( ssgColourArray *cl ) ;
int getNumVertices () { return vertices -> getNum () ; }
int getNumNormals () { return normals -> getNum () ; }
int getNumColours () { return colours -> getNum () ; }
int getNumTexCoords () { return texcoords -> getNum () ; }
/* Don't call this unless you know what you are doing!! */
void rawSetNumVertices ( unsigned int n ) { vertices -> rawSetNum ( n ) ; }
int getNumTriangles () ;
void getTriangle ( int n, short *v1, short *v2, short *v3 ) ;
int getNumLines () ;
void getLine ( int n, short *v1, short *v2 ) ;
void getVertexList ( void **list ) { *list = vertices -> get ( 0 ) ; }
void getNormalList ( void **list ) { *list = normals -> get ( 0 ) ; }
void getTexCoordList ( void **list ) { *list = texcoords -> get ( 0 ) ; }
void getColourList ( void **list ) { *list = colours -> get ( 0 ) ; }
float *getVertex (int i){ int nv=getNumVertices(); if(i>=nv)i=nv-1;
return (nv<=0) ? _ssgVertex000:vertices->get(i);}
float *getNormal (int i){ int nn=getNumNormals(); if(i>=nn)i=nn-1;
return (nn<=0) ? _ssgNormalUp:normals->get(i);}
float *getTexCoord(int i){ int nc=getNumTexCoords(); if(i>=nc)i=nc-1;
return (nc<=0) ? _ssgTexCoord00:texcoords->get(i);}
float *getColour (int i){ int nc=getNumColours(); if(i>=nc)i=nc-1;
return (nc<=0) ? _ssgColourWhite:colours->get(i);}
ssgVtxArray *getAs_ssgVtxArray ();
virtual ~ssgVtxTable (void) ;
virtual const char *getTypeName(void) ;
virtual void recalcBSphere () ;
virtual void draw () ;
virtual void isect_triangles ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot_triangles ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los_triangles ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2);
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgTween : public ssgVtxTable
{
virtual void copy_from ( ssgTween *src, int clone_flags ) ;
void init () ;
protected:
_SSG_PUBLIC:
int curr_bank ;
ssgVertexArray *render_vertices ;
ssgNormalArray *render_normals ;
ssgTexCoordArray *render_texcoords ;
ssgColourArray *render_colours ;
ulList *banked_vertices ;
ulList *banked_normals ;
ulList *banked_texcoords ;
ulList *banked_colours ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTween () ;
ssgTween ( GLenum ty ) ;
virtual void setVertices ( ssgVertexArray *vl ) ;
virtual void setNormals ( ssgNormalArray *nl ) ;
virtual void setTexCoords ( ssgTexCoordArray *tl ) ;
virtual void setColours ( ssgColourArray *cl ) ;
virtual void recalcBSphere () ;
virtual void draw () ;
virtual void transform ( const sgMat4 m ) ;
virtual const char *getTypeName(void) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2);
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
int getNumBanks () { return banked_vertices -> getNumEntities () ; }
int newBank ( ssgVertexArray *vl, ssgNormalArray *nl,
ssgTexCoordArray *tl, ssgColourArray *cl ) ;
int newBank ( int newVertices , int newNormals,
int newTexCoords, int newColours ) ;
void setBank ( int bank ) ;
virtual ~ssgTween (void) ;
} ;
class ssgVtxArray : public ssgVtxTable
{
protected:
ssgIndexArray *indices;
virtual void draw_geometry () ;
virtual void copy_from ( ssgVtxArray *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgVtxArray () ;
ssgVtxArray ( GLenum ty, ssgVertexArray *vl,
ssgNormalArray *nl,
ssgTexCoordArray *tl,
ssgColourArray *cl,
ssgIndexArray *il ) ;
virtual void drawHighlight ( sgVec4 colour ) ;
virtual void drawHighlight ( sgVec4 colour, int i ) ;
virtual void pick ( int baseName ) ;
void setIndices ( ssgIndexArray *il ) ;
void addIndex ( short i) { indices->add(i); }
int getNumIndices () { return indices -> getNum () ; }
int getNumTriangles () ;
void getTriangle ( int n, short *v1, short *v2, short *v3 ) ;
int getNumLines () ;
void getLine ( int n, short *v1, short *v2 ) ;
void getIndexList ( void **list ) { *list = indices -> get ( 0 ) ; }
short *getIndex (int i){ int ni=getNumIndices();if(i>=ni)i=ni-1;
return (ni<=0) ? &_ssgIndex0 : indices->get(i);}
void removeUnusedVertices();
virtual ~ssgVtxArray (void) ;
virtual const char *getTypeName(void) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
// class ssgVtxInterleavedArray
class ssgBranch : public ssgEntity
{
ssgKidList kids ;
protected:
virtual void copy_from ( ssgBranch *src, int clone_flags ) ;
public:
virtual void zeroSpareRecursive ();
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgBranch (void) ;
virtual ~ssgBranch (void) ;
virtual int getNumKids (void) { return kids.getNumEntities() ; }
ssgEntity *getKid ( int n ) { return kids.getEntity ( n ) ; }
ssgEntity *getNextKid (void) { return kids.getNextEntity () ; }
int searchForKid ( ssgEntity *entity )
{ return kids.searchForEntity(entity); }
void addKid ( ssgEntity *entity ) ;
void removeKid ( int n ) ;
void removeKid ( ssgEntity *entity ) ;
void removeAllKids (void) ;
void replaceKid ( int n, ssgEntity *new_entity ) ;
void replaceKid ( ssgEntity *old_entity, ssgEntity *new_entity ) ;
void mergeHNodes();
virtual ssgEntity *getByName ( char *match ) ;
virtual ssgEntity *getByPath ( char *path ) ;
virtual const char *getTypeName(void) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual void getStats ( int *num_branches, int *num_leaves, int *num_tris, int *num_vertices ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void recalcBSphere () ;
} ;
#define SSGTWEEN_STOP_AT_END 0
#define SSGTWEEN_REPEAT 1
class ssgTweenController : public ssgBranch
{
float curr_bank ;
int mode ; /* STOP_AT_END or REPEAT */
protected:
virtual void copy_from ( ssgTweenController *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTweenController (void) ;
virtual ~ssgTweenController (void) ;
void setMode ( int _mode ) { mode = _mode ; }
int getMode () { return mode ; }
void selectBank ( float f ) { curr_bank = f ; }
float getCurrBank () { return curr_bank ; }
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual const char *getTypeName(void) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgInvisible : public ssgBranch
{
protected:
virtual void copy_from ( ssgInvisible *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgInvisible (void) ;
virtual ~ssgInvisible (void) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgSelector : public ssgBranch
{
unsigned char* selection ;
protected:
int max_kids ;
virtual void copy_from ( ssgSelector *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgSelector ( int max_kids = 32 ) ;
virtual ~ssgSelector (void) ;
void selectStep ( unsigned int s )
{
memset ( selection, 0, max_kids ) ;
selection [s] = 1 ;
}
void select ( unsigned int s )
{
for ( int i=0; i<max_kids && i<32; i++ )
selection [i] = ( (1<<i) & s ) != 0 ;
}
unsigned int getSelect ()
{
unsigned int s = 0 ;
for ( int i=0; i<max_kids && i<32; i++ )
if ( selection [i] ) s |= (1<<i) ;
return s ;
}
int isSelected ( unsigned int i ) const
{
return (i<(unsigned int)max_kids) ? selection [ i ] : FALSE ;
}
int getFirstSelection ()
{
int res ;
for ( res = 0 ; res < max_kids && ! selection[res] ; res++ )
/* Look for first selection */ ;
return ( res < max_kids ) ? res : -1 ;
}
ssgEntity *getFirstSelectedKid ()
{
int k = getFirstSelection () ;
return (k >= 0) ? getKid ( k ) : NULL ;
}
int getMaxKids (void) const { return max_kids ; }
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
} ;
class ssgRangeSelector : public ssgSelector
{
int additive ;
float rng_list [ 33 ] ;
protected:
virtual void copy_from ( ssgRangeSelector *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgRangeSelector (void) ;
virtual ~ssgRangeSelector (void) ;
void setRanges ( float *ranges, unsigned int nranges )
{
for ( unsigned int i = 0 ; i < 33 ; i++ )
if ( i < nranges )
rng_list [ i ] = ranges [ i ] ;
else
rng_list [ i ] = SG_MAX ;
}
void setRange ( unsigned int which, float range )
{
if ( which < 33 )
rng_list [ which ] = range ;
}
float *getRanges ()
{
return rng_list ;
}
float getRange ( unsigned int which )
{
return ( which < 33 ) ? rng_list[which] : SG_MAX ;
}
void setAdditive ( int add ) { additive = add ; }
int isAdditive () { return additive ; }
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
} ;
enum ssgAnimEnum
{
SSG_ANIM_START,
SSG_ANIM_STOP,
SSG_ANIM_PAUSE,
SSG_ANIM_RESUME
} ;
enum ssgAnimDirection
{
SSG_ANIM_SWING,
SSG_ANIM_ONESHOT,
SSG_ANIM_SHUTTLE
} ;
enum ssgAnimTimeMode
{
SSG_ANIM_FRAME,
SSG_ANIM_CLOCK
};
class ssgTimedSelector : public ssgSelector
{
_SSG_PUBLIC:
ssgAnimEnum running ;
ssgAnimDirection mode ;
double start_time ;
double pause_time ;
double loop_time ;
float *times ;
int curr ;
int start ;
int end ;
protected:
ssgAnimTimeMode time_mode ;
static ulClock ck ;
void compute_loop_time ()
{
loop_time = 0 ;
for ( int k = start ; k <= end ; k++ )
loop_time += times [ k ] ;
}
virtual void copy_from ( ssgTimedSelector *src, int clone_flags ) ;
double get_time() const
{
if (time_mode == SSG_ANIM_FRAME)
return (double) ssgGetFrameCounter() ;
else
return ck.update(), ck.getAbsTime();
}
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTimedSelector ( int max_kids = 32 ) ;
virtual ~ssgTimedSelector (void) ;
virtual const char *getTypeName(void) ;
int getStep () ;
ssgAnimTimeMode getTimeMode() const { return time_mode; }
float getDuration ( int i = 0 ) { return times [ i ] ; }
void setDuration ( float ti, int i = -1, ssgAnimTimeMode m = SSG_ANIM_FRAME )
{
time_mode = m;
if ( i >= 0 && i < max_kids )
times [ i ] = ti ;
else
for ( int j = 0 ; j < max_kids ; j++ )
times [ j ] = ti ;
compute_loop_time () ;
}
void control ( ssgAnimEnum m )
{
compute_loop_time () ;
if ( m == SSG_ANIM_PAUSE )
{
pause_time = get_time() ;
curr = getStep () ;
}
else
if ( m == SSG_ANIM_RESUME )
{
start_time += get_time () - pause_time ;
if ( running != SSG_ANIM_STOP )
m = SSG_ANIM_START ;
}
else
if ( m == SSG_ANIM_START )
{
start_time = get_time () ;
curr = getStep () ;
}
running = m ;
}
ssgAnimEnum getControl () { return running ; }
void setMode ( ssgAnimDirection m ) { mode = m ; }
ssgAnimDirection getMode () { return mode ; }
void setLimits ( int st, int en )
{
curr = st ;
start = st ;
end = en ;
compute_loop_time () ;
}
void getLimits ( int *st, int *en )
{
if ( st != NULL ) *st = start ;
if ( en != NULL ) *en = end ;
}
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
} ;
class ssgBaseTransform : public ssgBranch
{
protected:
sgMat4 transform ;
sgMat4 last_transform ;
int last_updated ;
int first_time ;
virtual void copy_from ( ssgBaseTransform *src, int clone_flags ) ;
public:
ssgBaseTransform (void) ;
virtual ~ssgBaseTransform (void) ;
void firsttime ()
{
if ( first_time )
{
first_time = FALSE ;
updateTransform () ;
}
}
void updateTransform ()
{
sgCopyMat4 ( last_transform, transform ) ;
last_updated = ssgGetFrameCounter () ;
}
void getLastTransform ( sgMat4 xform )
{
/*
If the transform was not updated this - or last frame
then we need to equate the two transforms.
*/
if ( last_updated < ssgGetFrameCounter () - 1 )
updateTransform () ;
sgCopyMat4 ( xform, last_transform ) ;
}
void getTransform ( sgMat4 xform )
{
sgCopyMat4 ( xform, transform ) ;
}
virtual void setTransform ( sgVec3 xyz ) = 0 ;
virtual void setTransform ( sgCoord *xform ) = 0 ;
virtual void setTransform ( sgCoord *xform, float sx, float sy, float sz )=0;
virtual void setTransform ( sgMat4 xform ) = 0 ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual const char *getTypeName(void) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
} ;
class ssgTransform : public ssgBaseTransform
{
protected:
virtual void copy_from ( ssgTransform *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTransform (void) ;
ssgTransform ( sgCoord *c ) ;
virtual ~ssgTransform (void) ;
virtual void setTransform ( sgVec3 xyz ) ;
virtual void setTransform ( sgCoord *xform ) ;
virtual void setTransform ( sgCoord *xform, float sx, float sy, float sz ) ;
virtual void setTransform ( sgMat4 xform ) ;
virtual void getNetTransform ( sgMat4 xform ) ;
virtual void getLastNetTransform ( sgMat4 xform ) ;
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void recalcBSphere () ;
} ;
class ssgAnimTransform : public ssgTransform
{
float curr_bank ;
int mode ; /* SSGTWEEN_STOP_AT_END or SSGTWEEN_REPEAT */
class ssgTransformArray transformations;
protected:
virtual void copy_from ( ssgAnimTransform *src, int clone_flags ) ;
public:
void setNum ( unsigned int n ) { transformations.setNum( n ); }
void setATransform ( sgMat4 thing, unsigned int n ) { transformations.raw_set ( (char *) thing, n ) ; } ;
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgAnimTransform (void) ;
virtual ~ssgAnimTransform (void) ;
void setMode ( int _mode ) { mode = _mode ; }
int getMode () { return mode ; }
void selectBank ( float f ) { curr_bank = f ; }
float getCurrBank () { return curr_bank ; }
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual const char *getTypeName(void) ;
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2 ) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgAxisTransform : public ssgTransform
{
sgVec3 rotation_axis ;
sgVec3 rotation_center ;
float limit_low ;
float limit_high ;
protected:
virtual void copy_from ( ssgAxisTransform *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgAxisTransform (void) ;
ssgAxisTransform ( sgVec3 axis, sgVec3 center ) ;
virtual ~ssgAxisTransform (void) ;
virtual void setAxis ( sgVec3 axis ) ;
virtual float *getAxis () ;
virtual void setCenter ( sgVec3 center ) ;
virtual float *getCenter () ;
virtual void setRotation ( float rot ) ;
virtual void setRotationLimits ( float low, float high ) ;
virtual void setLinearRotation ( float rot ) ;
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
};
class ssgTexTrans : public ssgBaseTransform
{
protected:
virtual void copy_from ( ssgTexTrans *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgTexTrans (void) ;
ssgTexTrans ( sgCoord *c ) ;
virtual ~ssgTexTrans (void) ;
virtual void setTransform ( sgVec3 xyz ) ;
virtual void setTransform ( sgCoord *xform ) ;
virtual void setTransform ( sgCoord *xform, float sx, float sy, float sz ) ;
virtual void setTransform ( sgMat4 xform ) ;
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
} ;
class ssgCutout : public ssgBranch
{
int point_rotate ;
protected:
virtual void copy_from ( ssgCutout *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgCutout (int pntrot=FALSE) ;
virtual ~ssgCutout (void) ;
int isPointRotate (void) { return point_rotate ; }
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
virtual void cull ( sgFrustum *f, sgMat4 m, int test_needed ) ;
virtual void isect ( sgSphere *s, sgMat4 m, int test_needed ) ;
virtual void hot ( sgVec3 s, sgMat4 m, int test_needed ) ;
virtual void los ( sgVec3 s, sgMat4 m, int test_needed ) ;
} ;
class ssgRoot : public ssgBranch
{
protected:
virtual void copy_from ( ssgRoot *src, int clone_flags ) ;
public:
virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgRoot (void) ;
virtual ~ssgRoot (void) ;
virtual const char *getTypeName(void) ;
virtual int load ( FILE *fd ) ;
virtual int save ( FILE *fd ) ;
} ;
class ssgLight
{
int id ;
int is_headlight ;
int is_turned_on ;
sgVec4 ambient ;
sgVec4 diffuse ;
sgVec4 specular ;
sgVec4 position ;
sgVec3 direction ;
float exponent ;
float cutoff ;
sgVec3 atten ;
public:
ssgLight ()
{
id = 0 ;
is_turned_on = FALSE ;
is_headlight = FALSE ;
sgSetVec4 ( position, 0.0f, 0.0f, 1.0f, 0.0f ) ;
sgSetVec4 ( ambient , 0.2f, 0.2f, 0.2f, 1.0f ) ;
sgSetVec4 ( diffuse , 1.0f, 1.0f, 1.0f, 1.0f ) ;
sgSetVec4 ( specular, 1.0f, 1.0f, 1.0f, 1.0f ) ;
sgSetVec3 ( direction, 0.0f, 0.0f, -1.0f ) ;
exponent = 1.0f;
cutoff = 90.0f;
sgSetVec3 ( atten, 1.0f, 0.0f, 0.0f ) ;
}
void setID ( int i ) { id = i ; }
int isOn () { return is_turned_on ; }
void on () { is_turned_on = TRUE ; }
void off () { is_turned_on = FALSE ; }
void setPosition ( const sgVec3 pos ) { sgCopyVec3 ( position, pos ) ; }
void getPosition ( sgVec3 pos ) { sgCopyVec3 ( pos, position ) ; }
void setPosition ( float x, float y, float z ) { sgSetVec3 ( position, x, y, z ) ; }
void setColour ( GLenum which, const sgVec4 col )
{
switch ( which )
{
case GL_AMBIENT : sgCopyVec4 ( ambient , col ) ; break ;
case GL_DIFFUSE : sgCopyVec4 ( diffuse , col ) ; break ;
case GL_SPECULAR : sgCopyVec4 ( specular, col ) ; break ;
default : break ;
}
}
void getColour ( GLenum which, sgVec4 col )
{
switch ( which )
{
case GL_AMBIENT : sgCopyVec4 ( col , ambient ) ; break ;
case GL_DIFFUSE : sgCopyVec4 ( col , diffuse ) ; break ;
case GL_SPECULAR : sgCopyVec4 ( col, specular ) ; break ;
default : break ;
}
}
void setColour ( GLenum which, float r, float g, float b )
{
sgVec4 colour = { r, g, b, 1.0f };
setColour(which, colour);
}
void setHeadlight ( int head ) { is_headlight = head ; }
int isHeadlight () { return is_headlight ; }
void setSpotlight ( int spot ) { position[3] = ( spot ? 1.0f : 0.0f ) ; }
int isSpotlight () { return position[3] != 0.0f; }
void setSpotDirection ( const sgVec3 dir ) { sgCopyVec3 ( direction, dir ) ; }
void getSpotDirection ( sgVec3 dir ) { sgCopyVec3 ( dir, direction ) ; }
void setSpotDirection ( float x, float y, float z ) { sgSetVec3 ( direction, x, y, z ) ; }
void setSpotDiffusion ( float exp, float cut = 90.0f )
{
exponent = exp;
cutoff = cut;
}
void getSpotDiffusion ( float *exp, float *cut = 0 )
{
if (exp != 0) *exp = exponent;
if (cut != 0) *cut = cutoff;
}
void setSpotAttenuation ( float constant, float linear, float quadratic )
{
sgSetVec3( atten, constant, linear, quadratic );
}
void getSpotAttenuation ( float *constant, float *linear, float *quadratic )
{
if (constant != 0) *constant = atten[0];
if (linear != 0) *linear = atten[1];
if (quadratic != 0) *quadratic = atten[2];
}
void setup ()
{
if ( is_turned_on )
{
glEnable ( (GLenum)(GL_LIGHT0+id) ) ;
glLightfv ( (GLenum)(GL_LIGHT0+id), GL_AMBIENT , ambient ) ;
glLightfv ( (GLenum)(GL_LIGHT0+id), GL_DIFFUSE , diffuse ) ;
glLightfv ( (GLenum)(GL_LIGHT0+id), GL_SPECULAR, specular ) ;
glLightfv ( (GLenum)(GL_LIGHT0+id), GL_POSITION, position ) ;
if ( isSpotlight() ) {
glLightfv ( (GLenum)(GL_LIGHT0+id), GL_SPOT_DIRECTION, direction ) ;
glLightf ( (GLenum)(GL_LIGHT0+id), GL_SPOT_EXPONENT, exponent ) ;
glLightf ( (GLenum)(GL_LIGHT0+id), GL_SPOT_CUTOFF, cutoff ) ;
glLightf ( (GLenum)(GL_LIGHT0+id), GL_CONSTANT_ATTENUATION, atten[0] );
glLightf ( (GLenum)(GL_LIGHT0+id), GL_LINEAR_ATTENUATION, atten[1] );
glLightf ( (GLenum)(GL_LIGHT0+id), GL_QUADRATIC_ATTENUATION, atten[2] );
}
}
else
glDisable ( (GLenum)(GL_LIGHT0+id) ) ;
}
} ;
class ssgHit
{
_SSG_PUBLIC:
int num_entries ;
ssgEntity *path [ SSG_MAXPATH ] ;
public:
ssgLeaf *leaf ;
int triangle ;
sgVec4 plane ;
sgMat4 matrix ;
ssgHit ()
{
leaf = NULL ;
init () ;
} ;
void init () { num_entries = 0 ; }
void addPath ( ssgEntity *e )
{
if ( num_entries < SSG_MAXPATH )
path [ num_entries++ ] = e ;
}
int getNumPathEntries () { return num_entries ; }
ssgEntity *getPathEntry ( int i )
{
return ( i >= 0 && i < num_entries ) ? path[i] : (ssgEntity *) NULL ;
}
} ;
class ssgContext
{
protected:
int enabledClipPlanes ;
sgVec4 clipPlane [ 6 ] ;
ssgSimpleState *currentState ;
ssgSimpleState *basicState ;
sgFrustum *frustum ;
sgMat4 cameraMatrix ;
int cullFace ;
int ovTexture ;
int ovCullface ;
ssgState *ovState ;
public:
ssgContext () ;
~ssgContext () ;
void forceBasicState () ;
void applyClipPlanes () ;
void removeClipPlanes () ;
void makeCurrent () ;
int isCurrent () ;
void clrClipPlane ( int i )
{
if ( i >= 0 && i < 6 )
enabledClipPlanes &= ~(1<<i) ;
}
void setClipPlane ( int i, sgVec4 plane )
{
if ( i >= 0 && i < 6 )
{
sgCopyVec4 ( clipPlane [ i ], plane ) ;
enabledClipPlanes |= (1<<i) ;
}
}
int isSetClipPlane ( int i ) { return enabledClipPlanes & (1<<i) ; }
float *getClipPlane ( int i )
{
return ((i<0)||(i>=6)) ? NULL : clipPlane [i] ;
}
void overrideState ( ssgState *s ) ;
void overrideTexture ( int on_off ) ;
void overrideCullface ( int on_off ) ;
void setCullface ( int on_off )
{
if ( cullFace == on_off || ovCullface )
return ;
cullFace = on_off ;
if ( cullFace ) glEnable ( GL_CULL_FACE ) ;
else glDisable ( GL_CULL_FACE ) ;
}
ssgState *overriddenState () { return ovState ; }
int stateOverridden () { return ovState != NULL ; }
int textureOverridden () { return ovTexture ; }
int cullfaceOverridden () { return ovCullface ; }
int cullfaceIsEnabled () { return cullFace ; }
sgFrustum *getFrustum () { return frustum ; }
// make a perspective projection
void setFrustum ( float l, float r, float b, float t, float n, float f ) ;
// make an orthographic projection
void setOrtho ( float l, float r, float b, float t, float n, float f ) ;
void getNearFar ( float *n, float *f ) ;
void getFOV ( float *w, float *h ) ;
void getOrtho ( float *w, float *h ) ;
void setNearFar ( float n, float f ) ;
void setOrtho ( float w, float h ) ; // make orthographic
void setFOV ( float w, float h ) ; // make perspective
int isOrtho () { return frustum -> isOrtho () ; } // is orthographic
ssgSimpleState *getState () { return currentState ; }
void cull ( ssgBranch *r ) ;
void getCameraPosition ( sgVec3 pos ) ;
void setCamera ( sgMat4 mat ) ;
void setCamera ( const sgCoord *coord ) ;
void setCameraLookAt ( const sgVec3 eye, const sgVec3 center, const sgVec3 up ) ;
void setCameraLookAt ( const sgVec3 eye, const sgVec3 center ) ;
void loadProjectionMatrix () ;
void loadModelviewMatrix () ;
void getProjectionMatrix ( sgMat4 dst ) ;
void getModelviewMatrix ( sgMat4 dst ) ;
void pushProjectionMatrix () ;
void pushProjectionMatrix ( sgFrustum *f ) ;
void loadModelviewMatrix ( sgMat4 mat ) ;
} ;
/* Compatibility inlines for pre-ssgContext applications */
extern ssgContext *_ssgCurrentContext ;
inline ssgContext *ssgGetCurrentContext () { return _ssgCurrentContext ; }
inline void ssgGetCameraPosition ( sgVec3 pos )
{
_ssgCurrentContext -> getCameraPosition ( pos ) ;
}
inline void ssgOverrideState ( ssgState *s )
{
_ssgCurrentContext->overrideState ( s ) ;
}
inline void ssgOverrideTexture ( int on_off )
{
_ssgCurrentContext->overrideTexture ( on_off ) ;
}
inline void ssgOverrideCullface ( int on_off )
{
_ssgCurrentContext->overrideCullface ( on_off ) ;
}
inline void ssgGetNearFar ( float *n, float *f )
{
_ssgCurrentContext->getNearFar ( n, f ) ;
}
inline void ssgGetFOV ( float *w, float *h )
{
_ssgCurrentContext->getFOV ( w, h ) ;
}
inline void ssgGetOrtho ( float *w, float *h )
{
_ssgCurrentContext->getOrtho ( w, h ) ;
}
inline void ssgSetFrustum ( float l, float r, float b, float t, float n, float f )
{
_ssgCurrentContext->setFrustum ( l, r, b, t, n, f ) ;
}
inline void ssgSetOrtho ( float l, float r, float b, float t, float n, float f )
{
_ssgCurrentContext->setOrtho ( l, r, b, t, n, f ) ;
}
inline void ssgSetFOV ( float w, float h )
{
_ssgCurrentContext->setFOV ( w, h ) ;
}
inline void ssgSetOrtho ( float w, float h )
{
_ssgCurrentContext->setOrtho ( w, h ) ;
}
inline void ssgSetNearFar ( float n, float f )
{
_ssgCurrentContext->setNearFar ( n, f ) ;
}
inline void ssgSetCamera ( sgMat4 mat )
{
_ssgCurrentContext-> setCamera ( mat ) ;
}
inline void ssgSetCamera ( sgCoord *coord )
{
_ssgCurrentContext-> setCamera ( coord ) ;
}
inline void ssgSetCameraLookAt ( const sgVec3 eye, const sgVec3 center, const sgVec3 up )
{
_ssgCurrentContext-> setCameraLookAt ( eye, center, up ) ;
}
inline void ssgSetCameraLookAt ( const sgVec3 eye, const sgVec3 center )
{
_ssgCurrentContext-> setCameraLookAt ( eye, center ) ;
}
inline void ssgLoadProjectionMatrix ()
{
_ssgCurrentContext->loadProjectionMatrix () ;
}
inline void ssgLoadProjectionMatrix ( sgFrustum *f )
{
glLoadIdentity () ;
_ssgCurrentContext->pushProjectionMatrix ( f ) ;
}
inline void ssgGetProjectionMatrix ( sgMat4 dst )
{
_ssgCurrentContext->getProjectionMatrix ( dst ) ;
}
inline void ssgGetModelviewMatrix ( sgMat4 dst )
{
_ssgCurrentContext->getModelviewMatrix ( dst ) ;
}
inline void ssgLoadModelviewMatrix ()
{
_ssgCurrentContext->loadModelviewMatrix () ;
}
inline void ssgLoadModelviewMatrix ( sgMat4 mat )
{
_ssgCurrentContext->loadModelviewMatrix ( mat ) ;
}
inline void ssgForceBasicState ()
{
_ssgCurrentContext -> forceBasicState () ;
}
inline sgFrustum *ssgGetFrustum ()
{
return _ssgCurrentContext -> getFrustum() ;
}
void ssgInit () ;
void ssgCullAndDraw ( ssgBranch *root ) ;
void ssgCullAndPick ( ssgBranch *root, sgVec2 botleft, sgVec2 topright ) ;
int ssgIsect ( ssgBranch *root, sgSphere*s,sgMat4 m, ssgHit **results ) ;
int ssgHOT ( ssgBranch *root, sgVec3 s, sgMat4 m, ssgHit **results ) ;
int ssgLOS ( ssgBranch *root, sgVec3 s, sgMat4 m, ssgHit **results ) ;
/* Load/Save functions */
enum {
SSG_MD2_STAND,
SSG_MD2_RUN,
SSG_MD2_ATTACK,
SSG_MD2_PAIN_1,
SSG_MD2_PAIN_2,
SSG_MD2_PAIN_3,
SSG_MD2_JUMP,
SSG_MD2_FLIPOFF,
SSG_MD2_SALUTE,
SSG_MD2_TAUNT,
SSG_MD2_WAVE,
SSG_MD2_POINT,
SSG_MD2_CROUCH_STAND,
SSG_MD2_CROUCH_WALK,
SSG_MD2_CROUCH_PAIN,
SSG_MD2_CROUCH_DEATH,
SSG_MD2_DEATH_1,
SSG_MD2_DEATH_2,
SSG_MD2_DEATH_3,
SSG_MD2_ALL,
SSG_MD2_POSE
};
class ssgLoaderOptions
{
//NOTES: we could add more later
//...model scale factor...
//...create normals or read them from the file?...
//...cutoff angle for smooth shading where there isn`t one in the file format...
//...which direction is front-facing in formats that don`t get it right...
//...etc...
protected:
/* for backward compatibility */
ssgState *(*create_state_cb)( char *) ;
ssgBranch *(*create_branch_cb)(char *) ;
char* model_dir ;
char* texture_dir ;
char* make_path ( char* path, const char* dir, const char* fname ) const ;
public:
ssgSimpleStateArray shared_states ;
ssgTextureArray shared_textures ;
ssgLoaderOptions ()
{
model_dir = 0 ;
texture_dir = 0 ;
/* for backward compatibility */
create_state_cb = 0 ;
create_branch_cb = 0 ;
}
virtual ~ssgLoaderOptions()
{
if (model_dir)
{
delete [] model_dir;
model_dir = 0;
}
if (texture_dir)
{
delete [] texture_dir;
texture_dir = 0;
}
}
const char* getModelDir ( void ) const { return model_dir ; }
const char* getTextureDir ( void ) const { return texture_dir ; }
void setModelDir ( const char *s ) ;
void setTextureDir ( const char *s ) ;
//
// the idea is that you derive a class from ssgLoaderOptions and
// override these methods to customize how the loaders work
//
virtual void makeModelPath ( char* path, const char *fname ) const ;
virtual void makeTexturePath ( char* path, const char *fname ) const ;
virtual ssgLeaf* createLeaf ( ssgLeaf* leaf, const char* parent_name ) ;
virtual ssgTexture* createTexture ( char* tfname,
int wrapu = TRUE, int wrapv = TRUE,
int mipmap = TRUE ) ;
virtual ssgTransform* createTransform ( ssgTransform* tr,
ssgTransformArray* ta ) const ;
virtual ssgSelector* createSelector ( ssgSelector* s ) const ;
virtual ssgBranch* createBranch ( char* text ) const
{
if ( create_branch_cb != NULL )
return (*create_branch_cb)(text) ;
return NULL ;
}
virtual ssgState* createState ( char* tfname ) const
{
if ( create_state_cb != NULL )
return (*create_state_cb)(tfname) ;
return NULL ;
}
virtual ssgSimpleState* createSimpleState ( char* tfname ) const
{
ssgState *st = createState ( tfname ) ;
if ( st != NULL )
{
if ( st -> isAKindOf ( ssgTypeSimpleState() ) )
{
return (ssgSimpleState*) st ;
}
else
{
ulSetError(UL_WARNING, "createState() did not return simple state");
}
}
return NULL ;
}
virtual void endLoad ()
{
/* default behavior is to reset sharing after loading a model */
shared_textures.removeAll () ;
shared_states.removeAll () ;
}
//
// *** DEPRECATED INTERFACE ***
// for backward compatibility
// derive and use virtual methods to override
//
void setCreateBranchCallback ( ssgBranch *(*cb)(char *) )
{
create_branch_cb = cb ;
}
void setCreateStateCallback ( ssgState *(*cb)(char *) )
{
create_state_cb = cb ;
}
} ;
int ssgSave ( const char *fname, ssgEntity *ent ) ;
int ssgSaveAC ( const char *fname, ssgEntity *ent ) ;
int ssgSaveASE ( const char *fname, ssgEntity *ent ) ;
int ssgSaveSSG ( const char *fname, ssgEntity *ent ) ;
int ssgSaveDXF ( const char *fname, ssgEntity *ent ) ;
int ssgSaveTRI ( const char *fname, ssgEntity *ent ) ;
int ssgSaveOBJ ( const char *fname, ssgEntity *ent ) ;
int ssgSaveX ( const char *fname, ssgEntity *ent ) ;
int ssgSaveM ( const char *fname, ssgEntity *ent ) ;
int ssgSave3ds ( const char *fname, ssgEntity *ent ) ;
int ssgSaveFLT ( const char *fname, ssgEntity *ent ) ;
int ssgSaveOFF ( const char *fname, ssgEntity *ent ) ;
int ssgSaveQHI ( const char *fname, ssgEntity *ent ) ;
int ssgSaveATG ( const char *fname, ssgEntity *ent ) ;
int ssgSaveVRML1( const char *fname, ssgEntity *ent ) ;
int ssgSaveASC ( const char *fname, ssgEntity *ent ) ;
int ssgSaveIV ( const char *fname, ssgEntity *ent ) ;
int ssgSavePOV ( const char *fname, ssgEntity *ent ) ;
ssgEntity *ssgLoad ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoad3ds ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadAC3D ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadASC ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadSSG ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadASE ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadDOF ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadDXF ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadTRI ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadOBJ ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadMD2 ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadMDL ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadX ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadFLT ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadM ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadStrip( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadOFF ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadATG ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
ssgEntity *ssgLoadVRML1( const char *fname, const ssgLoaderOptions* options = NULL ) ;
ssgEntity *ssgLoadIV ( const char *fname, const ssgLoaderOptions* options = NULL ) ;
ssgEntity *ssgLoadXPlaneOBJ ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
typedef ssgEntity *ssgLoadFunc ( const char *, const ssgLoaderOptions * ) ;
typedef int ssgSaveFunc ( const char *, ssgEntity * ) ;
void ssgAddModelFormat ( const char* extension,
ssgLoadFunc *loadfunc , ssgSaveFunc *savefunc ) ;
/* current loader options */
extern ssgLoaderOptions* _ssgCurrentOptions ;
inline ssgLoaderOptions* ssgGetCurrentOptions ()
{
return _ssgCurrentOptions ;
}
inline void ssgSetCurrentOptions ( ssgLoaderOptions* options )
{
if ( options != NULL )
_ssgCurrentOptions = options ;
}
/* For backwards compatibility */
inline ssgEntity *ssgLoad ( char *fname, ssgBranch *(*cb)(char *))
{
_ssgCurrentOptions -> setCreateBranchCallback ( cb ) ;
return ssgLoad ( fname ) ;
}
inline void ssgSetAppStateCallback ( ssgState *(*cb)(char *) )
{
_ssgCurrentOptions -> setCreateStateCallback ( cb ) ;
}
inline void ssgModelPath ( const char *path )
{
_ssgCurrentOptions -> setModelDir ( path ) ;
}
inline void ssgTexturePath ( const char *path )
{
_ssgCurrentOptions -> setTextureDir ( path ) ;
}
ssgEntity *ssgLoadAC ( const char *fname, const ssgLoaderOptions *options = NULL ) ;
void ssgGetValuesFromLastATGFile(double *x, double *y, double *z, double *r);
bool ssgConvertTexture( char * fname_output, char * fname_input ) ;
class ssgStatistics
{
int vertex_count ;
int leaf_count ;
public:
void reset () ;
void bumpVertexCount ( int i ) { vertex_count += i ; }
void bumpLeafCount ( int i ) { leaf_count += i ; }
int getVertexCount () { return vertex_count ; }
int getLeafCount () { return leaf_count ; }
ssgStatistics ()
{
reset () ;
}
} ;
ssgStatistics *ssgGetLatestStatistics () ;
/* scene walkers */
void ssgFlatten ( ssgEntity *ent ) ;
void ssgStripify ( ssgEntity *ent ) ;
void ssgArrayTool ( ssgEntity *ent, float* vtol = 0, bool make_normals = false ) ;
void ssgTransTool ( ssgEntity *ent, const sgMat4 trans ) ;
ssgLight *ssgGetLight ( int i ) ;
char *ssgShowStats () ;
void ssgDelete ( ssgBranch *br ) ;
const char *ssgGetVersion () ;
void ssgSetLoadOFFTranslucent ( int i );
void ssgRegisterType ( int type, ssgBase * ( *create_func ) () ) ;
ssgBase *ssgCreateOfType ( int type ) ;
#define SSG_BACKFACE_COLLISIONS_SUPPORTED 1
void ssgSetBackFaceCollisions ( bool b ) ;
#endif
|