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
26namespace 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
114 };
116
119
121 class GZ_COMMON_VISIBLE PoseAnimation : public Animation
122 {
127 public: PoseAnimation(const std::string &_name,
128 double _length, bool _loop, double _tension = 0.0);
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 private: double tension = 0.0;
159 };
161
164
166 class GZ_COMMON_VISIBLE NumericAnimation : public Animation
167 {
172 public: NumericAnimation(const std::string &_name,
173 double _length, bool _loop);
174
176 public: virtual ~NumericAnimation();
177
181 public: NumericKeyFrame *CreateKeyFrame(double _time);
182
186 public: void GetInterpolatedKeyFrame(NumericKeyFrame &_kf) const;
187 };
189 }
190}
191
192#endif
common
Definition FuelModelDatabase.hh:37
Manages an animation, which is a collection of keyframes and the ability to interpolate between the k...
Definition Animation.hh:44
Animation(const std::string &_name, double _length, bool _loop)
Constructor.
KeyFrame_V keyFrames
array of key frames
Definition Animation.hh:113
double GetTime() const
Return the current time position.
bool loop
true if animation repeats
Definition Animation.hh:107
std::vector< KeyFrame * > KeyFrame_V
array of keyframe type alias
Definition Animation.hh:110
double GetKeyFramesAtTime(double _time, KeyFrame **_kf1, KeyFrame **_kf2, unsigned int &_firstKeyIndex) const
Get the two key frames that bound a time value.
void AddTime(double _time)
Add time to the animation.
double timePos
current time position
Definition Animation.hh:101
KeyFrame * GetKeyFrame(unsigned int _index) const
Get a key frame using an index value.
void SetLength(double _len)
Set the duration of the animation.
virtual ~Animation()
Destructor.
double length
animation duration
Definition Animation.hh:98
std::string name
animation name
Definition Animation.hh:95
bool build
determines if the interpolation splines need building
Definition Animation.hh:104
unsigned int GetKeyFrameCount() const
Return the number of key frames in the animation.
double GetLength() const
Return the duration of the animation.
void SetTime(double _time)
Set the current time position of the animation.
A key frame in an animation.
Definition KeyFrame.hh:36
A numeric animation.
Definition Animation.hh:167
virtual ~NumericAnimation()
Destructor.
NumericKeyFrame * CreateKeyFrame(double _time)
Create a numeric keyframe at the given time.
void GetInterpolatedKeyFrame(NumericKeyFrame &_kf) const
Get a keyframe using the animation's current time.
NumericAnimation(const std::string &_name, double _length, bool _loop)
Constructor.
A keyframe for a NumericAnimation.
Definition KeyFrame.hh:87
A pose animation.
Definition Animation.hh:122
void GetInterpolatedKeyFrame(PoseKeyFrame &_kf) const
Get a keyframe using the animation's current time.
void BuildInterpolationSplines() const
Update the pose splines.
void GetInterpolatedKeyFrame(double _time, PoseKeyFrame &_kf) const
Get a keyframe using a passed in time.
PoseKeyFrame * CreateKeyFrame(double _time)
Create a pose keyframe at the given time.
PoseAnimation(const std::string &_name, double _length, bool _loop, double _tension=0.0)
Constructor.
virtual ~PoseAnimation()
Destructor.
A keyframe for a PoseAnimation.
Definition KeyFrame.hh:54
Forward declarations for the common classes.
Definition Animation.hh:27