Animation.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 "gazebo/util/system.hh"
23 
24 namespace ignition
25 {
26  namespace math
27  {
28  class Spline;
29  class RotationSpline;
30  }
31 }
32 
33 namespace gazebo
34 {
37 
38  namespace common
39  {
40  class KeyFrame;
41  class PoseKeyFrame;
42  class NumericKeyFrame;
43 
46 
50  class GZ_COMMON_VISIBLE Animation
51  {
56  public: Animation(const std::string &_name, double _length, bool _loop);
57 
59  public: virtual ~Animation();
60 
63  public: double GetLength() const;
64 
67  public: void SetLength(double _len);
68 
71  public: void SetTime(double _time);
72 
75  public: void AddTime(double _time);
76 
79  public: double GetTime() const;
80 
83  public: unsigned int GetKeyFrameCount() const;
84 
88  public: KeyFrame* GetKeyFrame(unsigned int _index) const;
89 
96  protected: double GetKeyFramesAtTime(double _time, KeyFrame **_kf1,
97  KeyFrame **_kf2,
98  unsigned int &_firstKeyIndex) const;
99 
100 
102  protected: std::string name;
103 
105  protected: double length;
106 
108  protected: double timePos;
109 
111  protected: mutable bool build;
112 
114  protected: bool loop;
115 
117  protected: typedef std::vector<KeyFrame*> KeyFrame_V;
118 
120  protected: KeyFrame_V keyFrames;
121  };
123 
126 
128  class GZ_COMMON_VISIBLE PoseAnimation : public Animation
129  {
134  public: PoseAnimation(const std::string &_name,
135  double _length, bool _loop);
136 
138  public: virtual ~PoseAnimation();
139 
143  public: PoseKeyFrame *CreateKeyFrame(double _time);
144 
147  public: void GetInterpolatedKeyFrame(PoseKeyFrame &_kf) const;
148 
152  protected: void GetInterpolatedKeyFrame(double _time,
153  PoseKeyFrame &_kf) const;
154 
156  protected: void BuildInterpolationSplines() const;
157 
159  private: mutable ignition::math::Spline *positionSpline;
160 
162  private: mutable ignition::math::RotationSpline *rotationSpline;
163  };
165 
168 
170  class GZ_COMMON_VISIBLE NumericAnimation : public Animation
171  {
176  public: NumericAnimation(const std::string &_name,
177  double _length, bool _loop);
178 
180  public: virtual ~NumericAnimation();
181 
185  public: NumericKeyFrame *CreateKeyFrame(double _time);
186 
190  public: void GetInterpolatedKeyFrame(NumericKeyFrame &_kf) const;
191  };
193  }
194 }
195 
196 #endif
bool build
determines if the interpolation splines need building
Definition: Animation.hh:111
bool loop
true if animation repeats
Definition: Animation.hh:114
KeyFrame_V keyFrames
array of key frames
Definition: Animation.hh:120
double timePos
current time position
Definition: Animation.hh:108
Forward declarations for the common classes.
Definition: Animation.hh:33
A numeric animation.
Definition: Animation.hh:170
std::string name
animation name
Definition: Animation.hh:102
A keyframe for a NumericAnimation.
Definition: KeyFrame.hh:88
double length
animation duration
Definition: Animation.hh:105
std::vector< KeyFrame * > KeyFrame_V
array of keyframe type alias
Definition: Animation.hh:117
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition: Animation.hh:50
A keyframe for a PoseAnimation.
Definition: KeyFrame.hh:55
A key frame in an animation.
Definition: KeyFrame.hh:37
A pose animation.
Definition: Animation.hh:128
Definition: Animation.hh:24