1 // matmodel.hxx -- class to handle models tied to a material property
3 // Written by David Megginson, December 2001
5 // Copyright (C) 1998 - 2003 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef _SG_MAT_MODEL_HXX
25 #define _SG_MAT_MODEL_HXX
28 # error This library requires C++
31 #include <simgear/compiler.h>
33 #include STL_STRING // Standard C++ string library
38 #include <simgear/structure/SGReferenced.hxx>
39 #include <simgear/structure/SGSharedPtr.hxx>
40 #include <simgear/structure/ssgSharedPtr.hxx>
41 #include <simgear/props/props.hxx>
46 class SGMatModelGroup;
51 * A randomly-placeable object.
53 * SGMaterial uses this class to keep track of the model(s) and
54 * parameters for a single instance of a randomly-placeable object.
55 * The object can have more than one variant model (i.e. slightly
56 * different shapes of trees), but they are considered equivalent
57 * and interchangeable.
59 class SGMatModel : public SGReferenced {
64 * The heading type for a randomly-placed object.
73 * Get the number of variant models available for the object.
75 * @return The number of variant models.
77 int get_model_count( SGModelLib *modellib,
78 const string &fg_root,
79 SGPropertyNode *prop_root,
80 double sim_time_sec );
84 * Get a specific variant model for the object.
86 * @param index The index of the model.
89 ssgEntity *get_model( int index,
91 const string &fg_root,
92 SGPropertyNode *prop_root,
93 double sim_time_sec );
97 * Get a randomly-selected variant model for the object.
99 * @return A randomly select model from the variants.
101 ssgEntity *get_random_model( SGModelLib *modellib,
102 const string &fg_root,
103 SGPropertyNode *prop_root,
104 double sim_time_sec );
108 * Get the average number of meters^2 occupied by each instance.
110 * @return The coverage in meters^2.
112 double get_coverage_m2 () const;
116 * Get the heading type for the object.
118 * @return The heading type.
120 HeadingType get_heading_type () const;
122 virtual ~SGMatModel ();
126 friend class SGMatModelGroup;
128 SGMatModel (const SGPropertyNode * node, double range_m);
133 * Actually load the models.
135 * This class uses lazy loading so that models won't be held
136 * in memory for materials that are never referenced.
138 void load_models( SGModelLib *modellib,
139 const string &fg_root,
140 SGPropertyNode *prop_root,
141 double sim_time_sec );
143 vector<string> _paths;
144 mutable vector<ssgSharedPtr<ssgEntity> > _models;
145 mutable bool _models_loaded;
148 HeadingType _heading_type;
153 * A collection of related objects with the same visual range.
155 * Grouping objects with the same range together significantly
156 * reduces the memory requirements of randomly-placed objects.
157 * Each SGMaterial instance keeps a (possibly-empty) list of
158 * object groups for placing randomly on the scenery.
160 class SGMatModelGroup : public SGReferenced {
164 virtual ~SGMatModelGroup ();
168 * Get the visual range of the object in meters.
170 * @return The visual range.
172 double get_range_m () const;
176 * Get the number of objects in the group.
178 * @return The number of objects.
180 int get_object_count () const;
184 * Get a specific object.
186 * @param index The object's index, zero-based.
187 * @return The object selected.
189 SGMatModel * get_object (int index) const;
193 friend class SGMaterial;
195 SGMatModelGroup (SGPropertyNode * node);
200 vector<SGSharedPtr<SGMatModel> > _objects;
205 #endif // _SG_MAT_MODEL_HXX