root/OpenSceneGraph/trunk/include/osgAnimation/Keyframe @ 13041

Revision 13041, 4.4 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*  -*-c++-*-
2 *  Copyright (C) 2008 Cedric Pinson <mornifle@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
15#ifndef OSGANIMATION_KEYFRAME_H
16#define OSGANIMATION_KEYFRAME_H
17
18#include <string>
19#include <osg/Referenced>
20#include <osgAnimation/Vec3Packed>
21#include <osgAnimation/CubicBezier>
22#include <osg/Quat>
23#include <osg/Vec4>
24#include <osg/Vec3>
25#include <osg/Vec2>
26#include <osg/Matrixf>
27
28namespace osgAnimation
29{
30
31    class Keyframe
32    {
33    public:
34        double getTime() const { return _time; }
35        void setTime(double time) { _time = time; }
36
37    protected:
38        double _time;
39
40    };
41
42    template <class T>
43    class TemplateKeyframe : public Keyframe
44    {
45    protected:
46        T _value;
47    public:
48        TemplateKeyframe () {}
49        ~TemplateKeyframe () {}
50
51        TemplateKeyframe (double time, const T& value)
52        {
53            _time = time;
54            _value = value;
55        }
56
57        void setValue(const T& value) { _value = value;}
58        const T& getValue() const { return _value;}
59    };
60
61
62    class KeyframeContainer : public osg::Referenced
63    {
64    public:
65        KeyframeContainer() {}
66        virtual unsigned int size() const = 0;
67    protected:
68        ~KeyframeContainer() {}
69        std::string _name;
70    };
71
72
73    template <class T>
74    class TemplateKeyframeContainer : public std::vector<TemplateKeyframe<T> >, public KeyframeContainer
75    {
76    public:
77        //    const char* getKeyframeType() { return #T ;}
78        TemplateKeyframeContainer() {}
79        typedef TemplateKeyframe<T> KeyType;
80
81        virtual unsigned int size() const { return (unsigned int)std::vector<TemplateKeyframe<T> >::size(); }
82
83    };
84
85    template <>
86    class TemplateKeyframeContainer<Vec3Packed> : public std::vector<TemplateKeyframe<Vec3Packed> >, public KeyframeContainer
87    {
88    public:
89        typedef TemplateKeyframe<Vec3Packed> KeyType;
90
91        TemplateKeyframeContainer() {}
92        const char* getKeyframeType() { return "Vec3Packed" ;}
93        void init(const osg::Vec3f& min, const osg::Vec3f& scale) { _min = min; _scale = scale; }
94
95        osg::Vec3f _min;
96        osg::Vec3f _scale;
97    };
98
99
100    typedef TemplateKeyframe<float> FloatKeyframe;
101    typedef TemplateKeyframeContainer<float> FloatKeyframeContainer;
102
103    typedef TemplateKeyframe<double> DoubleKeyframe;
104    typedef TemplateKeyframeContainer<double> DoubleKeyframeContainer;
105
106    typedef TemplateKeyframe<osg::Vec2> Vec2Keyframe;
107    typedef TemplateKeyframeContainer<osg::Vec2> Vec2KeyframeContainer;
108
109    typedef TemplateKeyframe<osg::Vec3> Vec3Keyframe;
110    typedef TemplateKeyframeContainer<osg::Vec3> Vec3KeyframeContainer;
111
112    typedef TemplateKeyframe<osg::Vec4> Vec4Keyframe;
113    typedef TemplateKeyframeContainer<osg::Vec4> Vec4KeyframeContainer;
114
115    typedef TemplateKeyframe<osg::Quat> QuatKeyframe;
116    typedef TemplateKeyframeContainer<osg::Quat> QuatKeyframeContainer;
117
118    typedef TemplateKeyframe<osg::Matrixf> MatrixKeyframe;
119    typedef TemplateKeyframeContainer<osg::Matrixf> MatrixKeyframeContainer;
120
121    typedef TemplateKeyframe<Vec3Packed> Vec3PackedKeyframe;
122    typedef TemplateKeyframeContainer<Vec3Packed> Vec3PackedKeyframeContainer;
123
124    typedef TemplateKeyframe<FloatCubicBezier> FloatCubicBezierKeyframe;
125    typedef TemplateKeyframeContainer<FloatCubicBezier> FloatCubicBezierKeyframeContainer;
126
127    typedef TemplateKeyframe<DoubleCubicBezier> DoubleCubicBezierKeyframe;
128    typedef TemplateKeyframeContainer<DoubleCubicBezier> DoubleCubicBezierKeyframeContainer;
129
130    typedef TemplateKeyframe<Vec2CubicBezier> Vec2CubicBezierKeyframe;
131    typedef TemplateKeyframeContainer<Vec2CubicBezier> Vec2CubicBezierKeyframeContainer;
132
133    typedef TemplateKeyframe<Vec3CubicBezier> Vec3CubicBezierKeyframe;
134    typedef TemplateKeyframeContainer<Vec3CubicBezier> Vec3CubicBezierKeyframeContainer;
135
136    typedef TemplateKeyframe<Vec4CubicBezier> Vec4CubicBezierKeyframe;
137    typedef TemplateKeyframeContainer<Vec4CubicBezier> Vec4CubicBezierKeyframeContainer;
138
139}
140
141#endif
Note: See TracBrowser for help on using the browser.