OpenSceneGraph 3.6.5
Channel
Go to the documentation of this file.
1/* -*-c++-*-
2 * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
3 *
4 * This library is open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version. The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * OpenSceneGraph Public License for more details.
13 *
14 * Authors:
15 * Cedric Pinson <cedric.pinson@plopbyte.net>
16 * Michael Platings <mplatings@pixelpower.com>
17 */
18
19#ifndef OSGANIMATION_CHANNEL
20#define OSGANIMATION_CHANNEL 1
21
22#include <osgAnimation/Export>
23#include <osgAnimation/Sampler>
24#include <osgAnimation/Target>
25#include <osg/Referenced>
26#include <string>
27
28
29namespace osgAnimation
30{
31
33 {
34 public:
35
37 Channel(const Channel& channel);
38 virtual ~Channel();
39 virtual Channel* clone() const = 0;
40
41 virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Channel*>(obj)!=NULL; }
42 virtual const char* libraryName() const { return "osgAnimation"; }
43 virtual const char* className() const { return "Channel"; }
44
45 virtual void update(double time, float weight, int priority) = 0;
46 virtual void reset() = 0;
47 virtual Target* getTarget() = 0;
48 virtual bool setTarget(Target*) = 0;
49
50 const std::string& getName() const;
51 void setName(const std::string& name);
52
53 virtual double getStartTime() const = 0;
54 virtual double getEndTime() const = 0;
55
56 const std::string& getTargetName() const;
57 void setTargetName(const std::string& name);
58
59 virtual Sampler* getSampler() = 0;
60 virtual const Sampler* getSampler() const = 0;
61
62 // create a keyframe container from current target value
63 // with one key only, can be used for debug or to create
64 // easily a default channel from an existing one
66
67 protected:
68
69 std::string _targetName;
70 std::string _name;
71 };
72
73
74 template <typename SamplerType>
75 class TemplateChannel : public Channel
76 {
77 public:
78
79 typedef typename SamplerType::UsingType UsingType;
82
83 Object* cloneType() const { return new TemplateChannel(); }
84 Object* clone(const osg::CopyOp&) const { return new TemplateChannel<SamplerType>(*this); }
85 Channel* clone() const { return new TemplateChannel<SamplerType>(*this); }
86
88 Channel(channel)
89 {
90 if (channel.getTargetTyped())
91 _target = new TargetType(*channel.getTargetTyped());
92
93 if (channel.getSamplerTyped())
94 _sampler = new SamplerType(*channel.getSamplerTyped());
95 }
96
97 TemplateChannel (SamplerType* s = 0,TargetType* target = 0)
98 {
99 if (target)
100 _target = target;
101 else
102 _target = new TargetType;
103 _sampler = s;
104 }
105
107 {
108 if (!_target.valid()) // no target it does not make sense to do it
109 {
110 return false;
111 }
112
113 // create a key from current target value
114 typename KeyframeContainerType::KeyType key(0, _target->getValue());
115 // recreate the keyframe container
116 getOrCreateSampler()->setKeyframeContainer(0);
117 getOrCreateSampler()->getOrCreateKeyframeContainer();
118 // add the key
119 _sampler->getKeyframeContainerTyped()->push_back(key);
120 return true;
121 }
122
123 virtual ~TemplateChannel() {}
124 virtual void update(double time, float weight, int priority)
125 {
126 // skip if weight == 0
127 if (weight < 1e-4)
128 return;
129 typename SamplerType::UsingType value;
130 _sampler->getValueAt(time, value);
131 _target->update(weight, value, priority);
132 }
133 virtual void reset() { _target->reset(); }
134 virtual Target* getTarget() { return _target.get();}
135 virtual bool setTarget(Target* target)
136 {
137 _target = dynamic_cast<TargetType*>(target);
138 return _target.get() == target;
139 }
140
141 SamplerType* getOrCreateSampler()
142 {
143 if (!_sampler.valid())
144 _sampler = new SamplerType;
145 return _sampler.get();
146 }
147
148 Sampler* getSampler() { return _sampler.get(); }
149 const Sampler* getSampler() const { return _sampler.get(); }
150
151 SamplerType* getSamplerTyped() { return _sampler.get();}
152 const SamplerType* getSamplerTyped() const { return _sampler.get();}
153 void setSampler(SamplerType* sampler) { _sampler = sampler; }
154
155 TargetType* getTargetTyped() { return _target.get(); }
156 const TargetType* getTargetTyped() const { return _target.get(); }
157 void setTarget(TargetType* target) { _target = target; }
158
159 virtual double getStartTime() const { return _sampler->getStartTime(); }
160 virtual double getEndTime() const { return _sampler->getEndTime(); }
161
162 protected:
165 };
166
167
168 typedef std::vector<osg::ref_ptr<osgAnimation::Channel> > ChannelList;
169
176
184
190
191}
192
193#endif
The osgAnimation library provides general purpose utility classes for animation.
Definition Action:34
TemplateChannel< DoubleCubicBezierSampler > DoubleCubicBezierChannel
Definition Channel:186
TemplateChannel< Vec2StepSampler > Vec2StepChannel
Definition Channel:172
TemplateChannel< FloatStepSampler > FloatStepChannel
Definition Channel:171
TemplateChannel< Vec3CubicBezierSampler > Vec3CubicBezierChannel
Definition Channel:188
TemplateChannel< Vec2CubicBezierSampler > Vec2CubicBezierChannel
Definition Channel:187
TemplateChannel< Vec4CubicBezierSampler > Vec4CubicBezierChannel
Definition Channel:189
TemplateChannel< Vec4LinearSampler > Vec4LinearChannel
Definition Channel:181
TemplateChannel< Vec2LinearSampler > Vec2LinearChannel
Definition Channel:179
TemplateChannel< QuatStepSampler > QuatStepChannel
Definition Channel:175
TemplateChannel< DoubleStepSampler > DoubleStepChannel
Definition Channel:170
TemplateChannel< Vec3StepSampler > Vec3StepChannel
Definition Channel:173
TemplateChannel< FloatLinearSampler > FloatLinearChannel
Definition Channel:178
std::vector< osg::ref_ptr< osgAnimation::Channel > > ChannelList
Definition Channel:168
TemplateChannel< Vec4StepSampler > Vec4StepChannel
Definition Channel:174
TemplateChannel< FloatCubicBezierSampler > FloatCubicBezierChannel
Definition Channel:185
TemplateChannel< DoubleLinearSampler > DoubleLinearChannel
Definition Channel:177
TemplateChannel< QuatSphericalLinearSampler > QuatSphericalLinearChannel
Definition Channel:182
TemplateChannel< Vec3LinearSampler > Vec3LinearChannel
Definition Channel:180
TemplateChannel< MatrixLinearSampler > MatrixLinearChannel
Definition Channel:183
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
Base class/standard interface for objects which require IO support, cloning and reference counting.
Definition Object:61
Object()
Construct an object.
Definition Object:69
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
void setTargetName(const std::string &name)
virtual void reset()=0
virtual double getEndTime() const =0
virtual Target * getTarget()=0
const std::string & getTargetName() const
virtual bool createKeyframeContainerFromTargetValue()=0
virtual const Sampler * getSampler() const =0
std::string _targetName
Definition Channel:69
std::string _name
Definition Channel:70
const std::string & getName() const
virtual bool setTarget(Target *)=0
virtual void update(double time, float weight, int priority)=0
virtual Sampler * getSampler()=0
virtual bool isSameKindAs(const Object *obj) const
Definition Channel:41
void setName(const std::string &name)
Set the name of object using C++ style string.
virtual const char * className() const
return the name of the object's class type.
Definition Channel:43
virtual double getStartTime() const =0
virtual Channel * clone() const =0
virtual const char * libraryName() const
return the name of the object's library.
Definition Channel:42
Channel(const Channel &channel)
Definition Channel:76
Sampler * getSampler()
Definition Channel:148
virtual bool setTarget(Target *target)
Definition Channel:135
virtual double getStartTime() const
Definition Channel:159
void setTarget(TargetType *target)
Definition Channel:157
void setSampler(SamplerType *sampler)
Definition Channel:153
Object * clone(const osg::CopyOp &) const
Clone an object, with Object* return type.
Definition Channel:84
const TargetType * getTargetTyped() const
Definition Channel:156
virtual double getEndTime() const
Definition Channel:160
virtual void update(double time, float weight, int priority)
Definition Channel:124
SamplerType::UsingType UsingType
Definition Channel:79
virtual void reset()
Definition Channel:133
TemplateKeyframeContainer< typename SamplerType::KeyframeType > KeyframeContainerType
Definition Channel:81
osg::ref_ptr< DoubleStepSampler > _sampler
Definition Channel:164
const Sampler * getSampler() const
Definition Channel:149
Channel * clone() const
Definition Channel:85
SamplerType * getSamplerTyped()
Definition Channel:151
SamplerType * getOrCreateSampler()
Definition Channel:141
const SamplerType * getSamplerTyped() const
Definition Channel:152
osg::ref_ptr< TargetType > _target
Definition Channel:163
TemplateTarget< UsingType > TargetType
Definition Channel:80
virtual bool createKeyframeContainerFromTargetValue()
Definition Channel:106
Object * cloneType() const
Clone the type of an object, with Object* return type.
Definition Channel:83
virtual Target * getTarget()
Definition Channel:134
virtual ~TemplateChannel()
Definition Channel:123
TemplateChannel(SamplerType *s=0, TargetType *target=0)
Definition Channel:97
TemplateChannel(const TemplateChannel &channel)
Definition Channel:87
TargetType * getTargetTyped()
Definition Channel:155
TemplateKeyframe< T > KeyType
Definition Keyframe:84
Definition Sampler:33
Definition Target:33
Definition Target:50
#define NULL
Definition Export:55
#define OSGANIMATION_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.