]> git.mxchange.org Git - simgear.git/blob - simgear/scene/material/matmodel.hxx
Mathias Fröhlich:
[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  - http://www.flightgear.org/~curt
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/structure/SGReferenced.hxx>
39 #include <simgear/structure/SGSharedPtr.hxx>
40 #include <simgear/structure/ssgSharedPtr.hxx>
41 #include <simgear/props/props.hxx>
42
43 SG_USING_STD(string);
44
45
46 class SGMatModelGroup;
47 class SGModelLib;
48
49
50 /**
51  * A randomly-placeable object.
52  *
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.
58  */
59 class SGMatModel : public SGReferenced {
60
61 public:
62
63     /**
64      * The heading type for a randomly-placed object.
65      */
66     enum HeadingType {
67         HEADING_FIXED,
68         HEADING_BILLBOARD,
69         HEADING_RANDOM
70     };
71
72     /**
73      * Get the number of variant models available for the object.
74      *
75      * @return The number of variant models.
76      */
77     int get_model_count( SGModelLib *modellib,
78                          const string &fg_root,
79                          SGPropertyNode *prop_root,
80                          double sim_time_sec );
81
82
83     /**
84      * Get a specific variant model for the object.
85      *
86      * @param index The index of the model.
87      * @return The model.
88      */
89     ssgEntity *get_model( int index,
90                           SGModelLib *modellib,
91                           const string &fg_root,
92                           SGPropertyNode *prop_root,
93                           double sim_time_sec );
94
95
96     /**
97      * Get a randomly-selected variant model for the object.
98      *
99      * @return A randomly select model from the variants.
100      */
101     ssgEntity *get_random_model( SGModelLib *modellib,
102                                  const string &fg_root,
103                                  SGPropertyNode *prop_root,
104                                  double sim_time_sec );
105
106
107     /**
108      * Get the average number of meters^2 occupied by each instance.
109      *
110      * @return The coverage in meters^2.
111      */
112     double get_coverage_m2 () const;
113
114
115     /**
116      * Get the heading type for the object.
117      *
118      * @return The heading type.
119      */
120     HeadingType get_heading_type () const;
121
122     virtual ~SGMatModel ();
123
124 protected:
125
126     friend class SGMatModelGroup;
127
128     SGMatModel (const SGPropertyNode * node, double range_m);
129
130 private:
131
132     /**
133      * Actually load the models.
134      *
135      * This class uses lazy loading so that models won't be held
136      * in memory for materials that are never referenced.
137      */
138     void load_models( SGModelLib *modellib,
139                       const string &fg_root,
140                       SGPropertyNode *prop_root,
141                       double sim_time_sec );
142
143     vector<string> _paths;
144     mutable vector<ssgSharedPtr<ssgEntity> > _models;
145     mutable bool _models_loaded;
146     double _coverage_m2;
147     double _range_m;
148     HeadingType _heading_type;
149 };
150
151
152 /**
153  * A collection of related objects with the same visual range.
154  *
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.
159  */
160 class SGMatModelGroup : public SGReferenced {
161
162 public:
163
164     virtual ~SGMatModelGroup ();
165
166
167     /**
168      * Get the visual range of the object in meters.
169      *
170      * @return The visual range.
171      */
172     double get_range_m () const;
173
174
175     /**
176      * Get the number of objects in the group.
177      *
178      * @return The number of objects.
179      */
180     int get_object_count () const;
181
182
183     /**
184      * Get a specific object.
185      *
186      * @param index The object's index, zero-based.
187      * @return The object selected.
188      */
189     SGMatModel * get_object (int index) const;
190
191 protected:
192
193     friend class SGMaterial;
194
195     SGMatModelGroup (SGPropertyNode * node);
196
197 private:
198
199     double _range_m;
200     vector<SGSharedPtr<SGMatModel> > _objects;
201
202 };
203
204
205 #endif // _SG_MAT_MODEL_HXX