90 lines
3.0 KiB
Plaintext
90 lines
3.0 KiB
Plaintext
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
//as published by the Free Software Foundation.
|
|
|
|
#ifndef OSG_ANIMATIONPATH
|
|
#define OSG_ANIMATIONPATH 1
|
|
|
|
#include <osg/Matrix>
|
|
#include <osg/Quat>
|
|
#include <osg/Transform>
|
|
|
|
#include <map>
|
|
|
|
namespace osg {
|
|
|
|
/** AnimationPath for specify the time varying transformation pathway to use when update camera and model objects.
|
|
* Subclassed from Transform::ComputeTransformCallback allows AnimationPath to
|
|
* be attached directly to Transform nodes to move subgraphs around the scene.
|
|
*/
|
|
class SG_EXPORT AnimationPath : public Transform::ComputeTransformCallback
|
|
{
|
|
public:
|
|
|
|
AnimationPath() {}
|
|
|
|
/** get the local transformation matrix for a point in time.*/
|
|
virtual bool getMatrix(double time,Matrix& matrix) const;
|
|
|
|
/** get the local inverse transformation matrix for a point in time.*/
|
|
virtual bool getInverse(double time,Matrix& matrix) const;
|
|
|
|
/** Get the transformation matrix which moves from local coords to world coords.*/
|
|
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const;
|
|
|
|
/** Get the transformation matrix which moves from world coords to local coords.*/
|
|
virtual const bool computeWorldToLocalMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const;
|
|
|
|
struct Key
|
|
{
|
|
Key() {}
|
|
|
|
Key(const osg::Vec3& position, const osg::Quat& rotation, const osg::Vec3& scale):
|
|
_position(position),
|
|
_rotation(rotation),
|
|
_scale(scale) {}
|
|
|
|
osg::Vec3 _position;
|
|
osg::Quat _rotation;
|
|
osg::Vec3 _scale;
|
|
|
|
inline void interpolate(const float ratio,const Key& first, const Key& second)
|
|
{
|
|
float one_minus_ratio = 1.0f-ratio;
|
|
_position = first._position*one_minus_ratio + second._position*ratio;
|
|
_rotation.slerp(ratio,first._rotation,second._rotation);
|
|
_scale = first._scale*one_minus_ratio + second._scale*ratio;
|
|
}
|
|
|
|
inline void getMatrix(Matrix& matrix) const
|
|
{
|
|
matrix.makeScale(_scale);
|
|
matrix.postMult(_rotation.getMatrix());
|
|
matrix.postMult(osg::Matrix::translate(_position));
|
|
}
|
|
|
|
inline void getInverse(Matrix& matrix) const
|
|
{
|
|
matrix.makeScale(1.0f/_scale.x(),1.0f/_scale.y(),1.0f/_scale.y());
|
|
matrix.postMult(_rotation.inverse().getMatrix());
|
|
matrix.postMult(osg::Matrix::translate(-_position));
|
|
}
|
|
};
|
|
|
|
|
|
void insert(double time,const Key& key);
|
|
|
|
protected:
|
|
|
|
virtual ~AnimationPath() {}
|
|
|
|
typedef std::map<double,Key> TimeKeyMap;
|
|
|
|
TimeKeyMap _timeKeyMap;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|