root/OpenSceneGraph/trunk/include/osgAnimation/Sampler @ 10527

Revision 10527, 4.9 kB (checked in by cedricpinson, 5 years ago)

From Michael Platings,
Changes to allow osgAnimation::*CubicBezierChannel? to be used
Added TemplateStepInterpolator? class

RevLine 
[9093]1/*  -*-c++-*-
[10527]2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
[9093]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.
[10527]13 *
14 * Authors:
15 *         Cedric Pinson <cedric.pinson@plopbyte.net>
16 *         Michael Platings <mplatings@pixelpower.com>
17 */
[9093]18
19#ifndef OSGANIMATION_SAMPLER_H
20#define OSGANIMATION_SAMPLER_H
21
22#include <vector>
23#include <iostream>
24#include <osg/Referenced>
25#include <osg/ref_ptr>
26#include <osgAnimation/Keyframe>
27#include <osgAnimation/Interpolator>
28
29namespace osgAnimation
30{
31
32    class Sampler : public osg::Referenced
33    {
34    public:
35        virtual KeyframeContainer* getKeyframeContainer() = 0;
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;
46        typedef TemplateKeyframeContainer<KeyframeType> KeyframeContainerType;
47        typedef typename F::UsingType UsingType;
48        typedef F FunctorType;
49
50        TemplateSampler() {}
51        ~TemplateSampler() {}
52
53        void getValueAt(float time, UsingType& result) const { _functor.getValue(*_keyframes, time, result);}
54        void setKeyframeContainer(KeyframeContainerType* kf) { _keyframes = kf;}
55
56        virtual KeyframeContainer* getKeyframeContainer() { return _keyframes.get(); }
57        virtual const KeyframeContainer* getKeyframeContainer() const { return _keyframes.get();}
58
59        KeyframeContainerType* getKeyframeContainerTyped() { return _keyframes.get();}
60        const KeyframeContainerType* getKeyframeContainerTyped() const { return _keyframes.get();}
61        KeyframeContainerType* getOrCreateKeyframeContainer()
62        {
63            if (_keyframes != 0)
64                return _keyframes.get();
65            _keyframes = new KeyframeContainerType;
66            return _keyframes.get();
67        }
68
69        float getStartTime() const
70        {
[9531]71            if (!_keyframes)
72                return 0.0f;
[9093]73            return _keyframes->front().getTime();
74        }
75
76        float getEndTime() const
77        {
[9531]78            if (!_keyframes)
79                return 0.0f;
[9093]80            return _keyframes->back().getTime();
81        }
82
83    protected:
84
85        FunctorType _functor;
86        osg::ref_ptr<KeyframeContainerType> _keyframes;
87    };
88
89
90    template<typename VALUESAMPLERTYPE, typename TIMESAMPLERTYPE>
91    class TemplateCompositeSampler : public osg::Referenced
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(float time, typename VALUESAMPLERTYPE::FunctorType::UsingType& result)
105        {
106            float 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
[10527]115    typedef TemplateSampler<DoubleStepInterpolator> DoubleStepSampler;
116    typedef TemplateSampler<FloatStepInterpolator> FloatStepSampler;
117    typedef TemplateSampler<Vec2StepInterpolator> Vec2StepSampler;
118    typedef TemplateSampler<Vec3StepInterpolator> Vec3StepSampler;
119    typedef TemplateSampler<Vec4StepInterpolator> Vec4StepSampler;
120    typedef TemplateSampler<QuatStepInterpolator> QuatStepSampler;
121
[9093]122    typedef TemplateSampler<DoubleLinearInterpolator> DoubleLinearSampler;
123    typedef TemplateSampler<FloatLinearInterpolator> FloatLinearSampler;
124    typedef TemplateSampler<Vec2LinearInterpolator> Vec2LinearSampler;
125    typedef TemplateSampler<Vec3LinearInterpolator> Vec3LinearSampler;
126    typedef TemplateSampler<Vec4LinearInterpolator> Vec4LinearSampler;
127    typedef TemplateSampler<QuatSphericalLinearInterpolator> QuatSphericalLinearSampler;
[10527]128
[9093]129    typedef TemplateSampler<FloatCubicBezierInterpolator> FloatCubicBezierSampler;
130    typedef TemplateSampler<DoubleCubicBezierInterpolator> DoubleCubicBezierSampler;
131    typedef TemplateSampler<Vec2CubicBezierInterpolator> Vec2CubicBezierSampler;
132    typedef TemplateSampler<Vec3CubicBezierInterpolator> Vec3CubicBezierSampler;
133    typedef TemplateSampler<Vec4CubicBezierInterpolator> Vec4CubicBezierSampler;
134 
[9376]135}
[9093]136
137#endif
Note: See TracBrowser for help on using the browser.