]> git.mxchange.org Git - flightgear.git/blob - src/Main/model.hxx
Initial revision.
[flightgear.git] / src / Main / 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 <string>
14 #include <vector>
15
16 SG_USING_STD(string);
17 SG_USING_STD(vector);
18
19 #include "fgfs.hxx"
20 #include <simgear/misc/props.hxx>
21 #include <simgear/timing/timestamp.hxx>
22
23 // Has anyone done anything *really* stupid, like making min and max macros?
24 #ifdef min
25 #undef min
26 #endif
27 #ifdef max
28 #undef max
29 #endif
30
31 class FGAircraftModel : public FGSubsystem
32 {
33 public:
34
35   FGAircraftModel ();
36   virtual ~FGAircraftModel ();
37
38   virtual void init ();
39   virtual void bind ();
40   virtual void unbind ();
41   virtual void update (int dt);
42
43 private:
44
45   class Animation;
46
47   Animation * make_animation (const char * object_name, SGPropertyNode * node);
48
49   ssgEntity * _model;
50   ssgSelector * _selector;
51   ssgTransform * _position;
52
53   vector <Animation *> _animations;
54
55
56   \f
57   //////////////////////////////////////////////////////////////////////
58   // Internal classes for individual animations.
59   //////////////////////////////////////////////////////////////////////
60
61   /**
62    * Abstract base class for all animations.
63    */
64   class Animation
65   {
66   public:
67
68     Animation ();
69
70     virtual ~Animation ();
71
72     /**
73      * Initialize the animation.
74      *
75      * @param object The object to animate.
76      * @param props The property node with configuration information.
77      */
78     virtual void init (ssgEntity * object, SGPropertyNode * props) = 0;
79
80
81     /**
82      * Update the animation.
83      *
84      * @param dt The elapsed time in milliseconds since the last call.
85      */
86     virtual void update (int dt) = 0;
87
88   };
89
90
91   /**
92    * A no-op animation.
93    */
94   class NullAnimation : public Animation
95   {
96   public:
97     NullAnimation ();
98     virtual ~NullAnimation ();
99     virtual void init (ssgEntity * object, SGPropertyNode * props);
100     virtual void update (int dt);
101   private:
102     ssgBranch * _branch;
103   };
104
105
106   /**
107    * Animation to select alternative versions of the same object.
108    */
109   class SelectAnimation : public Animation
110   {
111   public:
112     SelectAnimation ();
113     virtual ~SelectAnimation ();
114     virtual void init (ssgEntity * object, SGPropertyNode * props);
115     virtual void update (int dt);
116   private:
117     FGCondition * _condition;
118     ssgSelector * _selector;
119   };
120
121
122   /**
123    * Animation to spin an object around a center point.
124    *
125    * This animation rotates at a specific velocity.
126    */
127   class SpinAnimation : public Animation
128   {
129   public:
130     SpinAnimation ();
131     virtual ~SpinAnimation ();
132     virtual void init (ssgEntity * object, SGPropertyNode * props);
133     virtual void update (int dt);
134   private:
135     SGPropertyNode * _prop;
136     double _factor;
137     double _position_deg;
138     sgMat4 _matrix;
139     sgVec3 _center;
140     sgVec3 _axis;
141     ssgTransform * _transform;
142   };
143
144
145   /**
146    * Animation to rotate an object around a center point.
147    *
148    * This animation rotates to a specific position.
149    */
150   class RotateAnimation : public Animation
151   {
152   public:
153     RotateAnimation ();
154     virtual ~RotateAnimation ();
155     virtual void init (ssgEntity * object, SGPropertyNode * props);
156     virtual void update (int dt);
157   private:
158     SGPropertyNode * _prop;
159     double _offset_deg;
160     double _factor;
161     bool _has_min;
162     double _min_deg;
163     bool _has_max;
164     double _max_deg;
165     double _position_deg;
166     sgMat4 _matrix;
167     sgVec3 _center;
168     sgVec3 _axis;
169     ssgTransform * _transform;
170   };
171
172
173   /**
174    * Animation to slide along an axis.
175    */
176   class TranslateAnimation : public Animation
177   {
178   public:
179     TranslateAnimation ();
180     virtual ~TranslateAnimation ();
181     virtual void init (ssgEntity * object, SGPropertyNode * props);
182     virtual void update (int dt);
183   private:
184     SGPropertyNode * _prop;
185     double _offset_m;
186     double _factor;
187     bool _has_min;
188     double _min_m;
189     bool _has_max;
190     double _max_m;
191     double _position_m;
192     sgMat4 _matrix;
193     sgVec3 _axis;
194     ssgTransform * _transform;
195   };
196
197 };
198
199 extern FGAircraftModel current_model;
200
201 #endif // __MODEL_HXX
202