OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnimationPathManipulator.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGGA_ANIMATION_PATH_MANIPULATOR
15 #define OSGGA_ANIMATION_PATH_MANIPULATOR 1
16 
17 #include <osg/AnimationPath>
18 #include <osg/Notify>
19 #include <osgGA/CameraManipulator>
20 
21 namespace osgGA{
22 
23 //
24 // The AnimationPathManipulator is a Matrix Manipulator that reads an
25 // animation path from a file and plays it back. The file is expected
26 // to be ascii and a succession of lines with 8 floating point values
27 // per line. The succession of values are:
28 // time px py pz ax ay az aw
29 // where:
30 // time = elapsed time in seconds from the beginning of the animation
31 // px py pz = World position in cartesian coordinates
32 // ax ay az aw = Orientation (attitude) defined as a quaternion
33 
35 {
36  public:
37 
38  AnimationPathManipulator( osg::AnimationPath* animationPath=0 );
39 
40  AnimationPathManipulator( const std::string& filename );
41 
42  virtual const char* className() const { return "AnimationPath"; }
43 
44  void setTimeScale(double s) { _timeScale = s; }
45  double getTimeScale() const { return _timeScale; }
46 
47  void setTimeOffset(double o) { _timeOffset = o; }
48  double getTimeOffset() const { return _timeOffset; }
49 
51  {
52  virtual void completed(const AnimationPathManipulator* apm) = 0;
53  };
54 
55  void setAnimationCompletedCallback(AnimationCompletedCallback* acc) { _animationCompletedCallback = acc; }
56  AnimationCompletedCallback* getAnimationCompletedCallback() { return _animationCompletedCallback.get(); }
57  const AnimationCompletedCallback* getAnimationCompletedCallback() const { return _animationCompletedCallback.get(); }
58 
59  void setPrintOutTimingInfo(bool printOutTimingInfo) { _printOutTimingInfo=printOutTimingInfo; }
60  bool getPrintOutTimingInfo() const { return _printOutTimingInfo; }
61 
63  virtual void setByMatrix(const osg::Matrixd& matrix) { _matrix = matrix; }
64 
66  virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _matrix.invert(matrix); }
67 
69  virtual osg::Matrixd getMatrix() const { return _matrix; }
70 
72  virtual osg::Matrixd getInverseMatrix() const { return osg::Matrixd::inverse(_matrix); }
73 
74 
75  void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; }
76 
77  osg::AnimationPath* getAnimationPath() { return _animationPath.get(); }
78 
79  const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); }
80 
81  bool valid() const { return _animationPath.valid(); }
82 
83  void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
84 
85  void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
86  void home(double currentTime);
87 
88  virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
89 
91  virtual void getUsage(osg::ApplicationUsage& usage) const;
92 
93  protected:
94 
95  bool _valid;
96 
98 
99  void handleFrame( double time );
100 
102 
103  double _timeOffset;
104  double _timeScale;
105 
107 
108  double _pauseTime;
109  bool _isPaused;
110 
114 
116 
117 };
118 
119 }
120 
121 #endif
virtual const char * className() const
AnimationCompletedCallback * getAnimationCompletedCallback()
virtual void setByMatrix(const osg::Matrixd &matrix)
#define OSGGA_EXPORT
Definition: Export.h:40
virtual osg::Matrixd getInverseMatrix() const
static Matrixd inverse(const Matrixd &matrix)
Definition: Matrixd.h:530
virtual osg::Matrixd getMatrix() const
void setAnimationCompletedCallback(AnimationCompletedCallback *acc)
void setPrintOutTimingInfo(bool printOutTimingInfo)
void setAnimationPath(osg::AnimationPath *animationPath)
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
osg::ref_ptr< osg::AnimationPath > _animationPath
const AnimationCompletedCallback * getAnimationCompletedCallback() const
const osg::AnimationPath * getAnimationPath() const
osg::ref_ptr< AnimationCompletedCallback > _animationCompletedCallback