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 * Create new animation for given property.
73 * @param prop Property to be animated
74 * @param target Property containing target value
76 template<class Derived>
77 static PropertyInterpolator* create(const SGPropertyNode* target)
81 PropertyInterpolator* interp = new Derived;
82 interp->reset(target);
88 friend class PropertyInterpolationMgr;
91 easing_func_t _easing;
92 PropertyInterpolatorRef _next;
96 PropertyInterpolator();
98 virtual void setTarget(const SGPropertyNode* target) = 0;
99 virtual void init(const SGPropertyNode* prop) = 0;
100 virtual void write(SGPropertyNode* prop, double t) = 0;
103 class NumericInterpolator:
104 public PropertyInterpolator
110 virtual void setTarget(const SGPropertyNode* target);
111 virtual void init(const SGPropertyNode* prop);
112 virtual void write(SGPropertyNode* prop, double t);
115 } // namespace simgear
118 #endif /* SG_PROPERTY_INTERPOLATOR_HXX_ */