Channel
Go to the documentation of this file.
/* -*-c++-*-
* 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
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* 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
#define OSGANIMATION_CHANNEL 1
#include <osgAnimation/Export>
#include <osgAnimation/Sampler>
#include <osgAnimation/Target>
#include <osg/Referenced>
#include <string>
namespace osgAnimation
{
class OSGANIMATION_EXPORT Channel : public osg::Object
{
public:
Channel();
Channel(const Channel& channel);
virtual ~Channel();
virtual Channel* clone() const = 0;
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Channel*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osgAnimation"; }
virtual const char* className() const { return "Channel"; }
virtual void update(double time, float weight, int priority) = 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);
virtual double getStartTime() const = 0;
virtual double getEndTime() const = 0;
const std::string& getTargetName() const;
void setTargetName(const std::string& name);
virtual Sampler* getSampler() = 0;
virtual const Sampler* getSampler() const = 0;
// create a keyframe container from current target value
// with one key only, can be used for debug or to create
// easily a default channel from an existing one
virtual bool createKeyframeContainerFromTargetValue() = 0;
protected:
std::string _targetName;
std::string _name;
};
template <typename SamplerType>
class TemplateChannel : public Channel
{
public:
typedef typename SamplerType::UsingType UsingType;
typedef TemplateTarget<UsingType> TargetType;
typedef TemplateKeyframeContainer<typename SamplerType::KeyframeType> KeyframeContainerType;
Object* cloneType() const { return new TemplateChannel(); }
Object* clone(const osg::CopyOp&) const { return new TemplateChannel<SamplerType>(*this); }
Channel* clone() const { return new TemplateChannel<SamplerType>(*this); }
TemplateChannel (const TemplateChannel& channel) :
Channel(channel)
{
if (channel.getTargetTyped())
_target = new TargetType(*channel.getTargetTyped());
if (channel.getSamplerTyped())
_sampler = new SamplerType(*channel.getSamplerTyped());
}
TemplateChannel (SamplerType* s = 0,TargetType* target = 0)
{
if (target)
_target = target;
else
_target = new TargetType;
_sampler = s;
}
virtual bool createKeyframeContainerFromTargetValue()
{
if (!_target.valid()) // no target it does not make sense to do it
{
return false;
}
// create a key from current target value
typename KeyframeContainerType::KeyType key(0, _target->getValue());
// recreate the keyframe container
getOrCreateSampler()->setKeyframeContainer(0);
getOrCreateSampler()->getOrCreateKeyframeContainer();
// add the key
_sampler->getKeyframeContainerTyped()->push_back(key);
return true;
}
virtual ~TemplateChannel() {}
virtual void update(double time, float weight, int priority)
{
// skip if weight == 0
if (weight < 1e-4)
return;
typename SamplerType::UsingType value;
_sampler->getValueAt(time, value);
_target->update(weight, value, priority);
}
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()
{
if (!_sampler.valid())
_sampler = new SamplerType;
return _sampler.get();
}
Sampler* getSampler() { return _sampler.get(); }
const Sampler* getSampler() const { return _sampler.get(); }
SamplerType* getSamplerTyped() { return _sampler.get();}
const SamplerType* getSamplerTyped() const { return _sampler.get();}
void setSampler(SamplerType* sampler) { _sampler = sampler; }
TargetType* getTargetTyped() { return _target.get(); }
const TargetType* getTargetTyped() const { return _target.get(); }
void setTarget(TargetType* target) { _target = target; }
virtual double getStartTime() const { return _sampler->getStartTime(); }
virtual double getEndTime() const { return _sampler->getEndTime(); }
protected:
osg::ref_ptr<TargetType> _target;
osg::ref_ptr<SamplerType> _sampler;
};
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;
typedef TemplateChannel<QuatSphericalLinearSampler> QuatSphericalLinearChannel;
typedef TemplateChannel<MatrixLinearSampler> MatrixLinearChannel;
typedef TemplateChannel<FloatCubicBezierSampler> FloatCubicBezierChannel;
typedef TemplateChannel<DoubleCubicBezierSampler> DoubleCubicBezierChannel;
typedef TemplateChannel<Vec2CubicBezierSampler> Vec2CubicBezierChannel;
typedef TemplateChannel<Vec3CubicBezierSampler> Vec3CubicBezierChannel;
typedef TemplateChannel<Vec4CubicBezierSampler> Vec4CubicBezierChannel;
}
#endif
Referenced
Target
osgAnimation::Channel::setTargetName
void setTargetName(const std::string &name)
osgAnimation::Channel::reset
virtual void reset()=0
osgAnimation::Channel::getEndTime
virtual double getEndTime() const =0
osgAnimation::Channel::getTarget
virtual Target * getTarget()=0
osgAnimation::Channel::getTargetName
const std::string & getTargetName() const
osgAnimation::Channel::createKeyframeContainerFromTargetValue
virtual bool createKeyframeContainerFromTargetValue()=0
osgAnimation::Channel::getSampler
virtual const Sampler * getSampler() const =0
osgAnimation::Channel::_targetName
std::string _targetName
Definition Channel:69
osgAnimation::Channel::_name
std::string _name
Definition Channel:70
osgAnimation::Channel::getName
const std::string & getName() const
osgAnimation::Channel::setTarget
virtual bool setTarget(Target *)=0
osgAnimation::Channel::update
virtual void update(double time, float weight, int priority)=0
osgAnimation::Channel::getSampler
virtual Sampler * getSampler()=0
osgAnimation::Channel::isSameKindAs
virtual bool isSameKindAs(const Object *obj) const
Definition Channel:41
osgAnimation::Channel::setName
void setName(const std::string &name)
osgAnimation::Channel::className
virtual const char * className() const
Definition Channel:43
osgAnimation::Channel::getStartTime
virtual double getStartTime() const =0
osgAnimation::Channel::Channel
Channel()
osgAnimation::Channel::clone
virtual Channel * clone() const =0
osgAnimation::Channel::libraryName
virtual const char * libraryName() const
Definition Channel:42
osgAnimation::Channel::Channel
Channel(const Channel &channel)
osgAnimation::Channel::~Channel
virtual ~Channel()
osgAnimation::Sampler
Definition osgAnimation/Sampler:33
osgAnimation::Target
Definition Target:33
osgAnimation::TemplateChannel
Definition Channel:76
osgAnimation::TemplateChannel::getSampler
Sampler * getSampler()
Definition Channel:148
osgAnimation::TemplateChannel::setTarget
virtual bool setTarget(Target *target)
Definition Channel:135
osgAnimation::TemplateChannel::getStartTime
virtual double getStartTime() const
Definition Channel:159
osgAnimation::TemplateChannel::setTarget
void setTarget(TargetType *target)
Definition Channel:157
osgAnimation::TemplateChannel::setSampler
void setSampler(SamplerType *sampler)
Definition Channel:153
osgAnimation::TemplateChannel::clone
Object * clone(const osg::CopyOp &) const
Definition Channel:84
osgAnimation::TemplateChannel::getTargetTyped
const TargetType * getTargetTyped() const
Definition Channel:156
osgAnimation::TemplateChannel::getEndTime
virtual double getEndTime() const
Definition Channel:160
osgAnimation::TemplateChannel::update
virtual void update(double time, float weight, int priority)
Definition Channel:124
osgAnimation::TemplateChannel::UsingType
SamplerType::UsingType UsingType
Definition Channel:79
osgAnimation::TemplateChannel::reset
virtual void reset()
Definition Channel:133
osgAnimation::TemplateChannel::KeyframeContainerType
TemplateKeyframeContainer< typename SamplerType::KeyframeType > KeyframeContainerType
Definition Channel:81
osgAnimation::TemplateChannel< DoubleStepSampler >::_sampler
osg::ref_ptr< DoubleStepSampler > _sampler
Definition Channel:164
osgAnimation::TemplateChannel::getSampler
const Sampler * getSampler() const
Definition Channel:149
osgAnimation::TemplateChannel::clone
Channel * clone() const
Definition Channel:85
osgAnimation::TemplateChannel::getSamplerTyped
SamplerType * getSamplerTyped()
Definition Channel:151
osgAnimation::TemplateChannel::getOrCreateSampler
SamplerType * getOrCreateSampler()
Definition Channel:141
osgAnimation::TemplateChannel::getSamplerTyped
const SamplerType * getSamplerTyped() const
Definition Channel:152
osgAnimation::TemplateChannel< DoubleStepSampler >::_target
osg::ref_ptr< TargetType > _target
Definition Channel:163
osgAnimation::TemplateChannel::TargetType
TemplateTarget< UsingType > TargetType
Definition Channel:80
osgAnimation::TemplateChannel::createKeyframeContainerFromTargetValue
virtual bool createKeyframeContainerFromTargetValue()
Definition Channel:106
osgAnimation::TemplateChannel::cloneType
Object * cloneType() const
Definition Channel:83
osgAnimation::TemplateChannel::getTarget
virtual Target * getTarget()
Definition Channel:134
osgAnimation::TemplateChannel::~TemplateChannel
virtual ~TemplateChannel()
Definition Channel:123
osgAnimation::TemplateChannel::TemplateChannel
TemplateChannel(SamplerType *s=0, TargetType *target=0)
Definition Channel:97
osgAnimation::TemplateChannel::TemplateChannel
TemplateChannel(const TemplateChannel &channel)
Definition Channel:87
osgAnimation::TemplateChannel::getTargetTyped
TargetType * getTargetTyped()
Definition Channel:155
osgAnimation::TemplateKeyframeContainer
Definition Keyframe:80
osgAnimation::TemplateKeyframeContainer::KeyType
TemplateKeyframe< T > KeyType
Definition Keyframe:84
osgAnimation::TemplateTarget
Definition Target:50
osg::CopyOp
Definition CopyOp:41
osg::Object
Definition Object:61
osg::Object::Object
Object()
Definition Object:69
osg::ref_ptr
Definition ref_ptr:32
osgAnimation
Definition Action:34
osgAnimation::DoubleCubicBezierChannel
TemplateChannel< DoubleCubicBezierSampler > DoubleCubicBezierChannel
Definition Channel:186
osgAnimation::Vec2StepChannel
TemplateChannel< Vec2StepSampler > Vec2StepChannel
Definition Channel:172
osgAnimation::FloatStepChannel
TemplateChannel< FloatStepSampler > FloatStepChannel
Definition Channel:171
osgAnimation::Vec3CubicBezierChannel
TemplateChannel< Vec3CubicBezierSampler > Vec3CubicBezierChannel
Definition Channel:188
osgAnimation::Vec2CubicBezierChannel
TemplateChannel< Vec2CubicBezierSampler > Vec2CubicBezierChannel
Definition Channel:187
osgAnimation::Vec4CubicBezierChannel
TemplateChannel< Vec4CubicBezierSampler > Vec4CubicBezierChannel
Definition Channel:189
osgAnimation::Vec4LinearChannel
TemplateChannel< Vec4LinearSampler > Vec4LinearChannel
Definition Channel:181
osgAnimation::Vec2LinearChannel
TemplateChannel< Vec2LinearSampler > Vec2LinearChannel
Definition Channel:179
osgAnimation::QuatStepChannel
TemplateChannel< QuatStepSampler > QuatStepChannel
Definition Channel:175
osgAnimation::DoubleStepChannel
TemplateChannel< DoubleStepSampler > DoubleStepChannel
Definition Channel:170
osgAnimation::Vec3StepChannel
TemplateChannel< Vec3StepSampler > Vec3StepChannel
Definition Channel:173
osgAnimation::FloatLinearChannel
TemplateChannel< FloatLinearSampler > FloatLinearChannel
Definition Channel:178
osgAnimation::ChannelList
std::vector< osg::ref_ptr< osgAnimation::Channel > > ChannelList
Definition Channel:168
osgAnimation::Vec4StepChannel
TemplateChannel< Vec4StepSampler > Vec4StepChannel
Definition Channel:174
osgAnimation::FloatCubicBezierChannel
TemplateChannel< FloatCubicBezierSampler > FloatCubicBezierChannel
Definition Channel:185
osgAnimation::DoubleLinearChannel
TemplateChannel< DoubleLinearSampler > DoubleLinearChannel
Definition Channel:177
osgAnimation::QuatSphericalLinearChannel
TemplateChannel< QuatSphericalLinearSampler > QuatSphericalLinearChannel
Definition Channel:182
osgAnimation::Vec3LinearChannel
TemplateChannel< Vec3LinearSampler > Vec3LinearChannel
Definition Channel:180
osgAnimation::MatrixLinearChannel
TemplateChannel< MatrixLinearSampler > MatrixLinearChannel
Definition Channel:183
Export
OSGANIMATION_EXPORT
#define OSGANIMATION_EXPORT
Definition osgAnimation/Export:40
Sampler
NULL
#define NULL
Definition osg/Export:55