2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-10-08 15:39:38 +08:00
|
|
|
|
|
|
|
#ifndef OSGGA_ANIMATION_PATH_MANIPULATOR
|
|
|
|
#define OSGGA_ANIMATION_PATH_MANIPULATOR 1
|
|
|
|
|
|
|
|
#include <osg/AnimationPath>
|
|
|
|
#include <osg/Notify>
|
2010-05-27 23:54:37 +08:00
|
|
|
#include <osgGA/CameraManipulator>
|
2002-10-08 15:39:38 +08:00
|
|
|
|
|
|
|
namespace osgGA{
|
|
|
|
|
|
|
|
//
|
2003-10-28 00:07:21 +08:00
|
|
|
// The AnimationPathManipulator is a Matrix Manipulator that reads an
|
2002-10-08 15:39:38 +08:00
|
|
|
// animation path from a file and plays it back. The file is expected
|
|
|
|
// to be ascii and a succession of lines with 8 floating point values
|
|
|
|
// per line. The succession of values are:
|
|
|
|
// time px py pz ax ay az aw
|
|
|
|
// where:
|
2007-12-11 01:30:18 +08:00
|
|
|
// time = elapsed time in seconds from the beginning of the animation
|
|
|
|
// px py pz = World position in cartesian coordinates
|
2002-10-08 15:39:38 +08:00
|
|
|
// ax ay az aw = Orientation (attitude) defined as a quaternion
|
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
|
2002-10-08 15:39:38 +08:00
|
|
|
{
|
|
|
|
public:
|
2002-10-08 22:10:55 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
AnimationPathManipulator( osg::AnimationPath* animationPath=0 );
|
2002-10-08 22:10:55 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
AnimationPathManipulator( const std::string& filename );
|
2002-10-08 22:10:55 +08:00
|
|
|
|
2003-02-19 18:43:02 +08:00
|
|
|
virtual const char* className() const { return "AnimationPath"; }
|
2003-09-26 19:20:43 +08:00
|
|
|
|
2010-12-15 04:07:00 +08:00
|
|
|
void setTimeScale(double s) { _timeScale = s; }
|
|
|
|
double getTimeScale() const { return _timeScale; }
|
|
|
|
|
|
|
|
void setTimeOffset(double o) { _timeOffset = o; }
|
|
|
|
double getTimeOffset() const { return _timeOffset; }
|
|
|
|
|
|
|
|
struct AnimationCompletedCallback : public virtual osg::Referenced
|
|
|
|
{
|
|
|
|
virtual void completed(const AnimationPathManipulator* apm) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setAnimationCompletedCallback(AnimationCompletedCallback* acc) { _animationCompletedCallback = acc; }
|
|
|
|
AnimationCompletedCallback* getAnimationCompletedCallback() { return _animationCompletedCallback.get(); }
|
|
|
|
const AnimationCompletedCallback* getAnimationCompletedCallback() const { return _animationCompletedCallback.get(); }
|
|
|
|
|
2007-07-11 23:51:17 +08:00
|
|
|
void setPrintOutTimingInfo(bool printOutTimingInfo) { _printOutTimingInfo=printOutTimingInfo; }
|
|
|
|
bool getPrintOutTimingInfo() const { return _printOutTimingInfo; }
|
2002-10-08 22:10:55 +08:00
|
|
|
|
2003-05-19 23:15:17 +08:00
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual void setByMatrix(const osg::Matrixd& matrix) { _matrix = matrix; }
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _matrix.invert(matrix); }
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
/** get the position of the manipulator as 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual osg::Matrixd getMatrix() const { return _matrix; }
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual osg::Matrixd getInverseMatrix() const { return osg::Matrixd::inverse(_matrix); }
|
2003-05-19 23:15:17 +08:00
|
|
|
|
|
|
|
|
2002-10-08 22:10:55 +08:00
|
|
|
void setAnimationPath( osg::AnimationPath* animationPath ) { _animationPath=animationPath; }
|
|
|
|
|
|
|
|
osg::AnimationPath* getAnimationPath() { return _animationPath.get(); }
|
|
|
|
|
|
|
|
const osg::AnimationPath* getAnimationPath() const { return _animationPath.get(); }
|
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
bool valid() const { return _animationPath.valid(); }
|
2002-10-08 22:10:55 +08:00
|
|
|
|
2002-11-06 18:24:33 +08:00
|
|
|
void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
|
|
|
|
|
|
|
void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
2005-03-21 07:57:17 +08:00
|
|
|
void home(double currentTime);
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2002-10-08 22:10:55 +08:00
|
|
|
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
2003-02-19 18:43:02 +08:00
|
|
|
|
|
|
|
/** Get the keyboard and mouse usage of this manipulator.*/
|
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
2002-10-08 22:10:55 +08:00
|
|
|
|
2003-03-28 01:20:21 +08:00
|
|
|
protected:
|
2002-10-08 15:39:38 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
bool _valid;
|
2003-09-26 19:20:43 +08:00
|
|
|
|
2007-07-11 23:51:17 +08:00
|
|
|
bool _printOutTimingInfo;
|
2002-10-08 15:39:38 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
void handleFrame( double time );
|
2002-10-08 15:39:38 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
osg::ref_ptr<osg::AnimationPath> _animationPath;
|
2002-11-06 18:24:33 +08:00
|
|
|
|
2003-04-09 04:06:37 +08:00
|
|
|
double _timeOffset;
|
|
|
|
double _timeScale;
|
2010-12-15 04:07:00 +08:00
|
|
|
|
|
|
|
osg::ref_ptr<AnimationCompletedCallback> _animationCompletedCallback;
|
|
|
|
|
2003-04-09 04:06:37 +08:00
|
|
|
double _pauseTime;
|
|
|
|
bool _isPaused;
|
|
|
|
|
|
|
|
double _realStartOfTimedPeriod;
|
|
|
|
double _animStartOfTimedPeriod;
|
|
|
|
int _numOfFramesSinceStartOfTimedPeriod;
|
2003-05-19 23:15:17 +08:00
|
|
|
|
2003-09-06 06:35:34 +08:00
|
|
|
osg::Matrixd _matrix;
|
2002-10-08 15:39:38 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|