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 <string> // Standard C++ string library
36 #include <osg/ref_ptr>
38 #include <osg/NodeVisitor>
39 #include <osg/Billboard>
41 #include <simgear/structure/SGReferenced.hxx>
42 #include <simgear/structure/SGSharedPtr.hxx>
43 #include <simgear/props/props.hxx>
44 #include <simgear/math/sg_random.h>
47 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.
74 * Get the number of variant models available for the object.
76 * @return The number of variant models.
78 int get_model_count( SGPropertyNode *prop_root );
82 * Get a randomly-selected variant model for the object.
84 * @return A randomly select model from the variants.
86 osg::Node *get_random_model( SGPropertyNode *prop_root, mt *seed );
90 * Get the average number of meters^2 occupied by each instance.
92 * @return The coverage in meters^2.
94 double get_coverage_m2 () const;
97 * Get the visual range of the object in meters.
99 * @return The visual range.
101 double get_range_m () const;
104 * Get the minimum spacing between this and any
107 * @return The spacing in m.
109 double get_spacing_m () const;
113 * Get a randomized visual range
115 * @return a randomized visual range
117 double get_randomized_range_m(mt* seed) const;
120 * Get the heading type for the object.
122 * @return The heading type.
124 HeadingType get_heading_type () const;
126 virtual ~SGMatModel ();
131 friend class SGMatModelGroup;
133 SGMatModel (const SGPropertyNode * node, double range_m);
138 * Actually load the models.
140 * This class uses lazy loading so that models won't be held
141 * in memory for materials that are never referenced.
143 void load_models( SGPropertyNode *prop_root );
145 std::vector<std::string> _paths;
146 mutable std::vector<osg::ref_ptr<osg::Node> > _models;
147 mutable bool _models_loaded;
151 HeadingType _heading_type;
156 * A collection of related objects with the same visual range.
158 * Grouping objects with the same range together significantly
159 * reduces the memory requirements of randomly-placed objects.
160 * Each SGMaterial instance keeps a (possibly-empty) list of
161 * object groups for placing randomly on the scenery.
163 class SGMatModelGroup : public SGReferenced {
167 virtual ~SGMatModelGroup ();
171 * Get the visual range of the object in meters.
173 * @return The visual range.
175 double get_range_m () const;
179 * Get the number of objects in the group.
181 * @return The number of objects.
183 int get_object_count () const;
187 * Get a specific object.
189 * @param index The object's index, zero-based.
190 * @return The object selected.
192 SGMatModel * get_object (int index) const;
196 friend class SGMaterial;
198 SGMatModelGroup (SGPropertyNode * node, float default_object_range);
203 std::vector<SGSharedPtr<SGMatModel> > _objects;
206 #endif // _SG_MAT_MODEL_HXX