1 #ifndef __SG_INTERPOLATOR_HXX
2 #define __SG_INTERPOLATOR_HXX
5 // Subsystem that manages smooth linear interpolation of property
6 // values across multiple data points and arbitrary time intervals.
8 // Written by Andrew J. Ross, started December 2003
10 // Copyright (C) 2003 Andrew J. Ross - andy@plausible.org
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Library General Public
14 // License as published by the Free Software Foundation; either
15 // version 2 of the License, or (at your option) any later version.
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Library General Public License for more details.
22 // You should have received a copy of the GNU Library General Public
23 // License along with this library; if not, write to the
24 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 // Boston, MA 02111-1307, USA.
27 #include <simgear/props/props.hxx>
28 #include <simgear/structure/subsystem_mgr.hxx>
30 // TODO: support a callback upon interpolation completion so that user
31 // code can register another one immediately without worrying about
34 class SGInterpolator : public SGSubsystem {
36 SGInterpolator() { _list = 0; }
37 virtual void init() {}
38 virtual void update(double delta_time_sec);
40 // Simple method that interpolates a double property value from
41 // its current value (default of zero) to the specified target
42 // over the specified time.
43 void interpolate(SGPropertyNode* prop, double value, double dt_sec);
45 // More elaborate version that takes a pointer to lists of
47 void interpolate(SGPropertyNode* prop, int nPoints,
48 double* values, double* deltas);
50 // Cancels any interpolation of the specified property, leaving
51 // its value at the current (mid-interpolation) state.
52 void cancel(SGPropertyNode* prop);
56 SGPropertyNode_ptr target;
58 double* curve; // time0, val0, time1, val1, ...
61 ~Interp() { delete[] curve; }
62 double& dt(int i) { return curve[2*i]; }
63 double& val(int i) { return curve[2*i + 1]; }
67 bool interp(Interp* rec, double dt);
68 void addNew(SGPropertyNode* prop, int nPoints);
71 #endif // __SG_INTERPOLATOR_HXX