OpenSceneGraph 3.6.5
Keyframe
Go to the documentation of this file.
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 <osg/MixinVector>
23#include <osg/Quat>
24#include <osg/Vec4>
25#include <osg/Vec3>
26#include <osg/Vec2>
27#include <osg/Vec3us>
28#include <osg/Matrixf>
29
30namespace osgAnimation
31{
32
34 {
35 public:
36 double getTime() const { return _time; }
37 void setTime(double time) { _time = time; }
38
39 protected:
40 double _time;
41
42 };
43
44 template <class T>
46 {
47 protected:
49 public:
50 typedef T value_type;
51
54
55 TemplateKeyframe (double time, const T& value)
56 {
57 _time = time;
58 _value = value;
59 }
60
61 void setValue(const T& value) { _value = value;}
62 const T& getValue() const { return _value;}
63 };
64
65
67 {
68 public:
70 virtual unsigned int size() const = 0;
71 virtual unsigned int linearInterpolationDeduplicate() = 0;
72 protected:
74 std::string _name;
75 };
76
77
78 template <class T>
79 class TemplateKeyframeContainer : public osg::MixinVector<TemplateKeyframe<T> >, public KeyframeContainer
80 {
81 public:
82 // const char* getKeyframeType() { return #T ;}
86 virtual unsigned int size() const { return (unsigned int)osg::MixinVector<TemplateKeyframe<T> >::size(); }
87 virtual unsigned int linearInterpolationDeduplicate() {
88 if(size() <= 1) {
89 return 0;
90 }
91
92 typename VectorType::iterator keyframe = VectorType::begin(),
93 previous = VectorType::begin();
94 // 1. find number of consecutives identical keyframes
95 std::vector<unsigned int> intervalSizes;
96 unsigned int intervalSize = 1;
97 for(++ keyframe ; keyframe != VectorType::end() ; ++ keyframe, ++ previous, ++ intervalSize) {
98 if(!(previous->getValue() == keyframe->getValue())) {
99 intervalSizes.push_back(intervalSize);
100 intervalSize = 0;
101 }
102 }
103 intervalSizes.push_back(intervalSize);
104
105 // 2. build deduplicated list of keyframes
106 unsigned int cumul = 0;
107 VectorType deduplicated;
108 for(std::vector<unsigned int>::iterator iterator = intervalSizes.begin() ; iterator != intervalSizes.end() ; ++ iterator) {
109 deduplicated.push_back((*this)[cumul]);
110 if(*iterator > 1) {
111 deduplicated.push_back((*this)[cumul + (*iterator) - 1]);
112 }
113 cumul += *iterator;
114 }
115
116 unsigned int count = size() - deduplicated.size();
117 this->swap(deduplicated);
118 return count;
119 }
120 };
121
122 template <>
123 class TemplateKeyframeContainer<Vec3Packed> : public osg::MixinVector<TemplateKeyframe<Vec3Packed> >, public KeyframeContainer
124 {
125 public:
126 typedef TemplateKeyframe<Vec3Packed> KeyType;
127
129 const char* getKeyframeType() { return "Vec3Packed" ;}
130 void init(const osg::Vec3f& min, const osg::Vec3f& scale) { _min = min; _scale = scale; }
131
132 osg::Vec3f _min;
133 osg::Vec3f _scale;
134 };
135
136
139
142
145
148
151
154
157
160
163
166
169
172
175
178
181
182}
183
184#endif
The osgAnimation library provides general purpose utility classes for animation.
Definition Action:34
TemplateKeyframeContainer< DoubleCubicBezier > DoubleCubicBezierKeyframeContainer
Definition Keyframe:171
TemplateKeyframe< DoubleCubicBezier > DoubleCubicBezierKeyframe
Definition Keyframe:170
TemplateKeyframeContainer< osg::Vec3us > Vec3usKeyframeContainer
Definition Keyframe:150
TemplateKeyframeContainer< Vec3Packed > Vec3PackedKeyframeContainer
Definition Keyframe:165
TemplateKeyframeContainer< FloatCubicBezier > FloatCubicBezierKeyframeContainer
Definition Keyframe:168
TemplateKeyframeContainer< double > DoubleKeyframeContainer
Definition Keyframe:141
TemplateKeyframe< FloatCubicBezier > FloatCubicBezierKeyframe
Definition Keyframe:167
TemplateKeyframeContainer< float > FloatKeyframeContainer
Definition Keyframe:138
TemplateKeyframe< osg::Vec4 > Vec4Keyframe
Definition Keyframe:152
TemplateKeyframeContainer< osg::Vec4 > Vec4KeyframeContainer
Definition Keyframe:153
TemplateKeyframe< osg::Vec3us > Vec3usKeyframe
Definition Keyframe:149
TemplateKeyframe< Vec3Packed > Vec3PackedKeyframe
Definition Keyframe:164
TemplateKeyframe< Vec2CubicBezier > Vec2CubicBezierKeyframe
Definition Keyframe:173
TemplateKeyframeContainer< Vec3CubicBezier > Vec3CubicBezierKeyframeContainer
Definition Keyframe:177
TemplateKeyframe< osg::Matrixf > MatrixKeyframe
Definition Keyframe:161
TemplateKeyframe< osg::Vec2 > Vec2Keyframe
Definition Keyframe:143
TemplateKeyframeContainer< osg::Matrixf > MatrixKeyframeContainer
Definition Keyframe:162
TemplateKeyframe< double > DoubleKeyframe
Definition Keyframe:140
TemplateKeyframe< osg::Quat > QuatKeyframe
Definition Keyframe:155
TemplateKeyframeContainer< Vec4CubicBezier > Vec4CubicBezierKeyframeContainer
Definition Keyframe:180
TemplateKeyframe< float > FloatKeyframe
Definition Keyframe:137
TemplateKeyframe< Vec3CubicBezier > Vec3CubicBezierKeyframe
Definition Keyframe:176
TemplateKeyframeContainer< osg::Vec3 > Vec3KeyframeContainer
Definition Keyframe:147
TemplateKeyframeContainer< Vec2CubicBezier > Vec2CubicBezierKeyframeContainer
Definition Keyframe:174
TemplateKeyframeContainer< osg::Quat > QuatKeyframeContainer
Definition Keyframe:156
TemplateKeyframe< Vec4CubicBezier > Vec4CubicBezierKeyframe
Definition Keyframe:179
TemplateKeyframeContainer< osg::Vec2 > Vec2KeyframeContainer
Definition Keyframe:144
TemplateKeyframe< osg::Vec3 > Vec3Keyframe
Definition Keyframe:146
MixinVector is a base class that allows inheritance to be used to easily emulate derivation from std:...
Definition MixinVector:29
size_type size() const
Definition MixinVector:92
const_iterator end() const
Definition MixinVector:99
const_iterator begin() const
Definition MixinVector:97
void push_back(const value_type &value)
Definition MixinVector:117
void swap(vector_type &other)
Definition MixinVector:88
vector_type::iterator iterator
Definition MixinVector:39
Base class for providing reference counted objects.
Definition Referenced:44
Definition Keyframe:34
double getTime() const
Definition Keyframe:36
double _time
Definition Keyframe:40
void setTime(double time)
Definition Keyframe:37
Definition Keyframe:46
TemplateKeyframe(double time, const T &value)
Definition Keyframe:55
void setValue(const T &value)
Definition Keyframe:61
~TemplateKeyframe()
Definition Keyframe:53
TemplateKeyframe()
Definition Keyframe:52
T value_type
Definition Keyframe:50
const T & getValue() const
Definition Keyframe:62
Vec3Packed _value
Definition Keyframe:48
~KeyframeContainer()
Definition Keyframe:73
std::string _name
Definition Keyframe:74
virtual unsigned int linearInterpolationDeduplicate()=0
virtual unsigned int size() const =0
KeyframeContainer()
Definition Keyframe:69
osg::MixinVector< TemplateKeyframe< typename SamplerType::KeyframeType > > VectorType
Definition Keyframe:85
virtual unsigned int linearInterpolationDeduplicate()
Definition Keyframe:87
TemplateKeyframeContainer()
Definition Keyframe:83
virtual unsigned int size() const
Definition Keyframe:86
TemplateKeyframe< typename SamplerType::KeyframeType > KeyType
Definition Keyframe:84

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.