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

Revision 9877, 4.3 kB (checked in by robert, 5 years ago)

From Roland Smeenk & Cedric Pinson,

"Summary of changes:
From Roland
-Added MorphGeometry?
-Bone Bindmatrix is only calculated if needed
-osgAnimation plugin now supports all available channel types (before only linear vec3 or quat channels)
-osgAnimation plugin now supports MorphGeometry?
-osgAnimation plugin now supports animation and channel weights, animation playmode, duration and starttime
-removed osgAnimationManager.cpp from CMakeList

From Cedric
-fixed the last_update field (it was only updated at the first update) in BasicAnimationManager?.cpp
- Refactore some part of MorphGeometry? minor changes
- Add osganimationmorph as example
"

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