Updated to slideshow3D to support animation + pausing of animation.
Updated associated osg/osgUtil classes that provide animation pausing.
This commit is contained in:
@@ -82,30 +82,72 @@ bool AnimationPath::getInterpolatedControlPoint(double time,ControlPoint& contro
|
||||
}
|
||||
|
||||
|
||||
void AnimationPath::read(std::istream& in)
|
||||
{
|
||||
while (!in.eof())
|
||||
{
|
||||
double time;
|
||||
osg::Vec3 position;
|
||||
osg::Quat rotation;
|
||||
in >> time >> position.x() >> position.y() >> position.z() >> rotation.x() >> rotation.y() >> rotation.z() >> rotation.w();
|
||||
if(!in.eof())
|
||||
insert(time,osg::AnimationPath::ControlPoint(position,rotation));
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationPath::write(std::ostream& fout)
|
||||
{
|
||||
const TimeControlPointMap& tcpm = getTimeControlPointMap();
|
||||
for(TimeControlPointMap::const_iterator tcpmitr=tcpm.begin();
|
||||
tcpmitr!=tcpm.end();
|
||||
++tcpmitr)
|
||||
{
|
||||
const ControlPoint& cp = tcpmitr->second;
|
||||
fout<<tcpmitr->first<<" "<<cp._position<<" "<<cp._rotation<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
class AnimationPathCallbackVisitor : public NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp):
|
||||
_cp(cp) {}
|
||||
AnimationPathCallbackVisitor(const AnimationPath::ControlPoint& cp, bool useInverseMatrix):
|
||||
_cp(cp),
|
||||
_useInverseMatrix(useInverseMatrix) {}
|
||||
|
||||
virtual void apply(MatrixTransform& mt)
|
||||
{
|
||||
Matrix matrix;
|
||||
_cp.getMatrix(matrix);
|
||||
if (_useInverseMatrix)
|
||||
_cp.getInverse(matrix);
|
||||
else
|
||||
_cp.getMatrix(matrix);
|
||||
|
||||
mt.setMatrix(matrix);
|
||||
}
|
||||
|
||||
virtual void apply(PositionAttitudeTransform& pat)
|
||||
{
|
||||
pat.setPosition(_cp._position);
|
||||
pat.setAttitude(_cp._rotation);
|
||||
if (_useInverseMatrix)
|
||||
{
|
||||
Matrix matrix;
|
||||
_cp.getInverse(matrix);
|
||||
pat.setPosition(matrix.getTrans());
|
||||
pat.setAttitude(_cp._rotation.inverse());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
pat.setPosition(_cp._position);
|
||||
pat.setAttitude(_cp._rotation);
|
||||
}
|
||||
}
|
||||
|
||||
AnimationPath::ControlPoint _cp;
|
||||
|
||||
bool _useInverseMatrix;
|
||||
};
|
||||
|
||||
|
||||
void AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
|
||||
{
|
||||
if (_animationPath.valid() &&
|
||||
@@ -113,19 +155,52 @@ void AnimationPathCallback::operator()(Node* node, NodeVisitor* nv)
|
||||
nv->getFrameStamp())
|
||||
{
|
||||
double time = nv->getFrameStamp()->getReferenceTime();
|
||||
if (_firstTime==0.0) _firstTime = time;
|
||||
|
||||
_animationTime = ((time-_firstTime)-_timeOffset)*_timeMultiplier;
|
||||
|
||||
AnimationPath::ControlPoint cp;
|
||||
if (_animationPath->getInterpolatedControlPoint(_animationTime,cp))
|
||||
_latestTime = time;
|
||||
|
||||
if (!_pause)
|
||||
{
|
||||
AnimationPathCallbackVisitor apcv(cp);
|
||||
node->accept(apcv);
|
||||
if (_firstTime==0.0) _firstTime = time;
|
||||
update(*node);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
NodeCallback::traverse(node,nv);
|
||||
}
|
||||
|
||||
void AnimationPathCallback::update(osg::Node& node)
|
||||
{
|
||||
double animationTime = ((_latestTime-_firstTime)-_timeOffset)*_timeMultiplier;
|
||||
|
||||
AnimationPath::ControlPoint cp;
|
||||
if (_animationPath->getInterpolatedControlPoint(animationTime,cp))
|
||||
{
|
||||
AnimationPathCallbackVisitor apcv(cp,_useInverseMatrix);
|
||||
node.accept(apcv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AnimationPathCallback::reset()
|
||||
{
|
||||
_firstTime = _latestTime;
|
||||
_pauseTime = _latestTime;
|
||||
}
|
||||
|
||||
void AnimationPathCallback::setPause(bool pause)
|
||||
{
|
||||
if (_pause==pause)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pause = pause;
|
||||
if (_pause)
|
||||
{
|
||||
_pauseTime = _latestTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_firstTime += (_latestTime-_pauseTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ Registry::Registry()
|
||||
// comment out because it was causing problems under OSX - causing it to crash osgconv when constucting ostream in osg::notify().
|
||||
// notify(INFO) << "Constructing osg::Registry"<<std::endl;
|
||||
|
||||
_createNodeFromImage = true;
|
||||
_createNodeFromImage = false;
|
||||
_openingLibrary = false;
|
||||
|
||||
_useObjectCacheHint = false;
|
||||
|
||||
@@ -37,15 +37,7 @@ AnimationPathManipulator::AnimationPathManipulator( const std::string& filename
|
||||
return;
|
||||
}
|
||||
|
||||
while (!in.eof())
|
||||
{
|
||||
double time;
|
||||
osg::Vec3 position;
|
||||
osg::Quat rotation;
|
||||
in >> time >> position.x() >> position.y() >> position.z() >> rotation.x() >> rotation.y() >> rotation.z() >> rotation.w();
|
||||
if(!in.eof())
|
||||
_animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
|
||||
}
|
||||
_animationPath->read(in);
|
||||
|
||||
in.close();
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ void AnimationPathCallback::write(DataOutputStream* out){
|
||||
out->writeDouble(_timeOffset);
|
||||
out->writeDouble(_timeMultiplier);
|
||||
out->writeDouble(_firstTime);
|
||||
out->writeDouble(_animationTime);
|
||||
out->writeDouble(_pauseTime);
|
||||
// Write animationpath if any
|
||||
if(getAnimationPath())
|
||||
{
|
||||
@@ -64,7 +64,7 @@ void AnimationPathCallback::read(DataInputStream* in){
|
||||
_timeOffset = in->readDouble();
|
||||
_timeMultiplier = in->readDouble();
|
||||
_firstTime = in->readDouble();
|
||||
_animationTime = in->readDouble();
|
||||
_pauseTime = in->readDouble();
|
||||
// Read animationpath if any
|
||||
if(in->readInt())
|
||||
{
|
||||
|
||||
@@ -829,14 +829,7 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio
|
||||
if (viewer->getAnimationPath())
|
||||
{
|
||||
std::ofstream fout("saved_animation.path");
|
||||
const osg::AnimationPath::TimeControlPointMap& tcpm = viewer->getAnimationPath()->getTimeControlPointMap();
|
||||
for(osg::AnimationPath::TimeControlPointMap::const_iterator tcpmitr=tcpm.begin();
|
||||
tcpmitr!=tcpm.end();
|
||||
++tcpmitr)
|
||||
{
|
||||
const osg::AnimationPath::ControlPoint& cp = tcpmitr->second;
|
||||
fout<<tcpmitr->first<<" "<<cp._position<<" "<<cp._rotation<<std::endl;
|
||||
}
|
||||
viewer->getAnimationPath()->write(fout);
|
||||
fout.close();
|
||||
|
||||
osg::notify(osg::NOTICE) << "Saved camera animation to 'saved_animation.path'"<< std::endl;
|
||||
|
||||
@@ -24,6 +24,8 @@ TransformCallback::TransformCallback(const osg::Vec3& pivot,const osg::Vec3& axi
|
||||
|
||||
_previousTraversalNumber = -1;
|
||||
_previousTime = -1.0;
|
||||
|
||||
_pause = false;
|
||||
}
|
||||
|
||||
void TransformCallback::operator() (osg::Node* node, osg::NodeVisitor* nv)
|
||||
@@ -34,14 +36,14 @@ void TransformCallback::operator() (osg::Node* node, osg::NodeVisitor* nv)
|
||||
|
||||
const osg::FrameStamp* fs = nv->getFrameStamp();
|
||||
if (!fs) return; // not frame stamp, no handle on the time so can't move.
|
||||
|
||||
|
||||
double newTime = fs->getReferenceTime();
|
||||
|
||||
// ensure that we do not operate on this node more than
|
||||
// once during this traversal. This is an issue since node
|
||||
// can be shared between multiple parents.
|
||||
if (nv->getTraversalNumber()!=_previousTraversalNumber)
|
||||
if (!_pause && nv->getTraversalNumber()!=_previousTraversalNumber)
|
||||
{
|
||||
double newTime = fs->getReferenceTime();
|
||||
float delta_angle = _angular_velocity*(newTime-_previousTime);
|
||||
|
||||
osg::Matrix mat = osg::Matrix::translate(-_pivot)*
|
||||
@@ -53,8 +55,10 @@ void TransformCallback::operator() (osg::Node* node, osg::NodeVisitor* nv)
|
||||
transform->preMult(mat);
|
||||
|
||||
_previousTraversalNumber = nv->getTraversalNumber();
|
||||
_previousTime = newTime;
|
||||
}
|
||||
|
||||
_previousTime = newTime;
|
||||
|
||||
}
|
||||
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
|
||||
Reference in New Issue
Block a user