]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/userdata.cxx
model paging patch from Till Busch
[simgear.git] / simgear / scene / tgdb / userdata.cxx
1 // userdata.hxx -- two classes for populating ssg user data slots in association
2 //                 with our implimenation of random surface objects.
3 //
4 // Written by David Megginson, started December 2001.
5 //
6 // Copyright (C) 2001 - 2003  Curtis L. Olson  - http://www.flightgear.org/~curt
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 // $Id$
23
24 #ifdef HAVE_CONFIG_H
25 #  include <simgear_config.h>
26 #endif
27
28 #include <osgDB/Registry>
29
30 #include <simgear/sg_inlines.h>
31 #include <simgear/math/point3d.hxx>
32 #include <simgear/math/sg_geodesy.hxx>
33 #include <simgear/math/sg_random.h>
34 #include <simgear/scene/material/mat.hxx>
35 #include <simgear/scene/material/matmodel.hxx>
36
37 #include "SGModelBin.hxx"
38 #include "userdata.hxx"
39 #include "SGReaderWriterBTG.hxx"
40
41 // the following are static values needed by the runtime object
42 // loader.  However, the loading is done via a call back so these
43 // values cannot be passed as parameters.  The calling application
44 // needs to call sgUserDataInit() with the appropriate values before
45 // building / drawing any scenery.
46
47 static bool _inited = false;
48 static SGPropertyNode *root_props = NULL;
49
50 // Because BTG files are now loaded through the osgDB::Registry, there
51 // are no symbols referenced by FlightGear in this library other than
52 // sgUserDataInit. But the libraries are all statically linked, so
53 // none of the other object files in this library would be included in
54 // the executable! Sticking the static proxy here forces the BTG code
55 // to be sucked in.
56 osgDB::RegisterReaderWriterProxy<SGReaderWriterBTG> g_readerWriter_BTG_Proxy;
57
58 void sgUserDataInit( SGPropertyNode *p ) {
59     _inited = true;
60     root_props = p;
61 }
62
63  osg::Node* sgGetRandomModel(SGMatModel *obj) {
64    return obj->get_random_model( root_props );
65  }
66
67 osg::Node* sgGetModel(int i, SGMatModel *obj) {
68    return obj->get_model(i, root_props );
69  }
70
71 static void random_pt_inside_tri( float *res,
72                                   float *n1, float *n2, float *n3 )
73 {
74     double a = sg_random();
75     double b = sg_random();
76     if ( a + b > 1.0 ) {
77         a = 1.0 - a;
78         b = 1.0 - b;
79     }
80     double c = 1 - a - b;
81
82     res[0] = n1[0]*a + n2[0]*b + n3[0]*c;
83     res[1] = n1[1]*a + n2[1]*b + n3[1]*c;
84     res[2] = n1[2]*a + n2[2]*b + n3[2]*c;
85 }
86