]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/matmodel.hxx
Use a round-robin scheme rather than returning a random textured state.
[simgear.git] / simgear / scene / material / matmodel.hxx
1 // matmodel.hxx -- class to handle models tied to a material property
2 //
3 // Written by David Megginson, December 2001
4 //
5 // Copyright (C) 1998 - 2003  Curtis L. Olson  - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _SG_MAT_MODEL_HXX
25 #define _SG_MAT_MODEL_HXX
26
27 #ifndef __cplusplus                                                          
28 # error This library requires C++
29 #endif                                   
30
31 #include <simgear/compiler.h>
32
33 #include STL_STRING      // Standard C++ string library
34
35 #include <plib/sg.h>
36 #include <plib/ssg.h>
37
38 #include <simgear/props/props.hxx>
39
40 SG_USING_STD(string);
41
42
43 class SGMatModelGroup;
44 class SGModelLib;
45
46
47 /**
48  * A randomly-placeable object.
49  *
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.
55  */
56 class SGMatModel {
57
58 public:
59
60     /**
61      * The heading type for a randomly-placed object.
62      */
63     enum HeadingType {
64         HEADING_FIXED,
65         HEADING_BILLBOARD,
66         HEADING_RANDOM
67     };
68
69     /**
70      * Get the number of variant models available for the object.
71      *
72      * @return The number of variant models.
73      */
74     int get_model_count( SGModelLib *modellib,
75                          const string &fg_root,
76                          SGPropertyNode *prop_root,
77                          double sim_time_sec );
78
79
80     /**
81      * Get a specific variant model for the object.
82      *
83      * @param index The index of the model.
84      * @return The model.
85      */
86     ssgEntity *get_model( int index,
87                           SGModelLib *modellib,
88                           const string &fg_root,
89                           SGPropertyNode *prop_root,
90                           double sim_time_sec );
91
92
93     /**
94      * Get a randomly-selected variant model for the object.
95      *
96      * @return A randomly select model from the variants.
97      */
98     ssgEntity *get_random_model( SGModelLib *modellib,
99                                  const string &fg_root,
100                                  SGPropertyNode *prop_root,
101                                  double sim_time_sec );
102
103
104     /**
105      * Get the average number of meters^2 occupied by each instance.
106      *
107      * @return The coverage in meters^2.
108      */
109     double get_coverage_m2 () const;
110
111
112     /**
113      * Get the heading type for the object.
114      *
115      * @return The heading type.
116      */
117     HeadingType get_heading_type () const;
118
119 protected:
120
121     friend class SGMatModelGroup;
122
123     SGMatModel (const SGPropertyNode * node, double range_m);
124
125     virtual ~SGMatModel ();
126
127 private:
128
129     /**
130      * Actually load the models.
131      *
132      * This class uses lazy loading so that models won't be held
133      * in memory for materials that are never referenced.
134      */
135     void load_models( SGModelLib *modellib,
136                       const string &fg_root,
137                       SGPropertyNode *prop_root,
138                       double sim_time_sec );
139
140     vector<string> _paths;
141     mutable vector<ssgEntity *> _models;
142     mutable bool _models_loaded;
143     double _coverage_m2;
144     double _range_m;
145     HeadingType _heading_type;
146 };
147
148
149 /**
150  * A collection of related objects with the same visual range.
151  *
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.
156  */
157 class SGMatModelGroup {
158
159 public:
160
161     virtual ~SGMatModelGroup ();
162
163
164     /**
165      * Get the visual range of the object in meters.
166      *
167      * @return The visual range.
168      */
169     double get_range_m () const;
170
171
172     /**
173      * Get the number of objects in the group.
174      *
175      * @return The number of objects.
176      */
177     int get_object_count () const;
178
179
180     /**
181      * Get a specific object.
182      *
183      * @param index The object's index, zero-based.
184      * @return The object selected.
185      */
186     SGMatModel * get_object (int index) const;
187
188 protected:
189
190     friend class SGMaterial;
191
192     SGMatModelGroup (SGPropertyNode * node);
193
194 private:
195
196     double _range_m;
197     vector<SGMatModel *> _objects;
198
199 };
200
201
202 #endif // _SG_MAT_MODEL_HXX