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