From Michael Platings,

Changes to allow osgAnimation::*CubicBezierChannel to be used
Added TemplateStepInterpolator class
This commit is contained in:
Cedric Pinson 2009-08-06 12:40:06 +00:00
parent 38c36f0158
commit 2916d9b7ea
5 changed files with 92 additions and 52 deletions

View File

@ -10,7 +10,11 @@
* 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_BONE_H
#define OSGANIMATION_BONE_H
@ -129,30 +133,15 @@ namespace osgAnimation
{
if (channel->getName().find("quaternion") != std::string::npos)
{
osgAnimation::QuatSphericalLinearChannel* qc = dynamic_cast<osgAnimation::QuatSphericalLinearChannel*>(channel);
if (qc)
{
qc->setTarget(_quaternion.get());
return true;
}
return channel->setTarget(_quaternion.get());
}
else if (channel->getName().find("position") != std::string::npos)
{
osgAnimation::Vec3LinearChannel* vc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
if (vc)
{
vc->setTarget(_position.get());
return true;
}
return channel->setTarget(_position.get());
}
else if (channel->getName().find("scale") != std::string::npos)
{
osgAnimation::Vec3LinearChannel* vc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
if (vc)
{
vc->setTarget(_scale.get());
return true;
}
return channel->setTarget(_scale.get());
}
else
{

View File

@ -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,7 +10,11 @@
* 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_CHANNEL_H
#define OSGANIMATION_CHANNEL_H
@ -36,6 +40,7 @@ namespace osgAnimation
virtual void update(float time) = 0;
virtual void reset() = 0;
virtual Target* getTarget() = 0;
virtual bool setTarget(Target*) = 0;
const std::string& getName() const;
void setName(const std::string& name);
@ -98,6 +103,11 @@ namespace osgAnimation
}
virtual void reset() { _target->reset(); }
virtual Target* getTarget() { return _target.get();}
virtual bool setTarget(Target* target)
{
_target = dynamic_cast<TargetType*>(target);
return _target.get() == target;
}
SamplerType* getOrCreateSampler()
{
@ -126,9 +136,16 @@ namespace osgAnimation
typedef std::vector<osg::ref_ptr<osgAnimation::Channel> > ChannelList;
typedef TemplateChannel<DoubleStepSampler> DoubleStepChannel;
typedef TemplateChannel<FloatStepSampler> FloatStepChannel;
typedef TemplateChannel<Vec2StepSampler> Vec2StepChannel;
typedef TemplateChannel<Vec3StepSampler> Vec3StepChannel;
typedef TemplateChannel<Vec4StepSampler> Vec4StepChannel;
typedef TemplateChannel<QuatStepSampler> QuatStepChannel;
typedef TemplateChannel<DoubleLinearSampler> DoubleLinearChannel;
typedef TemplateChannel<FloatLinearSampler> FloatLinearChannel;
typedef TemplateChannel<Vec2LinearSampler> Vec2LinearChannel;
typedef TemplateChannel<Vec3LinearSampler> Vec3LinearChannel;
typedef TemplateChannel<Vec4LinearSampler> Vec4LinearChannel;

View File

@ -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,7 +10,11 @@
* 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
@ -61,6 +65,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);
return keyframes[i].getValue();
}
};
template <class TYPE, class KEY=TYPE>
class TemplateLinearInterpolator : public TemplateInterpolatorBase<TYPE,KEY>
{
@ -184,6 +214,14 @@ namespace osgAnimation
}
};
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;

View File

@ -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,7 +10,11 @@
* 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_SAMPLER_H
#define OSGANIMATION_SAMPLER_H
@ -108,12 +112,20 @@ namespace osgAnimation
};
typedef TemplateSampler<DoubleStepInterpolator> DoubleStepSampler;
typedef TemplateSampler<FloatStepInterpolator> FloatStepSampler;
typedef TemplateSampler<Vec2StepInterpolator> Vec2StepSampler;
typedef TemplateSampler<Vec3StepInterpolator> Vec3StepSampler;
typedef TemplateSampler<Vec4StepInterpolator> Vec4StepSampler;
typedef TemplateSampler<QuatStepInterpolator> QuatStepSampler;
typedef TemplateSampler<DoubleLinearInterpolator> DoubleLinearSampler;
typedef TemplateSampler<FloatLinearInterpolator> FloatLinearSampler;
typedef TemplateSampler<Vec2LinearInterpolator> Vec2LinearSampler;
typedef TemplateSampler<Vec3LinearInterpolator> Vec3LinearSampler;
typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler;
typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler;
typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler;
typedef TemplateSampler<DoubleCubicBezierInterpolator> DoubleCubicBezierSampler;
typedef TemplateSampler<Vec2CubicBezierInterpolator> Vec2CubicBezierSampler;

View File

@ -10,7 +10,11 @@
* 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>
*/
#include <osgAnimation/UpdateCallback>
#include <osg/MatrixTransform>
@ -95,30 +99,15 @@ bool UpdateTransform::link(osgAnimation::Channel* channel)
{
if (channel->getName().find("euler") != std::string::npos)
{
osgAnimation::Vec3LinearChannel* qc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
if (qc)
{
qc->setTarget(_euler.get());
return true;
}
return channel->setTarget(_euler.get());
}
else if (channel->getName().find("position") != std::string::npos)
{
osgAnimation::Vec3LinearChannel* vc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
if (vc)
{
vc->setTarget(_position.get());
return true;
}
return channel->setTarget(_position.get());
}
else if (channel->getName().find("scale") != std::string::npos)
{
osgAnimation::Vec3LinearChannel* vc = dynamic_cast<osgAnimation::Vec3LinearChannel*>(channel);
if (vc)
{
vc->setTarget(_scale.get());
return true;
}
return channel->setTarget(_scale.get());
}
else
{
@ -171,12 +160,7 @@ bool UpdateMaterial::link(osgAnimation::Channel* channel)
{
if (channel->getName().find("diffuse") != std::string::npos)
{
osgAnimation::Vec4LinearChannel* d = dynamic_cast<osgAnimation::Vec4LinearChannel*>(channel);
if (d)
{
d->setTarget(_diffuse.get());
return true;
}
return channel->setTarget(_diffuse.get());
}
else
{