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