bead.C 81.1 KB
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
/******************************************************************************\
  Copyright 1995 The University of North Carolina at Chapel Hill.
  All Rights Reserved.

  Permission to use, copy, modify and distribute this software and its
  documentation for educational, research and non-profit purposes, without
  fee, and without a written agreement is hereby granted, provided that the
  above copyright notice and the following three paragraphs appear in all
  copies.

  IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA
  AT CHAPEL HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, 
  INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
  OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE
  UNIVERSITY OF NORTH CAROLINA HAS BEEN ADVISED OF THE POSSIBILITY OF
  SUCH DAMAGES.

  THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY WARRANTIES, 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HERUNDER IS
  ON AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATIONS
  TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

  The author may be contacted via:

  US Mail:             Mike Goslin
                       Department of Computer Science
                       Sitterson Hall, CB #3175
                       University of N. Carolina
                       Chapel Hill, NC 27599-3175

  Phone:               (919)962-1719

  EMail:               goslin@cs.unc.edu

*******************************************************************************/
/*******************************************************************************
*
* FILENAME:     bead.C 
* CLASS:        Bead 
* DESCRIPTION:  
* AUTHOR:       Mike Goslin
* CREATED:      2/7/95
* REVISIONS:
*
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <time.h>
#include <math.h>

#include "bead.H"

/*******************************************************************************
*     Function: printComment
*  Description: prints out an mgComment structure 
*        Input:  
*       Output:
*******************************************************************************/
void printComment(const mgComment& comment)
{
    printf("\n");
    printf("==============================================================\n");
    printf(" COMMENT\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", comment.length);
    printf("%s\n", comment.text);
}

