root/OpenSceneGraph/trunk/include/osgGA/AnimationPathManipulator @ 13041

Revision 13041, 4.4 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
21namespace 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
34class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
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
50        struct AnimationCompletedCallback : public virtual osg::Referenced
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
62        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
63        virtual void setByMatrix(const osg::Matrixd& matrix) { _matrix = matrix; }
64
65        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
66        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _matrix.invert(matrix); }
67
68        /** get the position of the manipulator as 4x4 Matrix.*/
69        virtual osg::Matrixd getMatrix() const { return _matrix; }
70
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); }
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
90        /** Get the keyboard and mouse usage of this manipulator.*/
91        virtual void getUsage(osg::ApplicationUsage& usage) const;
92
93    protected:
94
95        bool _valid;
96
97        bool _printOutTimingInfo;
98
99        void handleFrame( double time );
100
101        osg::ref_ptr<osg::AnimationPath> _animationPath;
102
103        double  _timeOffset;
104        double  _timeScale;
105
106        osg::ref_ptr<AnimationCompletedCallback> _animationCompletedCallback;
107
108        double  _pauseTime;
109        bool    _isPaused;
110
111        double  _realStartOfTimedPeriod;
112        double  _animStartOfTimedPeriod;
113        int     _numOfFramesSinceStartOfTimedPeriod;
114
115        osg::Matrixd _matrix;
116
117};
118
119}
120
121#endif
Note: See TracBrowser for help on using the browser.