1 // model.hxx - manage a 3D aircraft model.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain, and comes with no warranty.
10 # error This library requires C++
20 #include <simgear/math/point3d.hxx>
21 #include <simgear/props/props.hxx>
24 // Don't pull in the headers, since we don't need them here.
28 class ssgRangeSelector;
37 // Has anyone done anything *really* stupid, like making min and max macros?
47 * Load a 3D model with or without XML wrapper.
49 * If the path ends in ".xml", then it will be used as a property-
50 * list wrapper to add animations to the model.
52 * Subsystems should not normally invoke this function directly;
53 * instead, they should use the FGModelLoader declared in loader.hxx.
55 ssgBranch * fgLoad3DModel( const string& fg_root, const string &path,
56 SGPropertyNode *prop_root, double sim_time_sec );
60 //////////////////////////////////////////////////////////////////////
62 //////////////////////////////////////////////////////////////////////
65 * Abstract base class for all animations.
67 class Animation : public ssgBase
71 Animation (SGPropertyNode_ptr props, ssgBranch * branch);
73 virtual ~Animation ();
76 * Get the SSG branch holding the animation.
78 virtual ssgBranch * getBranch () { return _branch; }
81 * Initialize the animation, after children have been added.
86 * Update the animation.
88 virtual void update();
91 * Set the value of sim_time_sec. This needs to be called every
92 * frame in order for the time based animations to work correctly.
94 static void set_sim_time_sec( double val ) { sim_time_sec = val; }
98 static double sim_time_sec;
108 class NullAnimation : public Animation
111 NullAnimation (SGPropertyNode_ptr props);
112 virtual ~NullAnimation ();
117 * A range, or level-of-detail (LOD) animation.
119 class RangeAnimation : public Animation
122 RangeAnimation (SGPropertyNode_ptr props);
123 virtual ~RangeAnimation ();
128 * Animation to turn and face the screen.
130 class BillboardAnimation : public Animation
133 BillboardAnimation (SGPropertyNode_ptr props);
134 virtual ~BillboardAnimation ();
139 * Animation to select alternative versions of the same object.
141 class SelectAnimation : public Animation
144 SelectAnimation( SGPropertyNode *prop_root,
145 SGPropertyNode_ptr props );
146 virtual ~SelectAnimation ();
147 virtual void update();
149 FGCondition * _condition;
154 * Animation to spin an object around a center point.
156 * This animation rotates at a specific velocity.
158 class SpinAnimation : public Animation
161 SpinAnimation( SGPropertyNode *prop_root,
162 SGPropertyNode_ptr props,
163 double sim_time_sec );
164 virtual ~SpinAnimation ();
165 virtual void update();
167 SGPropertyNode_ptr _prop;
169 double _position_deg;
170 double _last_time_sec;
178 * Animation to draw objects for a specific amount of time each.
180 class TimedAnimation : public Animation
183 TimedAnimation (SGPropertyNode_ptr props);
184 virtual ~TimedAnimation ();
185 virtual void update();
187 double _duration_sec;
188 double _last_time_sec;
194 * Animation to rotate an object around a center point.
196 * This animation rotates to a specific position.
198 class RotateAnimation : public Animation
201 RotateAnimation( SGPropertyNode *prop_root, SGPropertyNode_ptr props );
202 virtual ~RotateAnimation ();
203 virtual void update();
205 SGPropertyNode_ptr _prop;
208 SGInterpTable * _table;
213 double _position_deg;
221 * Animation to slide along an axis.
223 class TranslateAnimation : public Animation
226 TranslateAnimation( SGPropertyNode *prop_root,
227 SGPropertyNode_ptr props );
228 virtual ~TranslateAnimation ();
229 virtual void update();
231 SGPropertyNode_ptr _prop;
234 SGInterpTable * _table;
246 ////////////////////////////////////////////////////////////////////////
248 ////////////////////////////////////////////////////////////////////////
251 * A wrapper for a model with a definite placement.
253 class FGModelPlacement
258 virtual ~FGModelPlacement ();
260 virtual void init( const string &fg_root,
262 SGPropertyNode *prop_root,
263 double sim_time_sec );
264 virtual void update( const Point3D scenery_center );
266 virtual ssgEntity * getSceneGraph () { return (ssgEntity *)_selector; }
268 virtual FGLocation * getFGLocation () { return _location; }
270 virtual bool getVisible () const;
271 virtual void setVisible (bool visible);
273 virtual double getLongitudeDeg () const { return _lon_deg; }
274 virtual double getLatitudeDeg () const { return _lat_deg; }
275 virtual double getElevationFt () const { return _elev_ft; }
277 virtual void setLongitudeDeg (double lon_deg);
278 virtual void setLatitudeDeg (double lat_deg);
279 virtual void setElevationFt (double elev_ft);
280 virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
282 virtual double getRollDeg () const { return _roll_deg; }
283 virtual double getPitchDeg () const { return _pitch_deg; }
284 virtual double getHeadingDeg () const { return _heading_deg; }
286 virtual void setRollDeg (double roll_deg);
287 virtual void setPitchDeg (double pitch_deg);
288 virtual void setHeadingDeg (double heading_deg);
289 virtual void setOrientation (double roll_deg, double pitch_deg,
292 // Addition by Diarmuid Tyson for Multiplayer Support
293 // Allows multiplayer to get players position transform
294 virtual const sgVec4 *get_POS() { return POS; }
308 ssgSelector * _selector;
309 ssgTransform * _position;
312 FGLocation * _location;
315 // Addition by Diarmuid Tyson for Multiplayer Support
316 // Moved from update method
317 // POS for transformation Matrix
322 #endif // __MODEL_HXX