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 - curt@flightgear.org
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., 675 Mass Ave, Cambridge, MA 02139, 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/props/props.hxx>
43 class SGMatModelGroup;
48 * A randomly-placeable object.
50 * SGMaterial uses this class to keep track of the model(s) and
51 * parameters for a single instance of a randomly-placeable object.
52 * The object can have more than one variant model (i.e. slightly
53 * different shapes of trees), but they are considered equivalent
54 * and interchangeable.
61 * The heading type for a randomly-placed object.
70 * Get the number of variant models available for the object.
72 * @return The number of variant models.
74 int get_model_count( SGModelLib *modellib,
75 const string &fg_root,
76 SGPropertyNode *prop_root,
77 double sim_time_sec );
81 * Get a specific variant model for the object.
83 * @param index The index of the model.
86 ssgEntity *get_model( int index,
88 const string &fg_root,
89 SGPropertyNode *prop_root,
90 double sim_time_sec );
94 * Get a randomly-selected variant model for the object.
96 * @return A randomly select model from the variants.
98 ssgEntity *get_random_model( SGModelLib *modellib,
99 const string &fg_root,
100 SGPropertyNode *prop_root,
101 double sim_time_sec );
105 * Get the average number of meters^2 occupied by each instance.
107 * @return The coverage in meters^2.
109 double get_coverage_m2 () const;
113 * Get the heading type for the object.
115 * @return The heading type.
117 HeadingType get_heading_type () const;
121 friend class SGMatModelGroup;
123 SGMatModel (const SGPropertyNode * node, double range_m);
125 virtual ~SGMatModel ();
130 * Actually load the models.
132 * This class uses lazy loading so that models won't be held
133 * in memory for materials that are never referenced.
135 void load_models( SGModelLib *modellib,
136 const string &fg_root,
137 SGPropertyNode *prop_root,
138 double sim_time_sec );
140 vector<string> _paths;
141 mutable vector<ssgEntity *> _models;
142 mutable bool _models_loaded;
145 HeadingType _heading_type;
150 * A collection of related objects with the same visual range.
152 * Grouping objects with the same range together significantly
153 * reduces the memory requirements of randomly-placed objects.
154 * Each SGMaterial instance keeps a (possibly-empty) list of
155 * object groups for placing randomly on the scenery.
157 class SGMatModelGroup {
161 virtual ~SGMatModelGroup ();
165 * Get the visual range of the object in meters.
167 * @return The visual range.
169 double get_range_m () const;
173 * Get the number of objects in the group.
175 * @return The number of objects.
177 int get_object_count () const;
181 * Get a specific object.
183 * @param index The object's index, zero-based.
184 * @return The object selected.
186 SGMatModel * get_object (int index) const;
190 friend class SGMaterial;
192 SGMatModelGroup (SGPropertyNode * node);
197 vector<SGMatModel *> _objects;
202 #endif // _SG_MAT_MODEL_HXX