Animation.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
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 #include <ignition/math/Spline.hh>
23 #include <ignition/math/RotationSpline.hh>
24 #include "gazebo/util/system.hh"
25 
26 namespace gazebo
27 {
30 
31  namespace common
32  {
33  class KeyFrame;
34  class PoseKeyFrame;
35  class NumericKeyFrame;
36 
39 
43  class GZ_COMMON_VISIBLE Animation
44  {
49  public: Animation(const std::string &_name, double _length, bool _loop);
50 
52  public: virtual ~Animation();
53 
56  public: double GetLength() const;
57 
60  public: void SetLength(double _len);
61 
64  public: void SetTime(double _time);
65 
68  public: void AddTime(double _time);
69 
72  public: double GetTime() const;
73 
76  public: unsigned int GetKeyFrameCount() const;
77 
81  public: KeyFrame* GetKeyFrame(unsigned int _index) const;
82 
89  protected: double GetKeyFramesAtTime(double _time, KeyFrame **_kf1,
90  KeyFrame **_kf2,
91  unsigned int &_firstKeyIndex) const;
92 
93 
95  protected: std::string name;
96 
98  protected: double length;
99 
101  protected: double timePos;
102 
104  protected: mutable bool build;
105 
107  protected: bool loop;
108 
110  protected: typedef std::vector<KeyFrame*> KeyFrame_V;
111 
113  protected: KeyFrame_V keyFrames;
114  };
116 
119 
121  class GZ_COMMON_VISIBLE PoseAnimation : public Animation
122  {
127  public: PoseAnimation(const std::string &_name,
128  double _length, bool _loop);
129 
131  public: virtual ~PoseAnimation();
132 
136  public: PoseKeyFrame *CreateKeyFrame(double _time);
137 
140  public: void GetInterpolatedKeyFrame(PoseKeyFrame &_kf) const;
141 
145  protected: void GetInterpolatedKeyFrame(double _time,
146  PoseKeyFrame &_kf) const;
147 
149  protected: void BuildInterpolationSplines() const;
150 
152  private: mutable ignition::math::Spline *positionSpline;
153 
155  private: mutable ignition::math::RotationSpline *rotationSpline;
156  };
158 
161 
163  class GZ_COMMON_VISIBLE NumericAnimation : public Animation
164  {
169  public: NumericAnimation(const std::string &_name,
170  double _length, bool _loop);
171 
173  public: virtual ~NumericAnimation();
174 
178  public: NumericKeyFrame *CreateKeyFrame(double _time);
179 
183  public: void GetInterpolatedKeyFrame(NumericKeyFrame &_kf) const;
184  };
186  }
187 }
188 
189 #endif
bool build
determines if the interpolation splines need building
Definition: Animation.hh:104
bool loop
true if animation repeats
Definition: Animation.hh:107
KeyFrame_V keyFrames
array of key frames
Definition: Animation.hh:113
double timePos
current time position
Definition: Animation.hh:101
A numeric animation.
Definition: Animation.hh:163
std::string name
animation name
Definition: Animation.hh:95
A keyframe for a NumericAnimation.
Definition: KeyFrame.hh:86
double length
animation duration
Definition: Animation.hh:98
std::vector< KeyFrame * > KeyFrame_V
array of keyframe type alias
Definition: Animation.hh:110
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition: Animation.hh:43
A keyframe for a PoseAnimation.
Definition: KeyFrame.hh:53
A key frame in an animation.
Definition: KeyFrame.hh:35
A pose animation.
Definition: Animation.hh:121