/*******************************************************************************
*     Function: Constructor
*        Class: HeaderBead
*       Access: Public
*  Description: Default constructor - initializes to reasonable values
*        Input:  
*       Output:
*******************************************************************************/
HeaderBead::HeaderBead(void)
{
    time_t	the_time;

    type = MG_HEADER;
    strcpy(name, "HEADER");

    fltHeader.opcode = MG_HEADER;
    fltHeader.length = FLT14_HEADER_RECORD_LENGTH;
    fltHeader.frev = 14;
    fltHeader.dbrev = 1;
    the_time = time(NULL);
    strcpy(fltHeader.revDate, ctime(&the_time)); // we want these to always be
					      // identical for binary file diffs
    fltHeader.nextGroupId = 0;
    fltHeader.nextLodId = 0;
    fltHeader.nextObjId = 0;
    fltHeader.nextPolyId = 0;
    fltHeader.unitMulDiv = 1;
    fltHeader.unitType = 0;   // defaults to METERS
    fltHeader.texWhite = 0; // defaults to FALSE on new textured polygons base
    fltHeader.flags = 1;      // save vertex normals = first bit
    // SWLat, SWLong, NELat, NELong, latOrig, longOrig no longer used in 14.1
    fltHeader.projType = 0; // defaults to "flat earth"
    // oswIfmt[2], otorTrans[2], upperLat, lowerLat, nlHash not used in 14.1
    fltHeader.nextDofId = 0;
    fltHeader.vtxFormat = 1;  // defaults to double precision float
    fltHeader.dblOrig = 100;  // OpenFlight
    fltHeader.swIfmt[0] = 0;
    fltHeader.swIfmt[1] = 0;
    fltHeader.terTrans[0] = 0;
    fltHeader.terTrans[1] = 0;
    fltHeader.soundId = 0;
    fltHeader.pathId = 0;
    fltHeader.clipId = 0;
    fltHeader.textId = 0;
    fltHeader.switchId = 0;
    // Initialize these to reasonable values - update them as the database is
    // read in
    fltHeader.SWLat1 = 0;
    fltHeader.SWLong1 = 0;
    fltHeader.NELat1 = 0;
    fltHeader.NELong1 = 0;
    fltHeader.latOrig1 = 0;
    fltHeader.longOrig1 = 0;
    fltHeader.upperLat1 = 0;
    fltHeader.lowerLat1 = 0;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: HeaderBead
*       Access: Public
*  Description:
*        Input: A valid flight header structure
*       Output:
*******************************************************************************/
HeaderBead::HeaderBead(const mgHeader& _fltHeader)
{
    type = MG_HEADER;
    strcpy(name, DEFAULT_NAME);

    if (_fltHeader.frev < 14)
    {
	fprintf(stderr, "WARNING: Old flight version <%d>.  Converting header to version 14.\n", _fltHeader.frev);
	memcpy(&fltHeader, &_fltHeader, FLT13_HEADER_RECORD_LENGTH);
	fltHeader.frev = 14;
	fltHeader.soundId = 0;
	fltHeader.pathId = 0;
	fltHeader.clipId = 0;
	fltHeader.textId = 0;
	fltHeader.switchId = 0;
	fltHeader.SWLat1 = (double)_fltHeader.SWLat;
	fltHeader.SWLong1 = (double)_fltHeader.SWLong;
	fltHeader.NELat1 = (double)_fltHeader.NELat;
	fltHeader.NELong1 = (double)_fltHeader.NELong;
	fltHeader.latOrig1 = (double)_fltHeader.latOrig;
	fltHeader.longOrig1 = (double)_fltHeader.longOrig;
	fltHeader.upperLat1 = (double)_fltHeader.upperLat;
	fltHeader.lowerLat1 = (double)_fltHeader.lowerLat;
	fltHeader.length = FLT14_HEADER_RECORD_LENGTH;
    }
    else	
    	fltHeader = _fltHeader;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Destructor
*        Class: HeaderBead
*       Access: Public
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
HeaderBead::~HeaderBead()
{
}

/*******************************************************************************
*     Function: printHeader
*  Description:
*        Input:
*       Output:
*******************************************************************************/
void printHeader(const mgHeader& fltHeader)
{
    char projtype[20];

    printf("\n");
    printf("==============================================================\n");
    printf(" HEADER RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", fltHeader.length);
    printf("Format Revision:\t\t\t%d\n", fltHeader.frev);
    printf("Revision level:\t\t\t\t%d\n", fltHeader.dbrev);
    printf("Last revision:\t\t\t\t%s\n", fltHeader.revDate);
    printf("Next group:\t\t\t\t%d\n", fltHeader.nextGroupId);
    printf("Next lod:\t\t\t\t%d\n", fltHeader.nextLodId);
    printf("Next object:\t\t\t\t%d\n", fltHeader.nextObjId);
    printf("Next polygon:\t\t\t\t%d\n", fltHeader.nextPolyId);
    printf("Unit multiplier:\t\t\t%d\n", fltHeader.unitMulDiv);
    printf("Units:\t\t\t\t\t%d\n", fltHeader.unitType);
    if (fltHeader.texWhite == 1)  
	printf("\ttexwhite is TRUE\n");
    printf("Flags:\t\t\t\t\t%d\n", fltHeader.flags);
    if (fltHeader.flags & 1)
       printf("\tSave Vertex Normals\n");
    switch(fltHeader.projType) {
	case 0: strcpy(projtype, "Flat Earth"); break; 
	case 1: strcpy(projtype, "Trapezoidal"); break; 
	case 2: strcpy(projtype, "Round Earth"); break; 
	case 3: strcpy(projtype, "Lambert"); break; 
	case 4: strcpy(projtype, "UTM"); break; 
	case 5: strcpy(projtype, "Geodetic"); break; 
	case 6: strcpy(projtype, "Geocentric"); break; 
	default: strcpy(projtype, "Unknown"); break; }
    printf("Projection type:\t\t\t%s\n", projtype);
    printf("Next dof:\t\t\t\t%d\n", fltHeader.nextDofId); 
    if (fltHeader.vtxFormat == 1) 
    	printf("Flag:\tDbl precision float vertex:\tTRUE\n");
    printf("Database origin:\t\t\t%d\n", fltHeader.dblOrig);
    printf("Southwest database coordinate x:\t%.4f\n", fltHeader.swIfmt[0]);
    printf("Southwest database coordinate y:\t%.4f\n", fltHeader.swIfmt[1]);
    printf("Delta x to place database:\t\t%.4f\n", fltHeader.terTrans[0]);
    printf("Delta y to place database:\t\t%.4f\n", fltHeader.terTrans[1]);
    printf("Next sound bead id:\t\t\t%d\n", fltHeader.soundId);
    printf("Next path bead id:\t\t\t%d\n", fltHeader.pathId);
    printf("Next clipping region id:\t\t%d\n", fltHeader.clipId);
    printf("Next text bead id:\t\t\t%d\n", fltHeader.textId);
    printf("Next switch bead id:\t\t\t%d\n", fltHeader.switchId);
    printf("Southwest database corner latitude :\t%.4f\n", fltHeader.SWLat1);
    printf("Southwest database corner longitude:\t%.4f\n", fltHeader.SWLong1);
    printf("Northeast database corner latitude :\t%.4f\n", fltHeader.NELat1);
    printf("Northeast database corner longitude:\t%.4f\n", fltHeader.NELong1);
    printf("Database origin latitude:\t\t%.4f\n", fltHeader.latOrig1);
    printf("Database orign longitude:\t\t%.4f\n", fltHeader.longOrig1);
    printf("Lambert upper latitude:\t\t\t%.4f\n", fltHeader.upperLat1);
    printf("Lambert lower latitude:\t\t\t%.4f\n", fltHeader.lowerLat1);
}

/*******************************************************************************
*     Function: print
*        Class: HeaderBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
void HeaderBead::print(void) const
{
    printHeader(fltHeader);
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexRecordBead
*       Access: Public
*  Description: Default constructor 
*        Input:
*       Output:
*******************************************************************************/
VertexRecordBead::VertexRecordBead(void)
{
    fltVert = NULL;
    offset = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexRecordBead
*       Access: Public
*  Description: Default constructor - initializes a vertex with an
*		mgVertSharedAbs structure and type
*        Input: double coord[3] = x, y, z
*       Output:
*******************************************************************************/
VertexRecordBead::VertexRecordBead(double coord[3])
{
    type = MG_DVERT_ABS;
    strcpy(name, DEFAULT_NAME);

    fltVert = (mgVertSharedAbs *)malloc(sizeof(mgVertSharedAbs));
    ((mgVertSharedAbs *)fltVert)->opcode = MG_DVERT_ABS;
    ((mgVertSharedAbs *)fltVert)->length = FLT_VERT_SHARED_ABS_LENGTH;
    ((mgVertSharedAbs *)fltVert)->vcolor = -1; // Defaults to unshaded
    ((mgVertSharedAbs *)fltVert)->flags = 0; // Hard edge flag
    type = MG_DVERT_ABS;
    VEC3COPY(((mgVertSharedAbs *)fltVert)->p, coord);
    offset = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexRecordBead
*       Access: Public
*  Description: Default constructor - initializes a vertex with an
*		mgVertSharedNorm structure and type
*        Input: double coord[3] = x, y, z, float norm[3] = x, y, z
*       Output:
*******************************************************************************/
VertexRecordBead::VertexRecordBead(double coord[3], float norm[3])
{
    type = MG_DVERT_NORM;
    strcpy(name, DEFAULT_NAME);

    fltVert = (mgVertSharedNorm *)malloc(sizeof(mgVertSharedNorm));
    ((mgVertSharedNorm *)fltVert)->opcode = MG_DVERT_NORM;
    ((mgVertSharedNorm *)fltVert)->length = FLT_VERT_SHARED_NORM_LENGTH;
    ((mgVertSharedNorm *)fltVert)->vcolor = 4102;
    ((mgVertSharedNorm *)fltVert)->flags = 0; // Hard edge flag
    type = MG_DVERT_NORM;
    VEC3COPY(((mgVertSharedNorm *)fltVert)->p, coord);
    VEC3COPY(((mgVertSharedNorm *)fltVert)->n, norm);
    offset = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexRecordBead
*       Access: Public
*  Description: Default constructor - initializes a vertex with an
*		mgVertSharedNorm structure and type
*        Input: double coord[3] = x, y, z, float norm[3] = x, y, z
*       Output:
*******************************************************************************/
VertexRecordBead::VertexRecordBead(double coord[3], float u, float v)
{
    type = MG_DVERT_ABS_TEX;
    strcpy(name, DEFAULT_NAME);

    fltVert = (mgVertSharedAbsTex *)malloc(sizeof(mgVertSharedAbsTex));
    ((mgVertSharedAbsTex *)fltVert)->opcode = MG_DVERT_ABS_TEX;
    ((mgVertSharedAbsTex *)fltVert)->length = FLT_VERT_SHARED_ABS_TEX_LENGTH;
    ((mgVertSharedAbsTex *)fltVert)->vcolor = -1; // Defaults to unshaded
    ((mgVertSharedAbsTex *)fltVert)->flags = 0; // Hard edge flag
    type = MG_DVERT_ABS_TEX;
    VEC3COPY(((mgVertSharedNormTex *)fltVert)->p, coord);
    ((mgVertSharedNormTex *)fltVert)->t[0] = u;
    ((mgVertSharedNormTex *)fltVert)->t[1] = v;
    offset = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexRecordBead
*       Access: Public
*  Description: Default constructor - initializes a vertex with an
*		mgVertSharedNorm structure and type
*        Input: double coord[3] = x, y, z, float norm[3] = x, y, z
*       Output:
*******************************************************************************/
VertexRecordBead::VertexRecordBead(double coord[3], float norm[3], float tex[2])
{
    type = MG_DVERT_NORM_TEX;
    strcpy(name, DEFAULT_NAME);

    fltVert = (mgVertSharedNormTex *)malloc(sizeof(mgVertSharedNormTex));
    ((mgVertSharedNormTex *)fltVert)->opcode = MG_DVERT_NORM_TEX;
    ((mgVertSharedNormTex *)fltVert)->length = FLT_VERT_SHARED_NORM_TEX_LENGTH;
    ((mgVertSharedNormTex *)fltVert)->vcolor = -1; // Defaults to unshaded
    ((mgVertSharedNormTex *)fltVert)->flags = 0; // Hard edge flag
    type = MG_DVERT_NORM_TEX;
    VEC3COPY(((mgVertSharedNormTex *)fltVert)->p, coord);
    VEC3COPY(((mgVertSharedNormTex *)fltVert)->n, norm);
    VEC2COPY(((mgVertSharedNormTex *)fltVert)->t, tex);
    offset = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexRecordBead
*       Access: Public
*  Description:
*        Input: A valid flight vertex type and structure
*       Output:
*******************************************************************************/
VertexRecordBead::VertexRecordBead(ushort _type, void *_fltVert)
{
    type = _type;
    strcpy(name, DEFAULT_NAME);
    fltVert = _fltVert;
    offset = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Destructor
*        Class: VertexRecordBead
*       Access: Public
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
VertexRecordBead::~VertexRecordBead()
{
    free(fltVert);
}

/*******************************************************************************
*     Function: getPoint 
*        Class: VertexRecordBead
*       Access: Public
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
void VertexRecordBead::getPoint(double point[3]) const
{
    switch (type)
    {
	case MG_DVERT_ABS:
	    VEC3COPY(point, ((mgVertSharedAbs *)fltVert)->p);
	    break;
	case MG_DVERT_NORM:
	    VEC3COPY(point, ((mgVertSharedNorm *)fltVert)->p);
	    break;
	case MG_DVERT_NORM_TEX:
	    VEC3COPY(point, ((mgVertSharedNormTex *)fltVert)->p);
	    break;
	case MG_DVERT_ABS_TEX:
	    VEC3COPY(point, ((mgVertSharedAbsTex *)fltVert)->p);
	    break;
    }
}

/*******************************************************************************
*     Function: getNormal 
*        Class: VertexRecordBead
*       Access: Public
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
uint VertexRecordBead::getNormal(float norm[3]) const
{
    if (type == MG_DVERT_NORM)
    {
	VEC3COPY(norm, ((mgVertSharedNorm *)fltVert)->n);
    }
    else if (type == MG_DVERT_NORM_TEX)
    {
	VEC3COPY(norm, ((mgVertSharedNormTex *)fltVert)->n);
    }
    else return 0;
    return 1;
}

/*******************************************************************************
*     Function: getUV 
*        Class: VertexRecordBead
*       Access: Public
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
uint VertexRecordBead::getUV(float uv[2]) const
{
    if (type == MG_DVERT_ABS_TEX)
    {
	VEC2COPY(uv, ((mgVertSharedAbsTex *)fltVert)->t);
    }
    else if (type == MG_DVERT_NORM_TEX)
    {
	VEC2COPY(uv, ((mgVertSharedNormTex *)fltVert)->t);
    }
    else return 0;
    return 1;
}

/*******************************************************************************
*     Function: printVertexRecord
*  Description:
*        Input:
*       Output:
*******************************************************************************/
void printVertexRecord(ushort type, void *fltVert)
{
    switch (type)
    {
	case MG_DVERT_ABS:
    printf("\n");
    printf("==============================================================\n");
    printf(" SHADED VERTEX RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", ((mgVertSharedAbs *)fltVert)->length);
    printf("x:\t\t\t\t%.3f\n", ((mgVertSharedAbs *)fltVert)->p[0]);
    printf("y:\t\t\t\t%.3f\n", ((mgVertSharedAbs *)fltVert)->p[1]);
    printf("z:\t\t\t\t%.3f\n", ((mgVertSharedAbs *)fltVert)->p[2]);
    printf("Hard Edge Flag:\t\t\t%d\n", ((mgVertSharedAbs *)fltVert)->flags 
								& 0x0001);
    printf("Touch Flag:\t\t\t%d\n", ((mgVertSharedAbs *)fltVert)->flags & 
								0x0002);
    printf("Vertex Color:\t\t\t%d\n", ((mgVertSharedAbs *)fltVert)->vcolor);
	break;
	case MG_DVERT_NORM:
    printf("\n");
    printf("==============================================================\n");
    printf(" SHADED NORMAL VERTEX RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", ((mgVertSharedNorm *)fltVert)->length);
    printf("x:\t\t\t\t%.3f\n", ((mgVertSharedNorm *)fltVert)->p[0]);
    printf("y:\t\t\t\t%.3f\n", ((mgVertSharedNorm *)fltVert)->p[1]);
    printf("z:\t\t\t\t%.3f\n", ((mgVertSharedNorm *)fltVert)->p[2]);
    printf("Hard Edge Flag:\t\t\t%d\n", ((mgVertSharedNorm *)fltVert)->flags 
								& 0x0001);
    printf("Touch Flag:\t\t\t%d\n", ((mgVertSharedNorm *)fltVert)->flags & 
								0x0002);
    printf("Vertex Color:\t\t\t%d\n", ((mgVertSharedNorm *)fltVert)->vcolor);
    printf("Normals:\t\t\t%.3f %.3f %.3f\n", 
				  	((mgVertSharedNorm *)fltVert)->n[0], 
					((mgVertSharedNorm *)fltVert)->n[1],
					((mgVertSharedNorm *)fltVert)->n[2]);
	break;
	case MG_DVERT_NORM_TEX:
    printf("\n");
    printf("==============================================================\n");
    printf(" SHADED TEXTURED NORMAL VERTEX RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", ((mgVertSharedNormTex *)fltVert)->length);
    printf("x:\t\t\t\t%.3f\n", ((mgVertSharedNormTex *)fltVert)->p[0]);
    printf("y:\t\t\t\t%.3f\n", ((mgVertSharedNormTex *)fltVert)->p[1]);
    printf("z:\t\t\t\t%.3f\n", ((mgVertSharedNormTex *)fltVert)->p[2]);
    printf("Hard Edge Flag:\t\t\t%d\n", ((mgVertSharedNormTex *)fltVert)->flags
                                                                & 0x0001);
    printf("Touch Flag:\t\t\t%d\n", ((mgVertSharedNormTex *)fltVert)->flags &
                                                                0x0002);
    printf("Vertex Color:\t\t\t%d\n", ((mgVertSharedNormTex *)fltVert)->vcolor);
    printf("Normals:\t\t\t%.3f %.3f %.3f\n", 
                                        ((mgVertSharedNormTex *)fltVert)->n[0], 
                                        ((mgVertSharedNormTex *)fltVert)->n[1],
                                        ((mgVertSharedNormTex *)fltVert)->n[2]);
    printf("Textures:\t\t\t%.3f %.3f\n",((mgVertSharedNormTex *)fltVert)->t[0],
					((mgVertSharedNormTex *)fltVert)->t[1]);
	break;
	case MG_DVERT_ABS_TEX:
    printf("\n");
    printf("==============================================================\n");
    printf(" SHADED TEXTURED VERTEX RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", ((mgVertSharedAbsTex *)fltVert)->length);
    printf("x:\t\t\t\t%.3f\n", ((mgVertSharedAbsTex *)fltVert)->p[0]);
    printf("y:\t\t\t\t%.3f\n", ((mgVertSharedAbsTex *)fltVert)->p[1]);
    printf("z:\t\t\t\t%.3f\n", ((mgVertSharedAbsTex *)fltVert)->p[2]);
    printf("Hard Edge Flag:\t\t\t%d\n", ((mgVertSharedAbsTex *)fltVert)->flags
                                                                & 0x0001);
    printf("Touch Flag:\t\t\t%d\n", ((mgVertSharedAbsTex *)fltVert)->flags &
                                                                0x0002);
    printf("Vertex Color:\t\t\t%d\n", ((mgVertSharedAbsTex *)fltVert)->vcolor);
    printf("Textures:\t\t\t%.3f %.3f\n",((mgVertSharedAbsTex *)fltVert)->t[0], 
                                        ((mgVertSharedAbsTex *)fltVert)->t[1]);
	break;
    }
}

/*******************************************************************************
*     Function: print 
*        Class: VertexRecordBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
void VertexRecordBead::print(void) const
{
    printVertexRecord(type, fltVert);
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexTableBead
*       Access: Public
*  Description: Default constructor 
*        Input:
*       Output:
*******************************************************************************/
VertexTableBead::VertexTableBead(void)
{
    type = MG_VTXTABLE;
    strcpy(name, "VERTEX_TABLE");

    fltVertTable.opcode = MG_VTXTABLE;
    fltVertTable.length = FLT_VTXTABLE_LENGTH;
    fltVertTable.vtxlen = FLT_VTXTABLE_LENGTH; // No vertices in pool initially
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
    current = NULL;
    vpool = NULL;
    currentOffset = FLT_VTXTABLE_LENGTH;
    fltflag = 0;  
    sharedVertex = 0;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexTableBead
*       Access: Public
*  Description:  
*        Input: A valid flight vertex table record
*       Output:
*******************************************************************************/
VertexTableBead::VertexTableBead(const mgVertTable& _fltVertTable)
{
    type = MG_VTXTABLE;
    strcpy(name, "VERTEX_TABLE");

    fltVertTable = _fltVertTable;
    currentOffset = FLT_VTXTABLE_LENGTH;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
    vpool = NULL;
    current = vpool;
    fltflag = 1;
    sharedVertex = 1;
}

/*******************************************************************************
*     Function: Destructor
*        Class: VertexTableBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
VertexTableBead::~VertexTableBead()
{
    Bead *temp;

    temp = vpool;
    while (temp->right() != NULL)
	temp = temp->right();
    temp = temp->left();
    while (temp->left() != NULL)
    {
	delete temp->right();
	temp = temp->left();
    }
    delete temp;
}

/*******************************************************************************
*     Function: addVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
int VertexTableBead::addVertex(ushort type, void* fltVert)
{
    int offset;

    VertexRecordBead *bead = new VertexRecordBead(type, fltVert); 
    if (vpool == NULL)
    {
	vpool = bead;
        current = bead;
    }
    else
    {
	current->right(bead);
	bead->left(current);
	current = bead;
    }
   switch (type)
   {
    	case MG_DVERT_ABS:
	    offset = FLT_VERT_SHARED_ABS_LENGTH;
    	break;
    	case MG_DVERT_NORM:
	    offset = FLT_VERT_SHARED_NORM_LENGTH;
     	break;	
    	case MG_DVERT_NORM_TEX:
	    offset = FLT_VERT_SHARED_NORM_TEX_LENGTH;
    	break;
    	case MG_DVERT_ABS_TEX:
	    offset = FLT_VERT_SHARED_ABS_TEX_LENGTH;
        break;
    	default:
    	    fprintf(stderr,"addVertex: Unknown vertex type < %d >\n", type);
	    offset = 0;
    	break;
    }
    if (fltflag == 0) // only increment vtxlen if source is not a flt file
    	fltVertTable.vtxlen += offset;

    current->Offset(currentOffset);
    currentOffset += offset;
    return (current->Offset());
}

/*******************************************************************************
*     Function: addVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
int VertexTableBead::addVertex(double coord[3])
{
    VertexRecordBead *nbead;
    double npoint[3];

    VertexRecordBead *bead = new VertexRecordBead(coord); 
    if (vpool == NULL)
    {
	vpool = bead;
        current = vpool;
    }
    else if (!sharedVertex)
    {
	current->right(bead);
	bead->left(current);	
	current = bead;
    } 
    else
    {
	nbead = vpool;
	while (nbead != NULL)
	{
	    nbead->getPoint(npoint);
	    if ((fabs(npoint[0] - coord[0]) < VERT_FUZZ) &&
	    	(fabs(npoint[1] - coord[1]) < VERT_FUZZ) &&
	    	(fabs(npoint[2] - coord[2]) < VERT_FUZZ))
		return (nbead->Offset());
	    nbead = (VertexRecordBead *)nbead->right();
	}
	current->right(bead);
	bead->left(current);
	current = bead;
    }
    fltVertTable.vtxlen += FLT_VERT_SHARED_ABS_LENGTH;
    current->Offset(currentOffset);
    currentOffset += FLT_VERT_SHARED_ABS_LENGTH;
    return (current->Offset());
}

/*******************************************************************************
*     Function: addVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
int VertexTableBead::addVertex(double coord[3], float norm[3])
{
    VertexRecordBead *nbead;
    double npoint[3];

    VertexRecordBead *bead = new VertexRecordBead(coord, norm); 
    if (vpool == NULL)
    {
	vpool = bead;
        current = bead;
    }
    else if (!sharedVertex)
    {
	current->right(bead);
	bead->left(current);	
	current = bead;
    } 
    else
    {
	nbead = vpool;
	while (nbead != NULL)
	{
	    nbead->getPoint(npoint);
	    if ((fabs(npoint[0] - coord[0]) < VERT_FUZZ) &&
	    	(fabs(npoint[1] - coord[1]) < VERT_FUZZ) &&
	    	(fabs(npoint[2] - coord[2]) < VERT_FUZZ))
		return (nbead->Offset());
	    nbead = (VertexRecordBead *)nbead->right();
	}
	current->right(bead);
	bead->left(current);
	current = bead;
    }
    fltVertTable.vtxlen += FLT_VERT_SHARED_NORM_LENGTH;
    current->Offset(currentOffset);
    currentOffset += FLT_VERT_SHARED_NORM_LENGTH;
    return (current->Offset());
}

/*******************************************************************************
*     Function: addVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
int VertexTableBead::addVertex(double coord[3], float u, float v)
{
    VertexRecordBead *nbead;
    double npoint[3];

    VertexRecordBead *bead = new VertexRecordBead(coord, u, v); 
    if (vpool == NULL)
    {
	vpool = bead;
        current = bead;
    }
    else if (!sharedVertex)
    {
	current->right(bead);
	bead->left(current);	
	current = bead;
    } 
    else
    {
	nbead = vpool;
	while (nbead != NULL)
	{
	    nbead->getPoint(npoint);
	    if ((fabs(npoint[0] - coord[0]) < VERT_FUZZ) &&
	    	(fabs(npoint[1] - coord[1]) < VERT_FUZZ) &&
	    	(fabs(npoint[2] - coord[2]) < VERT_FUZZ))
		return (nbead->Offset());
	    nbead = (VertexRecordBead *)nbead->right();
	}
	current->right(bead);
	bead->left(current);
	current = bead;
    }
    fltVertTable.vtxlen += FLT_VERT_SHARED_ABS_TEX_LENGTH;
    current->Offset(currentOffset);
    currentOffset += FLT_VERT_SHARED_ABS_TEX_LENGTH;
    return (current->Offset());
}

/*******************************************************************************
*     Function: addVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
int VertexTableBead::addVertex(double coord[3], float norm[3], float tex[2])
{
    VertexRecordBead *nbead;
    double npoint[3];

    VertexRecordBead *bead = new VertexRecordBead(coord, norm, tex); 
    if (vpool == NULL)
    {
	vpool = bead;
        current = bead;
    }
    else if (!sharedVertex)
    {
	current->right(bead);
	bead->left(current);	
	current = bead;
    } 
    else
    {
	nbead = vpool;
	while (nbead != NULL)
	{
	    nbead->getPoint(npoint);
	    if ((fabs(npoint[0] - coord[0]) < VERT_FUZZ) &&
	    	(fabs(npoint[1] - coord[1]) < VERT_FUZZ) &&
	    	(fabs(npoint[2] - coord[2]) < VERT_FUZZ))
		return (nbead->Offset());
	    nbead = (VertexRecordBead *)nbead->right();
	}
	current->right(bead);
	bead->left(current);
	current = bead;
    }
    fltVertTable.vtxlen += FLT_VERT_SHARED_NORM_TEX_LENGTH;
    current->Offset(currentOffset);
    currentOffset += FLT_VERT_SHARED_NORM_TEX_LENGTH;
    return (current->Offset());
}

/*******************************************************************************
*     Function: getVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
VertexRecordBead *VertexTableBead::getVertex(int offset)
{
    VertexRecordBead *vtx = vpool;
    while (vtx != NULL)
    {
	if (vtx->Offset() == offset)
	    return vtx;
	vtx = (VertexRecordBead *)vtx->right();
    }
    return NULL;
}

/*******************************************************************************
*     Function: getVertex 
*        Class: VertexTableBead
*       Access: Public
*  Description:
*        Input:
*       Output:
*******************************************************************************/
VertexRecordBead *VertexTableBead::getVertex(const VertexOffsetBead voffset)
{
    int offset = voffset.offset();
    VertexRecordBead *vtx = vpool;
    while (vtx != NULL)
    {
	if (vtx->Offset() == offset)
	    return vtx;
	vtx = (VertexRecordBead *)vtx->right();
    }
    return NULL;
}

/*******************************************************************************
*     Function: printVertexTable
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void printVertexTable(const mgVertTable& fltVertTable)
{
    printf("\n");
    printf("==============================================================\n");
    printf(" VERTEX TABLE HEADER RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", fltVertTable.length);
    printf("Vertex pool length:\t\t\t%d\n", fltVertTable.vtxlen);
}

/*******************************************************************************
*     Function: print
*        Class: VertexTableBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void VertexTableBead::print(void) const
{
    printVertexTable(fltVertTable);
}

/*******************************************************************************
*     Function: printVertPool
*        Class: VertexTableBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void VertexTableBead::printVertPool(void) const
{
    VertexRecordBead *vert;
    printVertexTable(fltVertTable);
    vert = vpool;
    while (vert != NULL)
    {
	printVertexRecord(vert->Type(), vert->fltStruct());
	vert = (VertexRecordBead *)vert->right();
    } 
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexListBead 
*       Access: Public
*  Description: Default constructor 
*        Input: 
*       Output:
*******************************************************************************/
VertexListBead::VertexListBead(void)
{
    type = MG_VTXLIST;
    strcpy(name, DEFAULT_NAME);

    fltVertList.opcode = MG_VTXLIST;
    fltVertList.length = FLT_VERT_LIST_LENGTH; // starts off at 4
    fltflag = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexListBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
VertexListBead::VertexListBead(const mgVertList& _fltVertList)
{
    type = MG_VTXLIST;
    strcpy(name, DEFAULT_NAME);

    fltVertList = _fltVertList;
    fltflag = 1;  // Indicates source was a flight file
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexListBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void VertexListBead::addOffset(void)
{
    // Only increment if source is not a flight file
    if (fltflag != 1)
	fltVertList.length += VERTEX_OFFSET_LENGTH;
}

/*******************************************************************************
*     Function: print 
*        Class: VertexListBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void VertexListBead::print(void) const
{
    printf("\n");
    printf("==============================================================\n");
    printf(" VERTEX LIST RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", fltVertList.length);
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexOffsetBead 
*       Access: Public
*  Description:  
*        Input: A valid offset into the vertex pool 
*       Output:
*******************************************************************************/
VertexOffsetBead::VertexOffsetBead(int offset)
{
    type = MG_VTXOFFSET;
    strcpy(name, DEFAULT_NAME);

    fltVertOffset.vtxoffset = offset; 
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexOffsetBead 
*       Access: Public
*  Description: Default constructor 
*        Input: 
*       Output:
*******************************************************************************/
VertexOffsetBead::VertexOffsetBead(void)
{
    type = MG_VTXOFFSET;
    strcpy(name, DEFAULT_NAME);

    fltVertOffset.vtxoffset = 0;  // Need to determine offset into vertex pool
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: VertexOffsetBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
VertexOffsetBead::VertexOffsetBead(const mgVertOffset& _fltVertOffset)
{
    type = MG_VTXOFFSET;
    strcpy(name, DEFAULT_NAME);

    fltVertOffset = _fltVertOffset;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Destructor
*        Class: VertexOffsetBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
VertexOffsetBead::~VertexOffsetBead(void)
{
}

/*******************************************************************************
*     Function: print 
*        Class: VertexOffsetBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void VertexOffsetBead::print(void) const
{
    printf("\n");
    printf("==============================================================\n");
    printf(" VERTEX OFFSET RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Offset:\t\t\t\t\t%d\n", fltVertOffset.vtxoffset);
}

/*******************************************************************************
*     Function: Constructor
*        Class: GroupBead
*       Access: Public
*  Description: Default constructor 
*        Input: 
*       Output:
*******************************************************************************/
GroupBead::GroupBead(void)
{
    type = MG_GROUP;
    strcpy(name, DEFAULT_NAME);

    fltGroup.opcode = 2;
    fltGroup.length = FLT_GROUP_LENGTH;
    fltGroup.relPri = 0;
    fltGroup.flags = 0;
    fltGroup.fxId1 = 0;
    fltGroup.fxId2 = 0;
    fltGroup.signif = 0;
    fltGroup.layer = 0; 

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: GroupBead
*       Access: Public
*  Description: 
*        Input: 
*       Output:
*******************************************************************************/
GroupBead::GroupBead(char *_name)
{
    type = MG_GROUP;
    strcpy(name, _name);

    fltGroup.opcode = MG_GROUP;
    fltGroup.length = FLT_GROUP_LENGTH;

    // initialize auxiliary data
    aux.matrix = NULL;
    aux.bbox = NULL;
    aux.comment = NULL;
    aux.id = NULL;
    aux.numvert = 0;

    if (strlen(_name) > MAX_SHORT_ID_LENGTH)
    {
	LongID(_name);
	strncpy(fltGroup.id, _name, MAX_SHORT_ID_LENGTH);
    }
    else
    	strcpy(fltGroup.id, _name);
    fltGroup.relPri = 0;
    fltGroup.flags = 0;
    fltGroup.fxId1 = 0;
    fltGroup.fxId2 = 0;
    fltGroup.signif = 0;
    fltGroup.layer = 0; 

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: GroupBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
GroupBead::GroupBead(const mgGroup& _fltGroup)
{
    type = MG_GROUP;
    strcpy(name, _fltGroup.id);

    fltGroup = _fltGroup;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: LongID 
*        Class: GroupBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void GroupBead::LongID(char *name)
{
    // deal with multiple different comments later
    if (aux.id != NULL)
 	fprintf(stderr, "Warning: id field of object already occupied\n");
    aux.id = (mgLongID *)malloc(sizeof(mgLongID));
    aux.id->opcode = MG_LONGID;
    // must consider SGI word alignment when calculating the length field
    int textlength = strlen(name); 
    // word alignment on 32 bytes
    if (textlength % 32)
    	textlength += 4 - (textlength % 4);
    aux.id->length = sizeof(aux.id->opcode) +    
			  sizeof(aux.id->length) +
			  textlength;
    strcpy(aux.id->text, name);
}

/*******************************************************************************
*     Function: printGroup 
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void printGroup(const mgGroup& fltGroup) 
{
    char flag[12];

    printf("\n");
    printf("==============================================================\n");
    printf(" GROUP RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", fltGroup.length);
    printf("Id:\t\t\t\t\t%s\n", fltGroup.id);
    printf("Relative priority:\t\t\t%d\n", fltGroup.relPri);
    strcpy(flag, "FALSE");
    if (fltGroup.flags & 1) strcpy(flag, "TRUE");
    printf("Flag:\tTerrain:\t\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltGroup.flags & 2) strcpy(flag, "TRUE");
    printf("Flag:\tForward animation:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltGroup.flags & 4) strcpy(flag, "TRUE");
    printf("Flag:\tCycling animation:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltGroup.flags & 8) strcpy(flag, "TRUE");
    printf("Flag:\tBounding box follows:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltGroup.flags & 16) strcpy(flag, "TRUE");
    printf("Flag:\tFreeze bounding box:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltGroup.flags & 32) strcpy(flag, "TRUE");
    printf("Flag:\tDefault parent:\t\t\t%s\n", flag);
    printf("Special effects id 1:\t\t\t%d\n", fltGroup.fxId1);
    printf("Special effects id 2:\t\t\t%d\n", fltGroup.fxId2);
    printf("Significance flags:\t\t\t%d\n", fltGroup.signif);
    printf("Layer number:\t\t\t\t%c\n", fltGroup.layer);
}

/*******************************************************************************
*     Function: print 
*        Class: GroupBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void GroupBead::print(void) const
{
    printGroup(fltGroup);
}

/*******************************************************************************
*     Function: Constructor
*        Class: SwitchBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
SwitchBead::SwitchBead(const mgSwitch& _fltSwitch)
{
    type = MG_SWITCH;
    strcpy(name, _fltSwitch.id);

    fltSwitch = _fltSwitch;
    parent = next = prev = child = NULL;
}

/*******************************************************************************
*     Function: print 
*        Class: SwitchBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void SwitchBead::print(void) const
{
}

/*******************************************************************************
*     Function: Constructor
*        Class: DofBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
DofBead::DofBead(const mgDof& _fltDof)
{
    type = MG_DOF;
    strcpy(name, _fltDof.id);

    fltDof = _fltDof;
    parent = next = prev = child = NULL;
}

/*******************************************************************************
*     Function: print 
*        Class: DofBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void DofBead::print(void) const
{
}

/*******************************************************************************
*     Function: Constructor
*        Class: LodBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
LodBead::LodBead(const mgLod& _fltLod)
{
    type = MG_LOD;
    strcpy(name, _fltLod.id);

    fltLod = _fltLod;
    parent = next = prev = child = NULL;
}

/*******************************************************************************
*     Function: print 
*        Class: LodBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void LodBead::print(void) const
{
}

/*******************************************************************************
*     Function: Constructor
*        Class: FLodBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
FLodBead::FLodBead(const mgFLod& _fltLod)
{
    type = MG_LODFLOAT;
    strcpy(name, _fltLod.id);

    fltLod = _fltLod;
    parent = next = prev = child = NULL;
}

/*******************************************************************************
*     Function: print 
*        Class: FLodBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void FLodBead::print(void) const
{
}

/*******************************************************************************
*     Function: Constructor
*        Class: ObjectBead
*       Access: Public
*  Description: Default constructor 
*        Input: 
*       Output:
*******************************************************************************/
ObjectBead::ObjectBead(void)
{
    type = MG_OBJECT;
    strcpy(name, DEFAULT_NAME);

    fltObject.opcode = MG_OBJECT;
    fltObject.length = FLT_OBJECT_LENGTH;
    fltObject.flags = 0;
    fltObject.relPri = 0;
    fltObject.transp = 0;  // Defaults to no transparency
    fltObject.fxId1 = 0;
    fltObject.fxId2 = 0;
    fltObject.signif = 0;
    fltObject.spare1 = 0;

    // initialize auxiliary data
    aux.matrix = NULL;
    aux.bbox = NULL;
    aux.comment = NULL;
    aux.id = NULL;
    aux.numvert = 0;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: ObjectBead
*       Access: Public
*  Description: 
*        Input: 
*       Output:
*******************************************************************************/
ObjectBead::ObjectBead(char *_name)
{
    type = MG_OBJECT;
    strcpy(name, _name);

    fltObject.opcode = MG_OBJECT;
    fltObject.length = FLT_OBJECT_LENGTH;

    // initialize auxiliary data
    aux.matrix = NULL;
    aux.bbox = NULL;
    aux.comment = NULL;
    aux.id = NULL;
    aux.numvert = 0;
  
    if (strlen(_name) > MAX_SHORT_ID_LENGTH)
    {
  	LongID(_name);
	strncpy(fltObject.id, _name, MAX_SHORT_ID_LENGTH);
    }
    else
    	strcpy(fltObject.id, _name);
    fltObject.flags = 0;
    fltObject.relPri = 0;
    fltObject.transp = 0;  // Defaults to no transparency
    fltObject.fxId1 = 0;
    fltObject.fxId2 = 0;
    fltObject.signif = 0;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: ObjectBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
ObjectBead::ObjectBead(const mgObject& _fltObject)
{
    type = MG_OBJECT;
    strcpy(name, _fltObject.id);
    fltObject = _fltObject;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: LongID 
*        Class: ObjectBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void ObjectBead::LongID(char *name)
{
    // deal with multiple different comments later
    if (aux.id != NULL)
 	fprintf(stderr, "Warning: id field of object already occupied\n");
    aux.id = (mgLongID *)malloc(sizeof(mgLongID));
    aux.id->opcode = MG_LONGID;
    // must consider SGI word alignment when calculating the length field
    int textlength = strlen(name); 
    // word alignment on 32 bytes
    if (textlength % 32)
    	textlength += 4 - (textlength % 4);
    aux.id->length = sizeof(aux.id->opcode) +    
			  sizeof(aux.id->length) +
			  textlength;
    strcpy(aux.id->text, name);
}

/*******************************************************************************
*     Function: printObject
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void printObject(const mgObject& fltObject)
{
    char flag[12];

    printf("\n");
    printf("==============================================================\n");
    printf(" OBJECT RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", fltObject.length);
    printf("Id:\t\t\t\t\t%s\n", fltObject.id);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 1) strcpy(flag, "TRUE");
    printf("Flag: Don't display in daylight:\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 2) strcpy(flag, "TRUE");
    printf("Flag: Don't display at dusk:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 4) strcpy(flag, "TRUE");
    printf("Flag: Don't display at night:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 8) strcpy(flag, "TRUE");
    printf("Flag: Don't illuminate:\t\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 16) strcpy(flag, "TRUE");
    printf("Flag: Flat shaded:\t\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 32) strcpy(flag, "TRUE");
    printf("Flag: Group's shadow object:\t\t%s\n", flag);
    strcpy(flag, "FALSE");
    if (fltObject.flags & 64) strcpy(flag, "TRUE");
    printf("Flag: Terrain:\t\t\t\t%s\n", flag);
    printf("Object relative priority:\t\t%d\n", fltObject.relPri);
    printf("Transparency factor:\t\t\t%d\n", fltObject.transp);
    printf("Special effects id 1:\t\t\t%d\n", fltObject.fxId1);
    printf("Special effects id 2:\t\t\t%d\n", fltObject.fxId2);
    printf("Significance:\t\t\t\t%d\n", fltObject.signif);
}

/*******************************************************************************
*     Function: print 
*        Class: ObjectBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void ObjectBead::print(void) const
{
    printObject(fltObject);
}

/*******************************************************************************
*     Function: Constructor
*        Class: PolygonBead
*       Access: Public
*  Description: Default constructor  
*        Input: 
*       Output:
*******************************************************************************/
PolygonBead::PolygonBead(void)
{
    type = MG_POLYGON;
    strcpy(name, DEFAULT_NAME);

    fltPoly.opcode = MG_POLYGON;
    fltPoly.length = FLT_POLYGON_LENGTH;
    fltPoly.IRCode = 0;
    fltPoly.relPri = 0;
    fltPoly.drawType = 0;  // Defaults to draw solid with no backface
    fltPoly.spare1 = 1;  // Defaults to texwhite = TRUE
    fltPoly.color1 = 4096;
    fltPoly.color2 = -1;
    fltPoly.textureTemplate = 0;  // Defaults to no template transparency
    fltPoly.detail = -1;
    fltPoly.texture = -1;
    fltPoly.material = -1;
    fltPoly.surfaceMaterialCode = 0;
    fltPoly.featureId = 0;
    fltPoly.IRMaterial = 0;
    fltPoly.transp = 0;  // Defaults to solid 
    fltPoly.spare4[0] = 0;

    // initialize auxiliary data
    aux.matrix = NULL;
    aux.bbox = NULL;
    aux.comment = NULL;
    aux.id = NULL;
    aux.numvert = 0;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: PolygonBead
*       Access: Public
*  Description:   
*        Input: 
*       Output:
*******************************************************************************/
PolygonBead::PolygonBead(char *_name)
{
    type = MG_POLYGON;
    strcpy(name, _name);

    fltPoly.opcode = MG_POLYGON;
    fltPoly.length = FLT_POLYGON_LENGTH;

// truncate name for now
    if (strlen(_name) > 7)
    {
	fprintf(stderr, "WARNING: truncating name for polygon bead\n");
	_name[6] = '\0';
    }

    strcpy(fltPoly.id, _name);
    fltPoly.IRCode = 0;
    fltPoly.relPri = 0;
    fltPoly.drawType = 0;  // Defaults to draw solid with no backface
    fltPoly.spare1 = 1;  // Defaults to texwhite = TRUE
    fltPoly.color1 = 4096;
    fltPoly.color2 = 0;
    fltPoly.spare2 = 0;
    fltPoly.textureTemplate = 0;  // Defaults to no template transparency
    fltPoly.detail = -1;
    fltPoly.texture = -1;
    fltPoly.material = -1;
    fltPoly.surfaceMaterialCode = 0;
    fltPoly.featureId = 0;
    fltPoly.IRMaterial = 0;
    fltPoly.transp = 0;  // Defaults to solid 
    fltPoly.spare4[0] = 0;

    // initialize auxiliary data
    aux.matrix = NULL;
    aux.bbox = NULL;
    aux.comment = NULL;
    aux.id = NULL;
    aux.numvert = 0;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: PolygonBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
PolygonBead::PolygonBead(const mgPolygon& _fltPoly)
{
    type = MG_POLYGON;

    strcpy(name, _fltPoly.id);

    fltPoly = _fltPoly;

    // initialize auxiliary data
    aux.matrix = NULL;
    aux.bbox = NULL;
    aux.comment = NULL;
    aux.id = NULL;
    aux.numvert = 0;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: comment 
*        Class: PolygonBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void PolygonBead::Comment(char *comment)
{
    // deal with multiple different comments later
    if (aux.comment != NULL)
 	fprintf(stderr, "Warning: comment field of polygon already occupied\n");
    aux.comment = (mgComment *)malloc(sizeof(mgComment));
    aux.comment->opcode = MG_COMMENT;
    // must consider SGI word alignment when calculating the length field
    int textlength = strlen(comment); 
    // word alignment on 32 bytes
    if (textlength % 32)
    	textlength += 4 - (textlength % 4);
    aux.comment->length = sizeof(aux.comment->opcode) +    
			  sizeof(aux.comment->length) +
			  textlength;
    strcpy(aux.comment->text, comment);
}

/*******************************************************************************
*     Function: comment 
*        Class: PolygonBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void PolygonBead::Comment(mgComment& comment)
{
    // deal with multiple different comments later
    if (aux.comment != NULL)
 	fprintf(stderr, "Warning: comment field of polygon already occupied\n");
    aux.comment = &comment;
}

/*******************************************************************************
*     Function: printPolygon 
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void printPolygon(const mgPolygon& fltPoly)
{
    char howdraw[64];

    printf("\n");
    printf("==============================================================\n");
    printf(" POLYGON RECORD\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t\t%d\n", fltPoly.length);
    printf("Id:\t\t\t\t\t%s\n", fltPoly.id);
    printf("IR code:\t\t\t\t%d\n", fltPoly.IRCode);
    printf("Polygon relative priority:\t\t%d\n", fltPoly.relPri);
    switch (fltPoly.drawType) {
    	case 1: strcpy(howdraw, "Draw solid backfaced"); break;
    	case 0: strcpy(howdraw, "Draw solid no backface"); break;
    	case 2: strcpy(howdraw, "Draw wireframe and not closed"); break;
    	case 3: strcpy(howdraw, "Draw closed wireframe"); break;
    	case 4: strcpy(howdraw, "Surround with wireframe in alt. color"); break;
    	case 8: strcpy(howdraw, "Omni-directional light"); break;
    	case 9: strcpy(howdraw, "Uni-directional light"); break;
    	case 10: strcpy(howdraw, "Bi-directional light"); break;
	default: strcpy(howdraw, "Unknown draw code"); break; } 
    printf("Flag:\tDrawtype:\t\t\t%s\n", howdraw);
    if (fltPoly.spare1 == 1) strcpy(howdraw, "TRUE");
    else strcpy(howdraw, "FALSE");
    printf("Texwhite:\t\t\t\t%s\n", howdraw);
    printf("Primary color/intensity code:\t\t%d\n", fltPoly.color1);
    printf("Secondary color code:\t\t\t%d\n", fltPoly.color2);
    switch (fltPoly.textureTemplate) {
	case 0: strcpy(howdraw, "None"); break;
	case 1: strcpy(howdraw, "Fixed"); break;
	case 3: strcpy(howdraw, "Axis type rotate"); break;
	case 5: strcpy(howdraw, "Point rotate"); break;
	default: strcpy(howdraw, "Unknown"); break; }
    printf("Set template transparency:\t\t%s\n", howdraw);
    printf("Detail texture pattern no.:\t\t%d\n", fltPoly.detail);
    printf("Texture pattern no.:\t\t\t%d\n", fltPoly.texture);
    printf("Material code [0-63]:\t\t\t%d\n", fltPoly.material);
    printf("Surface Material code:\t\t\t%d\n", fltPoly.surfaceMaterialCode);
    printf("Feature ID:\t\t\t\t%d\n", fltPoly.featureId);
    printf("IR material code:\t\t\t%d\n", fltPoly.IRMaterial);
    printf("Transparency:\t\t\t\t%x\n", fltPoly.transp);
    printf("Influences LOD generation:\t\t%d\n", fltPoly.spare4[0]);
}

/*******************************************************************************
*     Function: printPolygonAux 
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void printPolygonAux(const polygonAux& aux)
{
    if (aux.comment != NULL)
    	printComment(*aux.comment);
}

/*******************************************************************************
*     Function: print 
*        Class: PolygonBead 
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
void PolygonBead::print(void) const
{
    printPolygon(fltPoly);
    printPolygonAux(aux);
}

/*******************************************************************************
*     Function: Constructor
*        Class: ColorTableBead
*       Access: Public
*  Description: Default color table 
*        Input: 
*       Output:
*******************************************************************************/
ColorTableBead::ColorTableBead(void)
{
    int i;
    FILE *ctabfile;

    type = MG_COLOR_TABLE; 
    strcpy(name, "COLOR_TABLE");

    if ((ctabfile = fopen("ctab.bin", "r")) != NULL)
    {
	if (fread(&fltColTable, sizeof(mgColorTable), 1, ctabfile) <= 0)
	{
	    fprintf(stderr, "Couldn't read <ctab.bin>\n");
	    exit(-1);
	}
	fclose(ctabfile);
    }
    else
    {
	fprintf(stderr, "Couldn't find binary color table file <ctab.bin>\n");
	fprintf(stderr, "Creating text version of colortable\n");
    fltColTable.opcode = MG_COLOR_TABLE;
    fltColTable.length = FLT_COLOR_TABLE_LENGTH;
    mgColorTable *ctab = &fltColTable;

   ctab->color[0][0] = 254; ctab->color[0][1] = 254; ctab->color[0][2] = 254;
   ctab->color[1][0] = 241; ctab->color[1][1] = 166; ctab->color[1][2] = 140;
   ctab->color[2][0] = 239; ctab->color[2][1] = 205; ctab->color[2][2] = 142;
   ctab->color[3][0] = 236; ctab->color[3][1] = 239; ctab->color[3][2] = 142;
   ctab->color[4][0] = 205; ctab->color[4][1] = 239; ctab->color[4][2] = 143;
   ctab->color[5][0] = 172; ctab->color[5][1] = 240; ctab->color[5][2] = 142;
   ctab->color[6][0] = 142; ctab->color[6][1] = 240; ctab->color[6][2] = 152;
   ctab->color[7][0] = 143; ctab->color[7][1] = 239; ctab->color[7][2] = 190;
   ctab->color[8][0] = 141; ctab->color[8][1] = 240; ctab->color[8][2] = 227;
   ctab->color[9][0] = 142; ctab->color[9][1] = 220; ctab->color[9][2] = 239;
   ctab->color[10][0] = 143; ctab->color[10][1] = 184; ctab->color[10][2] = 239;
   ctab->color[11][0] = 144; ctab->color[11][1] = 146; ctab->color[11][2] = 238;
   ctab->color[12][0] = 222; ctab->color[12][1] = 81; ctab->color[12][2] = 32;
   ctab->color[13][0] = 222; ctab->color[13][1] = 158; ctab->color[13][2] = 32;
   ctab->color[14][0] = 222; ctab->color[14][1] = 226; ctab->color[14][2] = 28;
   ctab->color[15][0] = 154; ctab->color[15][1] = 222; ctab->color[15][2] = 31;
   ctab->color[16][0] = 90; ctab->color[16][1] = 222; ctab->color[16][2] = 32;
   ctab->color[17][0] = 29; ctab->color[17][1] = 225; ctab->color[17][2] = 44;
   ctab->color[18][0] = 31; ctab->color[18][1] = 223; ctab->color[18][2] = 129;
   ctab->color[19][0] = 30; ctab->color[19][1] = 224; ctab->color[19][2] = 199;
   ctab->color[20][0] = 30; ctab->color[20][1] = 179; ctab->color[20][2] = 224;
   ctab->color[21][0] = 32; ctab->color[21][1] = 112; ctab->color[21][2] = 223;
   ctab->color[22][0] = 31; ctab->color[22][1] = 31; ctab->color[22][2] = 222;
   ctab->color[23][0] = 173; ctab->color[23][1] = 187; ctab->color[23][2] = 209;
   ctab->color[24][0] = 175; ctab->color[24][1] = 207; ctab->color[24][2] = 193;
   ctab->color[25][0] = 185; ctab->color[25][1] = 208; ctab->color[25][2] = 173;
   ctab->color[26][0] = 205; ctab->color[26][1] = 192; ctab->color[26][2] = 176;
   ctab->color[27][0] = 221; ctab->color[27][1] = 200; ctab->color[27][2] = 218;

    for (i=0; i<MG_CT_FIXED; i++)
    {
        fltColTable.fixedColor[i][0] = 0;
        fltColTable.fixedColor[i][1] = 0;
        fltColTable.fixedColor[i][2] = 0;
    }
  }

    fixedColorCount = 4097;  // 4096 is white
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: ColorTableBead
*       Access: Public
*  Description:  
*        Input: A valid flight color table
*       Output:
*******************************************************************************/
ColorTableBead::ColorTableBead(const mgColorTable& _fltColTable)
{
    type = MG_COLOR_TABLE;
    strcpy(name, "COLOR_TABLE");

    fltColTable = _fltColTable;
    fixedColorCount = 4097; // 4096 is white
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Destructor
*        Class: ColorTableBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
ColorTableBead::~ColorTableBead()
{
}

/*******************************************************************************
*     Function: add
*        Class: ColorTableBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
ulong ColorTableBead::add(short value[3])
{
    if ((fixedColorCount+1) > (TOTAL_INTERP_PLUS_SPARE + NUM_FIXED_COLORS))
    {
	fprintf(stderr,"Warning:out of indices for fixed colors -add failed\n");
	return (0);
    }
    VEC3COPY(fltColTable.fixedColor[fixedColorCount-TOTAL_INTERP_PLUS_SPARE], 
								value);
    return (fixedColorCount++);
}

/*******************************************************************************
*     Function: add
*        Class: ColorTableBead
*       Access: Public
*  Description:  
*        Input: 
*       Output:
*******************************************************************************/
ulong ColorTableBead::add(short value[3], int delta)
{
    ulong i;

    if ((fixedColorCount+1) > (TOTAL_INTERP_PLUS_SPARE + NUM_FIXED_COLORS))
    {
	fprintf(stderr,"Warning:out of indices for fixed colors- add failed\n");
	return (0);
    }
    
    for (i=0; i<(fixedColorCount-TOTAL_INTERP_PLUS_SPARE); i++)
    {
	if ((abs(fltColTable.fixedColor[i][0] - value[0]) < delta) &&
	    (abs(fltColTable.fixedColor[i][1] - value[1]) < delta) &&
	    (abs(fltColTable.fixedColor[i][2] - value[2]) < delta))
{
printf("returning: %d\n", i+TOTAL_INTERP_PLUS_SPARE);
	    return (i+TOTAL_INTERP_PLUS_SPARE);
}
    }
    VEC3COPY(fltColTable.fixedColor[fixedColorCount-TOTAL_INTERP_PLUS_SPARE], 
								value);
    return (fixedColorCount++);
}

/*******************************************************************************
*     Function: printColorTable
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
void printColorTable(const mgColorTable& fltColTable) 
{
    int i;

    printf("\n");
    printf("==============================================================\n");
    printf(" COLOR TABLE\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t%d\n", fltColTable.length);
    printf("Variable Intensity colors\n");
    printf("\nINDEX\tRED\t\tGREEN\t\tBLUE\n");
    printf("---------------------------------------------------\n");

    for (i=0;i<MG_CT_SHADED;i++)
       printf(" %d\t%d\t\t%d\t\t%d\n", i, fltColTable.color[i][0],
                                          fltColTable.color[i][1],
                                          fltColTable.color[i][2]);

    printf("\nFixed intensity colors\n\n");
    printf("INDEX\tRED\t\tGREEN\t\tBLUE\n");
    printf("---------------------------------------------------\n");

    for (i=0;i<MG_CT_FIXED;i++)
       printf(" %d\t%d\t\t%d\t\t%d\n", i, fltColTable.fixedColor[i][0],
                                          fltColTable.fixedColor[i][1],
                                          fltColTable.fixedColor[i][2]);
}

/*******************************************************************************
*     Function: convertRGB  
*  Description: Converts an index into the color table into an RGB value
*        Input: 
*       Output:
*******************************************************************************/
uint convertRGB(const mgColorTable& fltColTable, short index, double color[3]) 
{
    int row, col;

    if (index > (TOTAL_INTERP_PLUS_SPARE + NUM_FIXED_COLORS))
	return 0;
    
    if (index < TOTAL_INTERP_COLORS)
    {
	col = index / COLOR_INTENSITIES;
	row = index - (col * COLOR_INTENSITIES);

	color[0] = fltColTable.color[col][0] * row / COLOR_INTENSITIES;
	color[1] = fltColTable.color[col][1] * row / COLOR_INTENSITIES;
	color[2] = fltColTable.color[col][2] * row / COLOR_INTENSITIES;
    }
    else if (index < TOTAL_INTERP_PLUS_SPARE)
    {
	color[0] = color[1] = color[2] = 0.0;  // Currently unused by MultiGen
	return 0;
    }
    else
    {
	color[0] = fltColTable.fixedColor[index - TOTAL_INTERP_PLUS_SPARE][0];
	color[1] = fltColTable.fixedColor[index - TOTAL_INTERP_PLUS_SPARE][1];
	color[2] = fltColTable.fixedColor[index - TOTAL_INTERP_PLUS_SPARE][2];
    }
    return 1;
}

/*******************************************************************************
*     Function: print 
*        Class: ColorTableBead
*       Access: Public
*  Description:
*        Input: 
*       Output:
*******************************************************************************/
void ColorTableBead::print(void) const
{
    printColorTable(fltColTable);
}

/*******************************************************************************
*     Function: Constructor
*        Class: MaterialTableBead
*       Access: Public
*  Description: Default constructor 
*        Input:
*       Output:
*******************************************************************************/
MaterialTableBead::MaterialTableBead(void)
{
    FILE *mtabfile;

    type = MG_MATERIAL_TABLE;
    strcpy(name, "MATERIAL_TABLE");

    if ((mtabfile = fopen("mtab.bin", "r")) != NULL)
    {
	if (fread(&fltMatTable, sizeof(mgMaterialTable), 1, mtabfile) <= 0)
	{
	    fprintf(stderr, "Couldn't read <mtab.bin>\n");
	    exit(-1);
	}
	fclose(mtabfile);
    }
    else
    	fprintf(stderr,"Couldn't find binary material table file <mtab.bin>\n");

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Constructor
*        Class: MaterialTableBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
MaterialTableBead::MaterialTableBead(const mgMaterialTable& _fltMatTable)
{
    type = MG_MATERIAL_TABLE;
    strcpy(name, "MATERIAL_TABLE");

    fltMatTable = _fltMatTable;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: printMaterialTable
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void printMaterialTable(const mgMaterialTable& fltMatTable, int matCnt) 
{
    int  matNdx;
    char flag[12];

    if (matCnt == 0)
	matCnt = NUM_MATERIALS;

    printf("\n");
    printf("==============================================================\n");
    printf(" MATERIAL TABLE\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t%d\n", fltMatTable.length);
    for (matNdx=0;matNdx<matCnt;matNdx++)
    {
       printf("\nMat #%d\tAmbient Diffuse Specular Emissive Shininess Alpha\n",
              matNdx);
       printf("---------------------------------------------------------\n");
       printf("Red\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n",
              fltMatTable.mat[matNdx].ambient[0],
              fltMatTable.mat[matNdx].diffuse[0],
              fltMatTable.mat[matNdx].specular[0],
              fltMatTable.mat[matNdx].emission[0],
              fltMatTable.mat[matNdx].shininess,
              fltMatTable.mat[matNdx].alpha);
       printf("Green\t%.3f\t%.3f\t%.3f\t%.3f\n",
              fltMatTable.mat[matNdx].ambient[1],
              fltMatTable.mat[matNdx].diffuse[1],
              fltMatTable.mat[matNdx].specular[1],
              fltMatTable.mat[matNdx].emission[1]);
       printf("Blue\t%.3f\t%.3f\t%.3f\t%.3f\n",
              fltMatTable.mat[matNdx].ambient[2],
              fltMatTable.mat[matNdx].diffuse[2],
              fltMatTable.mat[matNdx].specular[2],
              fltMatTable.mat[matNdx].emission[2]);
       strcpy(flag, "FALSE");
       if (fltMatTable.mat[matNdx].spare1[0] & 0x1) strcpy(flag, "TRUE");
       printf("Flag:\tMaterial used:\t\t\t%s\n", flag);
    }
}

/*******************************************************************************
*     Function: print 
*        Class: MaterialTableBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void MaterialTableBead::print(void) const
{
    printMaterialTable(fltMatTable, NUM_MATERIALS);
}

/*******************************************************************************
*     Function: constructor 
*        Class: TextureBead
*       Access: Public
*  Description: Default constructor 
*        Input:
*       Output:
*******************************************************************************/
TextureBead::TextureBead(void)
{
    type = MG_TEXTURE_REF;
    strcpy(name, "DEFAULT");
    strcpy(path, "DEFAULT");

    fltTexRef.opcode = MG_TEXTURE_REF;
    fltTexRef.length = sizeof(mgTextureRef);
    strcpy(fltTexRef.file, "DEFAULT.rgb");	 
    fltTexRef.index = 0;
    fltTexRef.x = 0;
    fltTexRef.y = 0;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: constructor 
*        Class: TextureBead
*       Access: Public
*  Description:  
*        Input: Texture file name, index # and coordinates in texture pallette
*       Output:
*******************************************************************************/
TextureBead::TextureBead(char *texfilename, long index, long x, long y)
{
    type = MG_TEXTURE_REF;
    strcpy(name, "MG_TEXTURE_REF");
    strcpy(path, texfilename);

    fltTexRef.opcode = MG_TEXTURE_REF;
    fltTexRef.length = sizeof(mgTextureRef);

    if (strlen(texfilename) > 79)
    {
	fprintf(stderr, "WARNING: truncating file name for texture ref bead\n");
	texfilename[78] = '\0';
    }

    strcpy(fltTexRef.file, texfilename);	 
    fltTexRef.index = index;
    fltTexRef.x = x;
    fltTexRef.y = y;
    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: constructor 
*        Class: TextureBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
TextureBead::TextureBead(const mgTextureRef& _fltTexRef)
{
    type = MG_TEXTURE_REF;
    strcpy(name, "MG_TEXTURE_REF");
    strcpy(path, _fltTexRef.file);
    fltTexRef = _fltTexRef;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Destructor 
*        Class: TextureBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
TextureBead::~TextureBead()
{
}

/*******************************************************************************
*     Function: printTextureRef
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void printTextureRef(const mgTextureRef& fltTexRef) 
{
    printf("\n");
    printf("==============================================================\n");
    printf(" TEXTURE REFERENCE\n");
    printf("--------------------------------------------------------------\n");
    printf("Length:\t\t\t\t%d\n", fltTexRef.length);
    printf("Filename:\t\t\t%s\n", fltTexRef.file);
    printf("Index:\t\t\t\t%ld\n", fltTexRef.index);
    printf("Pallette x coord:\t\t%ld\n", fltTexRef.x);
    printf("Pallette y coord:\t\t%ld\n", fltTexRef.y);
}

/*******************************************************************************
*     Function: print 
*        Class: TextureBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void TextureBead::print(void) const
{
    printTextureRef(fltTexRef);
}

/*******************************************************************************
*     Function: constructor 
*        Class: TextureAttrBead
*       Access: Public
*  Description: Default constructor 
*        Input:
*       Output:
*******************************************************************************/
TextureAttrBead::TextureAttrBead(void)
{
    type = MG_TEXTURE_ATTR;
    strcpy(name, "DEFAULT");
    strcpy(path, "DEFAULT.rgb.attr");

    fltTexAttr.width = 2;  // # texels in u direction
    fltTexAttr.height = 2; // # texels in v direction
    fltTexAttr.rwsizeu = 1;  // real world size in u direction
    fltTexAttr.rwsizev = 1;  // real world size in v direction
    fltTexAttr.type = 4;  // Defaults to RGB
    fltTexAttr.minfilter = TX_MIPMAP_TRILINEAR;
    fltTexAttr.magfilter = TX_BILINEAR;
    fltTexAttr.wrap = TX_REPEAT;
    fltTexAttr.wrapu = 0;
    fltTexAttr.wrapv = 0;
    fltTexAttr.i1 = 0;
    fltTexAttr.j1 = 0;
    fltTexAttr.envtype = TV_MODULATE;
    fltTexAttr.rwsizeuf = 1.0;
    fltTexAttr.rwsizevf = 1.0;
    fltTexAttr.internalformat = 0;  // Default format
    fltTexAttr.externalformat = TX_PACK_8;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: constructor 
*        Class: TextureAttrBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
TextureAttrBead::TextureAttrBead(const mgTextureAttr& _fltTexAttr)
{
    type = MG_TEXTURE_ATTR;
    strcpy(name, "MG_TEXTURE_ATTR");
    fltTexAttr = _fltTexAttr;

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: constructor 
*        Class: TextureAttrBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
TextureAttrBead::TextureAttrBead(char *texfilename, uint size)
{
    FILE *attrfile;
    type = MG_TEXTURE_ATTR;
    strcpy(name, "MG_TEXTURE_ATTR");
    strcpy(path, texfilename);
    strcat(path, ".attr");

    if ((attrfile = fopen("attr.bin", "r")) != NULL)
    {
	if (fread(&fltTexAttr, sizeof(mgTextureAttr), 1, attrfile) <= 0)
	{
	     fprintf(stderr, "Couldn't read from <attr.bin>\n");
	     exit (-1);
	}
	fclose(attrfile);
	fltTexAttr.width = size;
	fltTexAttr.height = size;
//	fltTexAttr.magfilter = TX_POINT;
        fltTexAttr.wrap = TX_CLAMP;
    }
    else
    {
	fprintf(stderr, "Couldn't load default attribute file <attr.bin>\n");\
	fprintf(stderr, "Using text defaults\n");
     

    fltTexAttr.width = size;  // # texels in u direction
    fltTexAttr.height = size; // # texels in v direction
    fltTexAttr.rwsizeu = 1000;  // real world size in u direction
    fltTexAttr.rwsizev = 1000;  // real world size in v direction
    fltTexAttr.iup = 64;  // i direction considered to be up
    fltTexAttr.jup = 0;   // j direction considered to be up
    fltTexAttr.type = 4;  // Defaults to RGB
    fltTexAttr.minfilter = TX_MIPMAP_TRILINEAR;
    fltTexAttr.magfilter = TX_BILINEAR;
    fltTexAttr.wrap = TX_CLAMP;
    fltTexAttr.wrapu = 0;
    fltTexAttr.wrapv = 0;
    fltTexAttr.changed = 0;
    fltTexAttr.i1 = 0;
    fltTexAttr.j1 = 0;
    fltTexAttr.envtype = TV_MODULATE;
    fltTexAttr.spareia = 0;  // Don't want alpha intensity pattern

    fltTexAttr.rwsizeuf = 1000.0;
    fltTexAttr.rwsizevf = 1000.0;

    fltTexAttr.internalformat = 0;  // Default format
    fltTexAttr.externalformat = 0;  

    fltTexAttr.usefilter = 0;  // TRUE indicates the following 8 floats are
			       // used as MIPMAP kernel

    fltTexAttr.controlpoint = 0;  // Don't send lod or scale next

    fltTexAttr.magfilteralpha = TX_BILINEAR;
    fltTexAttr.magfiltercolor = TX_BILINEAR;

    fltTexAttr.detail = 0;  // Next 5 integers are not a detail texture

    fltTexAttr.tile = 0;  // Next four floats are not a tile
   }

    parent = NULL;
    next = NULL;
    prev = NULL;
    child = NULL;
}

/*******************************************************************************
*     Function: Destructor 
*        Class: TextureAttrBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
TextureAttrBead::~TextureAttrBead()
{
}

/*******************************************************************************
*     Function: Write 
*        Class: TextureAttrBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
uint TextureAttrBead::Write(void)
{
    if ((file = fopen(path, "w")) == NULL)
    {
	fprintf(stderr, "Couldn't open texture attribute file: %s\n", path);
	return (0);
    }
    if (fwrite(&fltTexAttr, sizeof(mgTextureAttr), 1, file) <= 0)
    {
	fprintf(stderr, "Couldn't read from texture attribute file: %s\n",
								path);
	return (0);
    }
    fclose(file);
    return (1);
}

/*******************************************************************************
*     Function: printTextureAttr
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void printTextureAttr(const mgTextureAttr& fltTexAttr) 
{
    printf("\n");
    printf("==============================================================\n");
    printf(" TEXTURE ATTRIBUTE\n");
    printf("--------------------------------------------------------------\n");
    printf("Number of texels in u direction:\t%ld\n", fltTexAttr.width);
    printf("Number of texels in v direction:\t%ld\n", fltTexAttr.height);
    printf("Real world size u:\t\t\t%.2f\n", fltTexAttr.rwsizeuf);
    printf("Real world size v:\t\t\t%.2f\n", fltTexAttr.rwsizevf);
}

/*******************************************************************************
*     Function: print 
*        Class: TextureAttrBead
*       Access: Public
*  Description:  
*        Input:
*       Output:
*******************************************************************************/
void TextureAttrBead::print(void) const
{
    printTextureAttr(fltTexAttr);
}