1 // Adapter for interpolating different types of properties.
3 // Copyright (C) 2013 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef SG_PROPERTY_INTERPOLATOR_HXX_
20 #define SG_PROPERTY_INTERPOLATOR_HXX_
22 #include "easing_functions.hxx"
23 #include "propsfwd.hxx"
34 class PropertyInterpolator;
35 typedef SGSharedPtr<PropertyInterpolator> PropertyInterpolatorRef;
38 * Base class for interpolating different types of properties over time.
40 class PropertyInterpolator:
44 virtual ~PropertyInterpolator();
47 * Resets animation timer to zero and prepares for interpolation to new
50 void reset(const SGPropertyNode& target);
53 * Set easing function to be used for interpolation.
55 void setEasingFunction(easing_func_t easing);
58 * Calculate an animation step.
60 * @param prop Property being animated
61 * @param dt Current frame duration
62 * @return Time not used by the animation (>= 0 if animation has finished,
63 * else time is negative indicating the remaining time until
66 double update(SGPropertyNode& prop, double dt);
68 const std::string& getType() const { return _type; }
71 friend class PropertyInterpolationMgr;
74 easing_func_t _easing;
75 PropertyInterpolatorRef _next;
79 PropertyInterpolator();
81 virtual void setTarget(const SGPropertyNode& target) = 0;
82 virtual void init(const SGPropertyNode& prop) = 0;
83 virtual void write(SGPropertyNode& prop, double t) = 0;
86 class NumericInterpolator:
87 public PropertyInterpolator
93 virtual void setTarget(const SGPropertyNode& target);
94 virtual void init(const SGPropertyNode& prop);
95 virtual void write(SGPropertyNode& prop, double t);
98 } // namespace simgear
101 #endif /* SG_PROPERTY_INTERPOLATOR_HXX_ */