OpenIG  2.0.4
cross-platform open-source OpenSceneGraph Image Generator
Animation.h
Go to the documentation of this file.
1 //#******************************************************************************
2 //#*
3 //#* Copyright (C) 2015 Compro Computer Services
4 //#* http://openig.compro.net
5 //#*
6 //#* Source available at: https://github.com/CCSI-CSSI/MuseOpenIG
7 //#*
8 //#* This software is released under the LGPL.
9 //#*
10 //#* This software is free software; you can redistribute it and/or modify
11 //#* it under the terms of the GNU Lesser General Public License as published
12 //#* by the Free Software Foundation; either version 2.1 of the License, or
13 //#* (at your option) any later version.
14 //#*
15 //#* This software is distributed in the hope that it will be useful,
16 //#* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 //#* the GNU Lesser General Public License for more details.
19 //#*
20 //#* You should have received a copy of the GNU Lesser General Public License
21 //#* along with this library; if not, write to the Free Software
22 //#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //#*
24 //#* Please direct any questions or comments to the OpenIG Forums
25 //#* Email address: openig@compro.net
26 //#*
27 //#*
28 //#* Please direct any questions or comments to the OpenIG Forums
29 //#* Email address: openig@compro.net
30 //#*
31 //#*
32 //#*****************************************************************************
33 
34 #ifndef ANIMATION_H
35 #define ANIMATION_H
36 
37 #if defined(OPENIG_SDK)
38  #include <OpenIG-Base/Export.h>
39  #include <OpenIG-Base/ImageGenerator.h>
40 #else
41  #include <Core-Base/Export.h>
42  #include <Core-Base/ImageGenerator.h>
43 #endif
44 
45 #include <osg/Referenced>
46 #include <osg/ref_ptr>
47 #include <osg/Vec3>
48 #include <osg/Timer>
49 
50 #include <utility>
51 #include <vector>
52 #include <string>
53 #include <map>
54 
55 namespace OpenIG {
56  namespace Base {
57 
69  class IGCORE_EXPORT AnimationSequencePlaybackCallback : public osg::Referenced
70  {
71  public:
82  virtual bool operator()(double value) = 0;
83  };
84 
85  typedef std::map< std::string, osg::ref_ptr< AnimationSequencePlaybackCallback > > AnimationSequenceCallbacks;
86  typedef std::map< std::string, osg::ref_ptr< AnimationSequencePlaybackCallback > >::iterator AnimationSequenceCallbacksIterator;
87  typedef std::map< std::string, osg::ref_ptr< AnimationSequencePlaybackCallback > >::const_iterator AnimationSequenceCallbacksConstIterator;
88 
89  class IGCORE_EXPORT RefAnimationSequenceCallbacks : public AnimationSequenceCallbacks, public osg::Referenced {};
90 
98  class IGCORE_EXPORT Animations
99  {
100  protected:
107  Animations();
108 
115  ~Animations();
116 
117  public:
125  static Animations* instance();
126 
136  struct Animation : public osg::Referenced
137  {
138  Animation() : _duration(0.0) {}
139  Animation(const std::string& name, double duration)
140  : _name(name)
141  , _duration(duration)
142  {
143 
144  }
145 
154  struct Sequence : public osg::Referenced
155  {
156  Sequence() : _swapPitchRoll(false), _enabled(true) {}
157 
159  std::string _name;
161  std::string _player;
163  std::pair<double, double> _timeFrame;
165  osg::Vec3 _operationVector;
167  std::pair<double, double> _rotationUpdate;
171  std::pair<osg::Vec3, osg::Vec3> _positionalUpdate;
174  unsigned int _playerId;
183  bool _enabled;
184  };
185 
186 
188  typedef std::map< std::string, osg::ref_ptr<Sequence> > SequencesMap;
189  typedef std::map< std::string, osg::ref_ptr<Sequence> >::iterator SequencesMapIterator;
190  typedef std::map< std::string, osg::ref_ptr<Sequence> >::const_iterator SequencesMapConstIterator;
191 
193  SequencesMap _sequences;
195  std::string _name;
197  double _duration;
198 
199  };
200 
202  struct AnimationContainer : public std::map< std::string, osg::ref_ptr< Animation > >, public osg::Referenced {};
203 
216  void playAnimation(OpenIG::Base::ImageGenerator* ig, unsigned int entityId, const std::string& name, RefAnimationSequenceCallbacks* cbs = 0);
217 
229  void stopAnimation(OpenIG::Base::ImageGenerator* ig, unsigned int entityId, const std::string& name);
230 
242  void resetAnimation(OpenIG::Base::ImageGenerator* ig, unsigned int entityId, const std::string& name);
243 
255  void pauseResumeAnimation(OpenIG::Base::ImageGenerator* ig, unsigned int entityId, const std::string& name, bool pauseResume = true);
256 
257 
266  void updateAnimations(OpenIG::Base::ImageGenerator* ig);
267 
268  protected:
275  struct RuntimeAnimation : osg::Referenced
276  {
277  RuntimeAnimation() : _startTime(0), _pauseTime(0), _pausedTime(0.0), _entityId(0), _resumed(false) {}
278 
279  osg::Timer_t _startTime;
280  osg::Timer_t _pauseTime;
281  double _pausedTime;
282  osg::observer_ptr< Animation > _animation;
283  unsigned int _entityId;
284  osg::ref_ptr<RefAnimationSequenceCallbacks> _sequenceCallbacks;
285  bool _resumed;
286  };
287 
288  typedef std::vector< osg::ref_ptr<RuntimeAnimation> > RuntimeAnimations;
289  typedef std::vector< osg::ref_ptr<RuntimeAnimation> >::iterator RuntimeAnimationsIterator;
290  typedef std::vector< osg::ref_ptr<RuntimeAnimation> >::const_iterator RuntimeAnimationsConstIterator;
291 
293  RuntimeAnimations _animations;
294  };
295  } // namespace
296 } // namespace
297 
298 #endif // ANIMATION_H
Definition: ImageGenerator.h:62
Referenced pointer of std::vector of Animation.
Definition: Animation.h:202
The Animation struct.
Definition: Animation.h:136
osg::Vec3 _positionalOperationVector
The vector of the linear interpolation of the positional update.
Definition: Animation.h:169
The Animations class.
Definition: Animation.h:98
std::pair< double, double > _timeFrame
The time in seconds of this sequence.
Definition: Animation.h:163
std::string _name
Name of the Animation.
Definition: Animation.h:195
std::pair< double, double > _rotationUpdate
The update of the orientation along the _operationVector
Definition: Animation.h:167
osg::Vec3 _playerOriginalPosition
The original player position.
Definition: Animation.h:178
SequencesMap _sequences
Name std::string based map of Sequence.
Definition: Animation.h:193
std::string _name
The name of the Sequence.
Definition: Animation.h:159
osg::Vec3 _operationVector
The vector of the linear interpolation of the orientation.
Definition: Animation.h:165
bool _enabled
Enabled or disabled, if false the sequence is not processed.
Definition: Animation.h:183
The Image Generator abstract interface. This is base class for openig::OpenIG.
Definition: ImageGenerator.h:74
std::map< std::string, osg::ref_ptr< Sequence > > SequencesMap
Name std::string based map of Sequence.
Definition: Animation.h:188
unsigned int _playerId
The ID of the player. Since our players are OpenIG::Base::ImageGenerator::Entity this is the ID...
Definition: Animation.h:174
The AnimationSequencePlaybackCallback class.
Definition: Animation.h:69
The RuntimeAnimation struct.
Definition: Animation.h:275
std::string _player
The name of the player.
Definition: Animation.h:161
The Sequence struct.
Definition: Animation.h:154
double _duration
Duration of the animation in seconds.
Definition: Animation.h:197
bool _swapPitchRoll
flags to swap pitch and roll in the animation playback computation It is introduced to cover the vari...
Definition: Animation.h:181
std::pair< osg::Vec3, osg::Vec3 > _positionalUpdate
The update of the position
Definition: Animation.h:171
osg::Vec3 _playerOriginalOrientation
The original player orientation.
Definition: Animation.h:176
RuntimeAnimations _animations
std::vector of RuntimeAnimation
Definition: Animation.h:293