2.8 branch: backport of osgAnimation from svn head 11026.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* -*-c++-*-
|
||||
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net>
|
||||
* Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
@@ -10,13 +10,16 @@
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
*
|
||||
* Authors:
|
||||
* Cedric Pinson <cedric.pinson@plopbyte.net>
|
||||
* Michael Platings <mplatings@pixelpower.com>
|
||||
*/
|
||||
|
||||
#ifndef OSGANIMATION_INTERPOLATOR_H
|
||||
#define OSGANIMATION_INTERPOLATOR_H
|
||||
#ifndef OSGANIMATION_INTERPOLATOR
|
||||
#define OSGANIMATION_INTERPOLATOR 1
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osgAnimation/Interpolator>
|
||||
#include <osgAnimation/Keyframe>
|
||||
|
||||
namespace osgAnimation
|
||||
@@ -61,6 +64,32 @@ namespace osgAnimation
|
||||
};
|
||||
|
||||
|
||||
template <class TYPE, class KEY=TYPE>
|
||||
class TemplateStepInterpolator : public TemplateInterpolatorBase<TYPE,KEY>
|
||||
{
|
||||
public:
|
||||
|
||||
TemplateStepInterpolator() {}
|
||||
void getValue(const TemplateKeyframeContainer<KEY>& keyframes, float time, TYPE& result) const
|
||||
{
|
||||
|
||||
if (time >= keyframes.back().getTime())
|
||||
{
|
||||
result = keyframes.back().getValue();
|
||||
return;
|
||||
}
|
||||
else if (time <= keyframes.front().getTime())
|
||||
{
|
||||
result = keyframes.front().getValue();
|
||||
return;
|
||||
}
|
||||
|
||||
int i = getKeyIndexFromTime(keyframes,time);
|
||||
result = keyframes[i].getValue();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class TYPE, class KEY=TYPE>
|
||||
class TemplateLinearInterpolator : public TemplateInterpolatorBase<TYPE,KEY>
|
||||
{
|
||||
@@ -176,14 +205,22 @@ namespace osgAnimation
|
||||
float t2 = t * t;
|
||||
|
||||
TYPE v0 = keyframes[i].getValue().getPosition() * one_minus_t3;
|
||||
TYPE v1 = keyframes[i].getValue().getTangentPoint1() * (3.0 * t * one_minus_t2);
|
||||
TYPE v2 = keyframes[i].getValue().getTangentPoint2() * (3.0 * t2 * one_minus_t);
|
||||
TYPE v1 = keyframes[i].getValue().getControlPointIn() * (3.0 * t * one_minus_t2);
|
||||
TYPE v2 = keyframes[i].getValue().getControlPointOut() * (3.0 * t2 * one_minus_t);
|
||||
TYPE v3 = keyframes[i+1].getValue().getPosition() * (t2 * t);
|
||||
|
||||
result = v0 + v1 + v2 + v3;
|
||||
}
|
||||
};
|
||||
|
||||
typedef TemplateStepInterpolator<double, double> DoubleStepInterpolator;
|
||||
typedef TemplateStepInterpolator<float, float> FloatStepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec2, osg::Vec2> Vec2StepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec3, osg::Vec3> Vec3StepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec3, Vec3Packed> Vec3PackedStepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Vec4, osg::Vec4> Vec4StepInterpolator;
|
||||
typedef TemplateStepInterpolator<osg::Quat, osg::Quat> QuatStepInterpolator;
|
||||
|
||||
typedef TemplateLinearInterpolator<double, double> DoubleLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<float, float> FloatLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<osg::Vec2, osg::Vec2> Vec2LinearInterpolator;
|
||||
@@ -191,6 +228,7 @@ namespace osgAnimation
|
||||
typedef TemplateLinearInterpolator<osg::Vec3, Vec3Packed> Vec3PackedLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<osg::Vec4, osg::Vec4> Vec4LinearInterpolator;
|
||||
typedef TemplateSphericalLinearInterpolator<osg::Quat, osg::Quat> QuatSphericalLinearInterpolator;
|
||||
typedef TemplateLinearInterpolator<osg::Matrixf, osg::Matrixf> MatrixLinearInterpolator;
|
||||
|
||||
typedef TemplateCubicBezierInterpolator<float, FloatCubicBezier > FloatCubicBezierInterpolator;
|
||||
typedef TemplateCubicBezierInterpolator<double, DoubleCubicBezier> DoubleCubicBezierInterpolator;
|
||||
|
||||
Reference in New Issue
Block a user