openscenegraph
LinearInterpolator
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_LINEARINTERPOLATOR
16#define OSGPARTICLE_LINEARINTERPOLATOR
17
18#include <osgParticle/Interpolator>
19
20#include <osg/CopyOp>
21#include <osg/Object>
22#include <osg/Vec3>
23#include <osg/Vec4>
24
25namespace osgParticle
26{
27
28 /// A linear interpolator.
29 class LinearInterpolator: public Interpolator
30 {
31 public:
32 LinearInterpolator()
33 : Interpolator() {}
34
35 LinearInterpolator(const LinearInterpolator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY)
36 : Interpolator(copy, copyop) {}
37
38 META_Object(osgParticle, LinearInterpolator);
39
40 virtual float interpolate(float t, float y1, float y2) const
41 {
42 return y1 + (y2 - y1) * t;
43 }
44
45 virtual osg::Vec2 interpolate(float t, const osg::Vec2& y1, const osg::Vec2& y2) const
46 {
47 return y1 + (y2 - y1) * t;
48 }
49
50 virtual osg::Vec3 interpolate(float t, const osg::Vec3& y1, const osg::Vec3& y2) const
51 {
52 return y1 + (y2 - y1) * t;
53 }
54
55 virtual osg::Vec4 interpolate(float t, const osg::Vec4& y1, const osg::Vec4& y2) const
56 {
57 return y1 + (y2 - y1) * t;
58 }
59
60 protected:
61 virtual ~LinearInterpolator() {}
62 };
63
64}
65
66#endif