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 General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <simgear/props/props.hxx>
27 #include <simgear/structure/subsystem_mgr.hxx>
29 // TODO: support a callback upon interpolation completion so that user
30 // code can register another one immediately without worrying about
33 class SGInterpolator : public SGSubsystem {
35 SGInterpolator() { _list = 0; }
36 virtual void init() {}
37 virtual void update(double delta_time_sec);
39 // Simple method that interpolates a double property value from
40 // its current value (default of zero) to the specified target
41 // over the specified time.
42 void interpolate(SGPropertyNode* prop, double value, double dt_sec);
44 // More elaborate version that takes a pointer to lists of
46 void interpolate(SGPropertyNode* prop, int nPoints,
47 double* values, double* deltas);
49 // Cancels any interpolation of the specified property, leaving
50 // its value at the current (mid-interpolation) state.
51 void cancel(SGPropertyNode* prop);
55 SGPropertyNode_ptr target;
57 double* curve; // time0, val0, time1, val1, ...
60 ~Interp() { delete[] curve; }
61 double& dt(int i) { return curve[2*i]; }
62 double& val(int i) { return curve[2*i + 1]; }
66 bool interp(Interp* rec, double dt);
67 void addNew(SGPropertyNode* prop, int nPoints);
70 #endif // __SG_INTERPOLATOR_HXX