]> git.mxchange.org Git - flightgear.git/blob - src/Model/model.hxx
86ceb019fbfc2dd8ad03a5d60ac54fb0744fda4e
[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
19
20 // Don't pull in the headers, since we don't need them here.
21 class ssgBranch;
22 class ssgEntity;
23 class ssgRangeSelector;
24 class ssgSelector;
25 class ssgTransform;
26
27 class SGPropertyNode;
28 class SGInterpTable;
29 class FGCondition;
30 class FGLocation;
31
32
33 // Has anyone done anything *really* stupid, like making min and max macros?
34 #ifdef min
35 #undef min
36 #endif
37 #ifdef max
38 #undef max
39 #endif
40
41 class FG3DModel
42 {
43 public:
44
45   FG3DModel ();
46   virtual ~FG3DModel ();
47
48   virtual void init (const string &path);
49   virtual void update (int dt);
50
51   virtual bool getVisible () const;
52   virtual void setVisible (bool visible);
53
54   virtual double getLongitudeDeg () const { return _lon_deg; }
55   virtual double getLatitudeDeg () const { return _lat_deg; }
56   virtual double getElevationFt () const { return _elev_ft; }
57
58   virtual void setLongitudeDeg (double lon_deg);
59   virtual void setLatitudeDeg (double lat_deg);
60   virtual void setElevationFt (double elev_ft);
61   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
62
63   virtual double getRollDeg () const { return _roll_deg; }
64   virtual double getPitchDeg () const { return _pitch_deg; }
65   virtual double getHeadingDeg () const { return _heading_deg; }
66
67   virtual void setRollDeg (double roll_deg);
68   virtual void setPitchDeg (double pitch_deg);
69   virtual void setHeadingDeg (double heading_deg);
70   virtual void setOrientation (double roll_deg, double pitch_deg,
71                                double heading_deg);
72
73   virtual ssgEntity * getSceneGraph () const { return (ssgEntity *)_selector; }
74
75   virtual FGLocation * getFGLocation () const { return _location; }
76
77 private:
78
79   class Animation;
80   Animation * make_animation (const char * object_name, SGPropertyNode * node);
81
82                                 // Geodetic position
83   double _lon_deg;
84   double _lat_deg;
85   double _elev_ft;
86
87                                 // Orientation
88   double _roll_deg;
89   double _pitch_deg;
90   double _heading_deg;
91
92                                 // Animations
93   vector <Animation *> _animations;
94
95                                 // Scene graph
96   ssgBranch * _model;
97   ssgSelector * _selector;
98   ssgTransform * _position;
99
100                                 // Location
101   FGLocation * _location;
102
103
104   \f
105   //////////////////////////////////////////////////////////////////////
106   // Internal classes for individual animations.
107   //////////////////////////////////////////////////////////////////////
108
109   /**
110    * Abstract base class for all animations.
111    */
112   class Animation
113   {
114   public:
115
116     Animation ();
117
118     virtual ~Animation ();
119
120     /**
121      * Initialize the animation.
122      *
123      * @param object The object to animate.
124      * @param props The property node with configuration information.
125      */
126     virtual void init (ssgEntity * object, SGPropertyNode * props) = 0;
127
128
129     /**
130      * Update the animation.
131      *
132      * @param dt The elapsed time in milliseconds since the last call.
133      */
134     virtual void update (int dt) = 0;
135
136   };
137
138
139   /**
140    * A no-op animation.
141    */
142   class NullAnimation : public Animation
143   {
144   public:
145     NullAnimation ();
146     virtual ~NullAnimation ();
147     virtual void init (ssgEntity * object, SGPropertyNode * props);
148     virtual void update (int dt);
149   private:
150     ssgBranch * _branch;
151   };
152
153   
154   /**
155    * A range, or level-of-detail (LOD) animation.
156    */
157   class RangeAnimation : public Animation
158   {
159   public:
160     RangeAnimation ();
161     virtual ~RangeAnimation ();
162     virtual void init (ssgEntity * object, SGPropertyNode * props);
163     virtual void update (int dt);
164   private:
165     ssgRangeSelector * _branch;
166   };
167
168
169   /**
170    * Animation to select alternative versions of the same object.
171    */
172   class SelectAnimation : public Animation
173   {
174   public:
175     SelectAnimation ();
176     virtual ~SelectAnimation ();
177     virtual void init (ssgEntity * object, SGPropertyNode * props);
178     virtual void update (int dt);
179   private:
180     FGCondition * _condition;
181     ssgSelector * _selector;
182   };
183
184
185   /**
186    * Animation to spin an object around a center point.
187    *
188    * This animation rotates at a specific velocity.
189    */
190   class SpinAnimation : public Animation
191   {
192   public:
193     SpinAnimation ();
194     virtual ~SpinAnimation ();
195     virtual void init (ssgEntity * object, SGPropertyNode * props);
196     virtual void update (int dt);
197   private:
198     SGPropertyNode * _prop;
199     double _factor;
200     double _position_deg;
201     sgMat4 _matrix;
202     sgVec3 _center;
203     sgVec3 _axis;
204     ssgTransform * _transform;
205   };
206
207
208   /**
209    * Animation to rotate an object around a center point.
210    *
211    * This animation rotates to a specific position.
212    */
213   class RotateAnimation : public Animation
214   {
215   public:
216     RotateAnimation ();
217     virtual ~RotateAnimation ();
218     virtual void init (ssgEntity * object, SGPropertyNode * props);
219     virtual void update (int dt);
220   private:
221     SGPropertyNode * _prop;
222     double _offset_deg;
223     double _factor;
224     SGInterpTable * _table;
225     bool _has_min;
226     double _min_deg;
227     bool _has_max;
228     double _max_deg;
229     double _position_deg;
230     sgMat4 _matrix;
231     sgVec3 _center;
232     sgVec3 _axis;
233     ssgTransform * _transform;
234   };
235
236
237   /**
238    * Animation to slide along an axis.
239    */
240   class TranslateAnimation : public Animation
241   {
242   public:
243     TranslateAnimation ();
244     virtual ~TranslateAnimation ();
245     virtual void init (ssgEntity * object, SGPropertyNode * props);
246     virtual void update (int dt);
247   private:
248     SGPropertyNode * _prop;
249     double _offset_m;
250     double _factor;
251     SGInterpTable * _table;
252     bool _has_min;
253     double _min_m;
254     bool _has_max;
255     double _max_m;
256     double _position_m;
257     sgMat4 _matrix;
258     sgVec3 _axis;
259     ssgTransform * _transform;
260   };
261
262 };
263
264 #endif // __MODEL_HXX
265
266
267