]> git.mxchange.org Git - flightgear.git/blob - src/Model/model.hxx
Added support for additional animated, dynamic 3D models configured in
[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 setLongitudeDeg (double lon_deg);
47   virtual void setLatitudeDeg (double lat_deg);
48   virtual void setElevationFt (double elev_ft);
49   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
50
51   virtual double getRollDeg () const { return _roll_deg; }
52   virtual double getPitchDeg () const { return _pitch_deg; }
53   virtual double getHeadingDeg () const { return _heading_deg; }
54
55   virtual void setRollDeg (double roll_deg);
56   virtual void setPitchDeg (double pitch_deg);
57   virtual void setHeadingDeg (double heading_deg);
58   virtual void setOrientation (double roll_deg, double pitch_deg,
59                                double heading_deg);
60
61   virtual ssgEntity * getSceneGraph () const { return _selector; }
62
63   virtual FGLocation * getFGLocation () const { return _location; }
64
65 private:
66
67   class Animation;
68   Animation * make_animation (const char * object_name, SGPropertyNode * node);
69
70                                 // Geodetic position
71   double _lon_deg;
72   double _lat_deg;
73   double _elev_ft;
74
75                                 // Orientation
76   double _roll_deg;
77   double _pitch_deg;
78   double _heading_deg;
79
80                                 // Animations
81
82   vector <Animation *> _animations;
83
84
85                                 // Scene graph
86   ssgEntity * _model;
87   ssgSelector * _selector;
88   ssgTransform * _position;
89
90                                 // Location
91   FGLocation * _location;
92
93   \f
94   //////////////////////////////////////////////////////////////////////
95   // Internal classes for individual animations.
96   //////////////////////////////////////////////////////////////////////
97
98   /**
99    * Abstract base class for all animations.
100    */
101   class Animation
102   {
103   public:
104
105     Animation ();
106
107     virtual ~Animation ();
108
109     /**
110      * Initialize the animation.
111      *
112      * @param object The object to animate.
113      * @param props The property node with configuration information.
114      */
115     virtual void init (ssgEntity * object, SGPropertyNode * props) = 0;
116
117
118     /**
119      * Update the animation.
120      *
121      * @param dt The elapsed time in milliseconds since the last call.
122      */
123     virtual void update (int dt) = 0;
124
125   };
126
127
128   /**
129    * A no-op animation.
130    */
131   class NullAnimation : public Animation
132   {
133   public:
134     NullAnimation ();
135     virtual ~NullAnimation ();
136     virtual void init (ssgEntity * object, SGPropertyNode * props);
137     virtual void update (int dt);
138   private:
139     ssgBranch * _branch;
140   };
141
142
143   /**
144    * Animation to select alternative versions of the same object.
145    */
146   class SelectAnimation : public Animation
147   {
148   public:
149     SelectAnimation ();
150     virtual ~SelectAnimation ();
151     virtual void init (ssgEntity * object, SGPropertyNode * props);
152     virtual void update (int dt);
153   private:
154     FGCondition * _condition;
155     ssgSelector * _selector;
156   };
157
158
159   /**
160    * Animation to spin an object around a center point.
161    *
162    * This animation rotates at a specific velocity.
163    */
164   class SpinAnimation : public Animation
165   {
166   public:
167     SpinAnimation ();
168     virtual ~SpinAnimation ();
169     virtual void init (ssgEntity * object, SGPropertyNode * props);
170     virtual void update (int dt);
171   private:
172     SGPropertyNode * _prop;
173     double _factor;
174     double _position_deg;
175     sgMat4 _matrix;
176     sgVec3 _center;
177     sgVec3 _axis;
178     ssgTransform * _transform;
179   };
180
181
182   /**
183    * Animation to rotate an object around a center point.
184    *
185    * This animation rotates to a specific position.
186    */
187   class RotateAnimation : public Animation
188   {
189   public:
190     RotateAnimation ();
191     virtual ~RotateAnimation ();
192     virtual void init (ssgEntity * object, SGPropertyNode * props);
193     virtual void update (int dt);
194   private:
195     SGPropertyNode * _prop;
196     double _offset_deg;
197     double _factor;
198     bool _has_min;
199     double _min_deg;
200     bool _has_max;
201     double _max_deg;
202     double _position_deg;
203     sgMat4 _matrix;
204     sgVec3 _center;
205     sgVec3 _axis;
206     ssgTransform * _transform;
207   };
208
209
210   /**
211    * Animation to slide along an axis.
212    */
213   class TranslateAnimation : public Animation
214   {
215   public:
216     TranslateAnimation ();
217     virtual ~TranslateAnimation ();
218     virtual void init (ssgEntity * object, SGPropertyNode * props);
219     virtual void update (int dt);
220   private:
221     SGPropertyNode * _prop;
222     double _offset_m;
223     double _factor;
224     bool _has_min;
225     double _min_m;
226     bool _has_max;
227     double _max_m;
228     double _position_m;
229     sgMat4 _matrix;
230     sgVec3 _axis;
231     ssgTransform * _transform;
232   };
233
234 };
235
236 #endif // __MODEL_HXX
237
238
239