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