openscenegraph
osgAnimation/Sampler
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_SAMPLER
20#define OSGANIMATION_SAMPLER 1
21
22#include <vector>
23#include <iostream>
24#include <osg/Referenced>
25#include <osg/ref_ptr>
26#include <osgAnimation/Keyframe>
28
29namespace osgAnimation
30{
31
32 class Sampler : public osg::Referenced
33 {
34 public:
36 virtual const KeyframeContainer* getKeyframeContainer() const = 0;
37 protected:
38 };
39
40 // Sampler generic
41 template <class F>
42 class TemplateSampler : public Sampler
43 {
44 public:
45 typedef typename F::KeyframeType KeyframeType;
47 typedef typename F::UsingType UsingType;
48 typedef F FunctorType;
49
52
53 void getValueAt(double time, UsingType& result) const { _functor.getValue(*_keyframes, time, result);}
55
57 virtual const KeyframeContainer* getKeyframeContainer() const { return _keyframes.get();}
58
62 {
63 if (_keyframes != 0)
64 return _keyframes.get();
66 return _keyframes.get();
67 }
68
69 double getStartTime() const
70 {
71 if (!_keyframes || _keyframes->empty())
72 return 0.0;
73 return _keyframes->front().getTime();
74 }
75
76 double getEndTime() const
77 {
78 if (!_keyframes || _keyframes->empty())
79 return 0.0;
80 return _keyframes->back().getTime();
81 }
82
83 protected:
84
87 };
88
89
90 template<typename VALUESAMPLERTYPE, typename TIMESAMPLERTYPE>
92 {
93 VALUESAMPLERTYPE& _value;
94 TIMESAMPLERTYPE& _time;
95
96 public:
97 typedef typename VALUESAMPLERTYPE::FunctorType::UsingType UsingType;
98 typedef typename VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType;
99
100 TemplateCompositeSampler(VALUESAMPLERTYPE& value, TIMESAMPLERTYPE& time) : _value(value), _time(time)
101 {
102 }
103
104 void getValueAt(double time, typename VALUESAMPLERTYPE::FunctorType::UsingType& result)
105 {
106 double newtime;
107 _time.getValueAt(time, newtime);
108 _value.getValueAt(newtime, result);
109 }
110 float getStartTime() const {return _time.getStartTime(); }
111 float getEndTime() const {return _time.getEndTime();}
112 };
113
114
121
129
135
136}
137
138#endif
Definition Keyframe:67
Definition osgAnimation/Sampler:33
virtual const KeyframeContainer * getKeyframeContainer() const =0
virtual KeyframeContainer * getKeyframeContainer()=0
Definition osgAnimation/Sampler:92
TemplateCompositeSampler(VALUESAMPLERTYPE &value, TIMESAMPLERTYPE &time)
Definition osgAnimation/Sampler:100
float getStartTime() const
Definition osgAnimation/Sampler:110
VALUESAMPLERTYPE::FunctorType::KeyframeType KeyframeType
Definition osgAnimation/Sampler:98
float getEndTime() const
Definition osgAnimation/Sampler:111
void getValueAt(double time, typename VALUESAMPLERTYPE::FunctorType::UsingType &result)
Definition osgAnimation/Sampler:104
VALUESAMPLERTYPE::FunctorType::UsingType UsingType
Definition osgAnimation/Sampler:97
Definition osgAnimation/Sampler:43
TemplateSampler()
Definition osgAnimation/Sampler:50
void setKeyframeContainer(KeyframeContainerType *kf)
Definition osgAnimation/Sampler:54
virtual const KeyframeContainer * getKeyframeContainer() const
Definition osgAnimation/Sampler:57
double getEndTime() const
Definition osgAnimation/Sampler:76
F::UsingType UsingType
Definition osgAnimation/Sampler:47
osg::ref_ptr< KeyframeContainerType > _keyframes
Definition osgAnimation/Sampler:86
const KeyframeContainerType * getKeyframeContainerTyped() const
Definition osgAnimation/Sampler:60
KeyframeContainerType * getKeyframeContainerTyped()
Definition osgAnimation/Sampler:59
void getValueAt(double time, UsingType &result) const
Definition osgAnimation/Sampler:53
~TemplateSampler()
Definition osgAnimation/Sampler:51
FunctorType _functor
Definition osgAnimation/Sampler:85
F::KeyframeType KeyframeType
Definition osgAnimation/Sampler:45
double getStartTime() const
Definition osgAnimation/Sampler:69
virtual KeyframeContainer * getKeyframeContainer()
Definition osgAnimation/Sampler:56
TemplateKeyframeContainer< KeyframeType > KeyframeContainerType
Definition osgAnimation/Sampler:46
KeyframeContainerType * getOrCreateKeyframeContainer()
Definition osgAnimation/Sampler:61
F FunctorType
Definition osgAnimation/Sampler:48
Definition Referenced:44
Definition ref_ptr:32
Definition Action:34
TemplateSampler< Vec3StepInterpolator > Vec3StepSampler
Definition osgAnimation/Sampler:118
TemplateSampler< Vec4LinearInterpolator > Vec4LinearSampler
Definition osgAnimation/Sampler:126
TemplateSampler< FloatLinearInterpolator > FloatLinearSampler
Definition osgAnimation/Sampler:123
TemplateSampler< Vec3CubicBezierInterpolator > Vec3CubicBezierSampler
Definition osgAnimation/Sampler:133
TemplateSampler< DoubleStepInterpolator > DoubleStepSampler
Definition osgAnimation/Sampler:115
TemplateSampler< FloatStepInterpolator > FloatStepSampler
Definition osgAnimation/Sampler:116
TemplateSampler< Vec4StepInterpolator > Vec4StepSampler
Definition osgAnimation/Sampler:119
TemplateSampler< MatrixLinearInterpolator > MatrixLinearSampler
Definition osgAnimation/Sampler:128
TemplateSampler< Vec3LinearInterpolator > Vec3LinearSampler
Definition osgAnimation/Sampler:125
TemplateSampler< Vec2StepInterpolator > Vec2StepSampler
Definition osgAnimation/Sampler:117
TemplateSampler< DoubleLinearInterpolator > DoubleLinearSampler
Definition osgAnimation/Sampler:122
TemplateSampler< FloatCubicBezierInterpolator > FloatCubicBezierSampler
Definition osgAnimation/Sampler:130
TemplateSampler< QuatSphericalLinearInterpolator > QuatSphericalLinearSampler
Definition osgAnimation/Sampler:127
TemplateSampler< Vec2LinearInterpolator > Vec2LinearSampler
Definition osgAnimation/Sampler:124
TemplateSampler< QuatStepInterpolator > QuatStepSampler
Definition osgAnimation/Sampler:120
TemplateSampler< Vec4CubicBezierInterpolator > Vec4CubicBezierSampler
Definition osgAnimation/Sampler:134
TemplateSampler< DoubleCubicBezierInterpolator > DoubleCubicBezierSampler
Definition osgAnimation/Sampler:131
TemplateSampler< Vec2CubicBezierInterpolator > Vec2CubicBezierSampler
Definition osgAnimation/Sampler:132