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.14 2008/12/18 22:33:09 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 osg::Node* sgGetModel(int i, SGMatModel *obj) { 00068 return obj->get_model(i, root_props ); 00069 } 00070 00071 static void random_pt_inside_tri( float *res, 00072 float *n1, float *n2, float *n3 ) 00073 { 00074 double a = sg_random(); 00075 double b = sg_random(); 00076 if ( a + b > 1.0 ) { 00077 a = 1.0 - a; 00078 b = 1.0 - b; 00079 } 00080 double c = 1 - a - b; 00081 00082 res[0] = n1[0]*a + n2[0]*b + n3[0]*c; 00083 res[1] = n1[1]*a + n2[1]*b + n3[1]*c; 00084 res[2] = n1[2]*a + n2[2]*b + n3[2]*c; 00085 } 00086
1.5.6