00001 // userdata.hxx -- two classes for populating ssg user data slots in association 00002 // with our implimenation of random surface objects. 00003 // 00004 // Written by David Megginson, started December 2001. 00005 // 00006 // Copyright (C) 2001 - 2003 Curtis L. Olson - http://www.flightgear.org/~curt 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License as 00010 // published by the Free Software Foundation; either version 2 of the 00011 // License, or (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, but 00014 // WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the Free Software 00020 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 // 00022 // $Id: userdata_8cxx_source.html,v 1.3 2010/02/23 22:10:17 curt Exp $ 00023 00024 #ifdef HAVE_CONFIG_H 00025 # include <simgear_config.h> 00026 #endif 00027 00028 #include <osgDB/Registry> 00029 00030 #include <simgear/sg_inlines.h> 00031 #include <simgear/math/point3d.hxx> 00032 #include <simgear/math/sg_geodesy.hxx> 00033 #include <simgear/math/sg_random.h> 00034 #include <simgear/scene/material/mat.hxx> 00035 #include <simgear/scene/material/matmodel.hxx> 00036 00037 #include "SGModelBin.hxx" 00038 #include "userdata.hxx" 00039 #include "SGReaderWriterBTG.hxx" 00040 00041 // the following are static values needed by the runtime object 00042 // loader. However, the loading is done via a call back so these 00043 // values cannot be passed as parameters. The calling application 00044 // needs to call sgUserDataInit() with the appropriate values before 00045 // building / drawing any scenery. 00046 00047 static bool _inited = false; 00048 static SGPropertyNode *root_props = NULL; 00049 00050 // Because BTG files are now loaded through the osgDB::Registry, there 00051 // are no symbols referenced by FlightGear in this library other than 00052 // sgUserDataInit. But the libraries are all statically linked, so 00053 // none of the other object files in this library would be included in 00054 // the executable! Sticking the static proxy here forces the BTG code 00055 // to be sucked in. 00056 osgDB::RegisterReaderWriterProxy<SGReaderWriterBTG> g_readerWriter_BTG_Proxy; 00057 00058 void sgUserDataInit( SGPropertyNode *p ) { 00059 _inited = true; 00060 root_props = p; 00061 } 00062 00063 osg::Node* sgGetRandomModel(SGMatModel *obj) { 00064 return obj->get_random_model( root_props ); 00065 } 00066 00067 namespace simgear 00068 { 00069 SGPropertyNode* getPropertyRoot() 00070 { 00071 return root_props; 00072 } 00073 }