1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGGA_ANIMATION_PATH_MANIPULATOR
15#define OSGGA_ANIMATION_PATH_MANIPULATOR 1
17#include <osg/AnimationPath>
19#include <osgGA/CameraManipulator>
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
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
34class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
38 AnimationPathManipulator( osg::AnimationPath* animationPath=0 );
40 AnimationPathManipulator( const std::string& filename );
42 virtual const char* className() const { return "AnimationPath"; }
44 void setTimeScale(double s) { _timeScale = s; }
45 double getTimeScale() const { return _timeScale; }
47 void setTimeOffset(double o) { _timeOffset = o; }
48 double getTimeOffset() const { return _timeOffset; }
50 struct AnimationCompletedCallback : public virtual osg::Referenced
52 virtual void completed(const AnimationPathManipulator* apm) = 0;
55 void setAnimationCompletedCallback(AnimationCompletedCallback* acc) { _animationCompletedCallback = acc; }
56 AnimationCompletedCallback* getAnimationCompletedCallback() { return _animationCompletedCallback.get(); }
57 const AnimationCompletedCallback* getAnimationCompletedCallback() const { return _animationCompletedCallback.get(); }
59 void setPrintOutTimingInfo(bool printOutTimingInfo) { _printOutTimingInfo=printOutTimingInfo; }
60 bool getPrintOutTimingInfo() const { return _printOutTimingInfo; }
62 /** set the position of the matrix manipulator using a 4x4 Matrix.*/
63 virtual void setByMatrix(const osg::Matrixd& matrix) { _matrix = matrix; }
65 /** set the position of the matrix manipulator using a 4x4 Matrix.*/
66 virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _matrix.invert(matrix); }
68 /** get the position of the manipulator as 4x4 Matrix.*/
69 virtual osg::Matrixd getMatrix() const { return _matrix; }
71 /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
72 virtual osg::Matrixd getInverseMatrix() const { return osg::Matrixd::inverse(_matrix); }
75 void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; }
77 osg::AnimationPath* getAnimationPath() { return _animationPath.get(); }
79 const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); }
81 bool valid() const { return _animationPath.valid(); }
83 void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
85 void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
86 void home(double currentTime);
88 virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
90 /** Get the keyboard and mouse usage of this manipulator.*/
91 virtual void getUsage(osg::ApplicationUsage& usage) const;
97 bool _printOutTimingInfo;
99 void handleFrame( double time );
101 osg::ref_ptr<osg::AnimationPath> _animationPath;
106 osg::ref_ptr<AnimationCompletedCallback> _animationCompletedCallback;
111 double _realStartOfTimedPeriod;
112 double _animStartOfTimedPeriod;
113 int _numOfFramesSinceStartOfTimedPeriod;
115 osg::Matrixd _matrix;