All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Animation.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Nate Koenig
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _ANIMATION_HH_
18 #define _ANIMATION_HH_
19 
20 #include <string>
21 #include <vector>
22 
23 namespace gazebo
24 {
25  namespace math
26  {
27  class Spline;
28  class RotationSpline;
29  }
30 
33 
34  namespace common
35  {
36  class KeyFrame;
37  class PoseKeyFrame;
38  class NumericKeyFrame;
39 
42 
45  class Animation
46  {
51  public: Animation(const std::string &_name, double _length, bool _loop);
52 
54  public: virtual ~Animation();
55 
58  public: double GetLength() const;
59 
62  public: void SetLength(double _len);
63 
66  public: void SetTime(double _time);
67 
70  public: void AddTime(double _time);
71 
74  public: double GetTime() const;
75 
78  public: unsigned int GetKeyFrameCount() const;
79 
83  public: KeyFrame* GetKeyFrame(unsigned int _index) const;
84 
91  protected: double GetKeyFramesAtTime(double _time, KeyFrame **_kf1,
92  KeyFrame **_kf2,
93  unsigned int &_firstKeyIndex) const;
94 
95 
97  protected: std::string name;
98 
100  protected: double length;
101 
103  protected: double timePos;
104 
106  protected: mutable bool build;
107 
109  protected: bool loop;
110 
112  protected: typedef std::vector<KeyFrame*> KeyFrame_V;
113 
115  protected: KeyFrame_V keyFrames;
116  };
118 
121 
123  class PoseAnimation : public Animation
124  {
129  public: PoseAnimation(const std::string &_name,
130  double _length, bool _loop);
131 
133  public: virtual ~PoseAnimation();
134 
138  public: PoseKeyFrame *CreateKeyFrame(double _time);
139 
142  public: void GetInterpolatedKeyFrame(PoseKeyFrame &_kf) const;
143 
147  protected: void GetInterpolatedKeyFrame(double _time,
148  PoseKeyFrame &_kf) const;
149 
151  protected: void BuildInterpolationSplines() const;
152 
154  private: mutable math::Spline *positionSpline;
155 
157  private: mutable math::RotationSpline *rotationSpline;
158  };
160 
163 
166  {
171  public: NumericAnimation(const std::string &_name,
172  double _length, bool _loop);
173 
175  public: virtual ~NumericAnimation();
176 
180  public: NumericKeyFrame *CreateKeyFrame(double _time);
181 
185  public: void GetInterpolatedKeyFrame(NumericKeyFrame &_kf) const;
186  };
188  }
189 }
190 
191 #endif