OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interpolator.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 //osgParticle - Copyright (C) 2002 Marco Jez
14 
15 #ifndef OSGPARTICLE_INTERPOLATOR
16 #define OSGPARTICLE_INTERPOLATOR
17 
18 #include <osgParticle/range>
19 
20 #include <osg/CopyOp>
21 #include <osg/Object>
22 #include <osg/Vec2>
23 #include <osg/Vec3>
24 #include <osg/Vec4>
25 
26 namespace osgParticle
27 {
28 
30  class Interpolator : public osg::Object {
31  public:
33  : osg::Object() {}
34 
36  : osg::Object(copy, copyop) {}
37 
38  virtual const char* libraryName() const { return "osgParticle"; }
39  virtual const char* className() const { return "Interpolator"; }
40  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Interpolator* >(obj) != 0; }
41 
43  virtual float interpolate(float t, float y1, float y2) const = 0;
44 
46  virtual osg::Vec2 interpolate(float t, const osg::Vec2& y1, const osg::Vec2& y2) const
47  {
48  return osg::Vec2(
49  interpolate(t, y1.x(), y2.x()),
50  interpolate(t, y1.y(), y2.y())
51  );
52  }
53 
55  virtual osg::Vec3 interpolate(float t, const osg::Vec3& y1, const osg::Vec3& y2) const
56  {
57  return osg::Vec3(
58  interpolate(t, y1.x(), y2.x()),
59  interpolate(t, y1.y(), y2.y()),
60  interpolate(t, y1.z(), y2.z())
61  );
62  }
63 
65  virtual osg::Vec4 interpolate(float t, const osg::Vec4& y1, const osg::Vec4& y2) const
66  {
67  return osg::Vec4(
68  interpolate(t, y1.x(), y2.x()),
69  interpolate(t, y1.y(), y2.y()),
70  interpolate(t, y1.z(), y2.z()),
71  interpolate(t, y1.w(), y2.w())
72  );
73  }
74 
75  template<class ValueType>
76  ValueType interpolate(float t, const range<ValueType>& r) const
77  {
78  return interpolate(t, r.minimum, r.maximum);
79  }
80 
81  protected:
82  virtual ~Interpolator() {}
83  };
84 
85 }
86 
87 #endif
An abstract base class for implementing interpolators.
Definition: Interpolator.h:30
value_type & y()
Definition: Vec2f.h:68
value_type & x()
Definition: Vec3f.h:80
value_type & z()
Definition: Vec3f.h:82
ValueType maximum
Higher bound.
Definition: range.h:45
virtual float interpolate(float t, float y1, float y2) const =0
Interpolate between floats. Must be overriden in descendant classes.
Vec4f Vec4
Definition: Vec4.h:21
value_type & x()
Definition: Vec2f.h:67
value_type & y()
Definition: Vec4f.h:88
Vec2f Vec2
Definition: Vec2.h:21
ValueType interpolate(float t, const range< ValueType > &r) const
Definition: Interpolator.h:76
Vec3f Vec3
Definition: Vec3.h:21
Object()
Definition: Object.h:65
Interpolator(const Interpolator &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Interpolator.h:35
virtual const char * className() const
Definition: Interpolator.h:39
value_type & y()
Definition: Vec3f.h:81
virtual osg::Vec4 interpolate(float t, const osg::Vec4 &y1, const osg::Vec4 &y2) const
Interpolate between 4-dimensional vectors. Default behavior is to interpolate each component separate...
Definition: Interpolator.h:65
virtual const char * libraryName() const
Definition: Interpolator.h:38
value_type & w()
Definition: Vec4f.h:90
Definition: AlphaFunc.h:19
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: Interpolator.h:40
value_type & z()
Definition: Vec4f.h:89
ValueType minimum
Lower bound.
Definition: range.h:42
value_type & x()
Definition: Vec4f.h:87
virtual osg::Vec3 interpolate(float t, const osg::Vec3 &y1, const osg::Vec3 &y2) const
Interpolate between 3-dimensional vectors. Default behavior is to interpolate each component separate...
Definition: Interpolator.h:55
virtual osg::Vec2 interpolate(float t, const osg::Vec2 &y1, const osg::Vec2 &y2) const
Interpolate between 2-dimensional vectors. Default behavior is to interpolate each component separate...
Definition: Interpolator.h:46