]> git.mxchange.org Git - flightgear.git/blob - src/Model/model.hxx
This is step "1" of probably "many" in the process of separating out the
[flightgear.git] / src / Model / model.hxx
1 // model.hxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifndef __MODEL_HXX
7 #define __MODEL_HXX 1
8
9 #ifndef __cplusplus
10 # error This library requires C++
11 #endif
12
13 #include <vector>
14
15 SG_USING_STD(vector);
16
17 #include <plib/sg.h>
18 #include <plib/ssg.h>
19
20 #include <simgear/math/point3d.hxx>
21 #include <simgear/props/props.hxx>
22
23
24 // Don't pull in the headers, since we don't need them here.
25 class ssgBranch;
26 class ssgCutout;
27 class ssgEntity;
28 class ssgRangeSelector;
29 class ssgSelector;
30 class ssgTransform;
31
32 class SGInterpTable;
33 class FGCondition;
34 class FGLocation;
35
36
37 // Has anyone done anything *really* stupid, like making min and max macros?
38 #ifdef min
39 #undef min
40 #endif
41 #ifdef max
42 #undef max
43 #endif
44
45
46 /**
47  * Load a 3D model with or without XML wrapper.
48  *
49  * If the path ends in ".xml", then it will be used as a property-
50  * list wrapper to add animations to the model.
51  *
52  * Subsystems should not normally invoke this function directly;
53  * instead, they should use the FGModelLoader declared in loader.hxx.
54  */
55 ssgBranch * fgLoad3DModel( const string& fg_root, const string &path,
56                            SGPropertyNode *prop_root,
57                            double sim_time_sec );
58
59
60 \f
61 //////////////////////////////////////////////////////////////////////
62 // Animation classes
63 //////////////////////////////////////////////////////////////////////
64
65 /**
66  * Abstract base class for all animations.
67  */
68 class Animation :  public ssgBase
69 {
70 public:
71
72   Animation (SGPropertyNode_ptr props, ssgBranch * branch);
73
74   virtual ~Animation ();
75
76   /**
77    * Get the SSG branch holding the animation.
78    */
79   virtual ssgBranch * getBranch () { return _branch; }
80
81   /**
82    * Initialize the animation, after children have been added.
83    */
84   virtual void init ();
85
86   /**
87    * Update the animation.
88    */
89   virtual void update ();
90
91 protected:
92
93   ssgBranch * _branch;
94
95 };
96
97
98 /**
99  * A no-op animation.
100  */
101 class NullAnimation : public Animation
102 {
103 public:
104   NullAnimation (SGPropertyNode_ptr props);
105   virtual ~NullAnimation ();
106 };
107
108
109 /**
110  * A range, or level-of-detail (LOD) animation.
111  */
112 class RangeAnimation : public Animation
113 {
114 public:
115   RangeAnimation (SGPropertyNode_ptr props);
116   virtual ~RangeAnimation ();
117 };
118
119
120 /**
121  * Animation to turn and face the screen.
122  */
123 class BillboardAnimation : public Animation
124 {
125 public:
126   BillboardAnimation (SGPropertyNode_ptr props);
127   virtual ~BillboardAnimation ();
128 };
129
130
131 /**
132  * Animation to select alternative versions of the same object.
133  */
134 class SelectAnimation : public Animation
135 {
136 public:
137   SelectAnimation( SGPropertyNode *prop_root,
138                    SGPropertyNode_ptr props );
139   virtual ~SelectAnimation ();
140   virtual void update ();
141 private:
142   FGCondition * _condition;
143 };
144
145
146 /**
147  * Animation to spin an object around a center point.
148  *
149  * This animation rotates at a specific velocity.
150  */
151 class SpinAnimation : public Animation
152 {
153 public:
154   SpinAnimation( SGPropertyNode *prop_root,
155                  SGPropertyNode_ptr props,
156                  double sim_time_sec );
157   virtual ~SpinAnimation ();
158   virtual void update( double sim_time_sec );
159 private:
160   SGPropertyNode_ptr _prop;
161   double _factor;
162   double _position_deg;
163   double _last_time_sec;
164   sgMat4 _matrix;
165   sgVec3 _center;
166   sgVec3 _axis;
167 };
168
169
170 /**
171  * Animation to draw objects for a specific amount of time each.
172  */
173 class TimedAnimation : public Animation
174 {
175 public:
176     TimedAnimation (SGPropertyNode_ptr props);
177     virtual ~TimedAnimation ();
178     virtual void update( double sim_time_sec );
179 private:
180     double _duration_sec;
181     double _last_time_sec;
182     int _step;
183 };
184
185
186 /**
187  * Animation to rotate an object around a center point.
188  *
189  * This animation rotates to a specific position.
190  */
191 class RotateAnimation : public Animation
192 {
193 public:
194   RotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
195   virtual ~RotateAnimation ();
196   virtual void update();
197 private:
198   SGPropertyNode_ptr _prop;
199   double _offset_deg;
200   double _factor;
201   SGInterpTable * _table;
202   bool _has_min;
203   double _min_deg;
204   bool _has_max;
205   double _max_deg;
206   double _position_deg;
207   sgMat4 _matrix;
208   sgVec3 _center;
209   sgVec3 _axis;
210 };
211
212
213 /**
214  * Animation to slide along an axis.
215  */
216 class TranslateAnimation : public Animation
217 {
218 public:
219   TranslateAnimation( SGPropertyNode *prop_root,
220                       SGPropertyNode_ptr props );
221   virtual ~TranslateAnimation ();
222   virtual void update ();
223 private:
224   SGPropertyNode_ptr _prop;
225   double _offset_m;
226   double _factor;
227   SGInterpTable * _table;
228   bool _has_min;
229   double _min_m;
230   bool _has_max;
231   double _max_m;
232   double _position_m;
233   sgMat4 _matrix;
234   sgVec3 _axis;
235 };
236
237
238
239 ////////////////////////////////////////////////////////////////////////
240 // Model placement.
241 ////////////////////////////////////////////////////////////////////////
242
243 /**
244  * A wrapper for a model with a definite placement.
245  */
246 class FGModelPlacement
247 {
248 public:
249
250   FGModelPlacement ();
251   virtual ~FGModelPlacement ();
252
253   virtual void init( const string &fg_root,
254                      const string &path,
255                      SGPropertyNode *prop_root,
256                      double sim_time_sec );
257   virtual void update( const Point3D scenery_center );
258
259   virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; }
260
261   virtual FGLocation * getFGLocation () { return _location; }
262
263   virtual bool getVisible () const;
264   virtual void setVisible (bool visible);
265
266   virtual double getLongitudeDeg () const { return _lon_deg; }
267   virtual double getLatitudeDeg () const { return _lat_deg; }
268   virtual double getElevationFt () const { return _elev_ft; }
269
270   virtual void setLongitudeDeg (double lon_deg);
271   virtual void setLatitudeDeg (double lat_deg);
272   virtual void setElevationFt (double elev_ft);
273   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
274
275   virtual double getRollDeg () const { return _roll_deg; }
276   virtual double getPitchDeg () const { return _pitch_deg; }
277   virtual double getHeadingDeg () const { return _heading_deg; }
278
279   virtual void setRollDeg (double roll_deg);
280   virtual void setPitchDeg (double pitch_deg);
281   virtual void setHeadingDeg (double heading_deg);
282   virtual void setOrientation (double roll_deg, double pitch_deg,
283                                double heading_deg);
284   
285   // Addition by Diarmuid Tyson for Multiplayer Support
286   // Allows multiplayer to get players position transform
287   virtual const sgVec4 *get_POS() { return POS; }
288
289 private:
290
291                                 // Geodetic position
292   double _lon_deg;
293   double _lat_deg;
294   double _elev_ft;
295
296                                 // Orientation
297   double _roll_deg;
298   double _pitch_deg;
299   double _heading_deg;
300
301   ssgSelector * _selector;
302   ssgTransform * _position;
303
304                                 // Location
305   FGLocation * _location;
306
307
308   // Addition by Diarmuid Tyson for Multiplayer Support
309   // Moved from update method
310   // POS for transformation Matrix
311   sgMat4 POS;
312
313 };
314
315 #endif // __MODEL_HXX