|
本帖最后由 wanghuisoftware 于 2012-2-25 23:22 编辑
请问,我将路径漫游过程的视图保存为图片序列,通过一个新建的相机实现。具体思路可参考下述代码:
//建立动画路径
osg::ref_ptr<osg::AnimationPath> _animationPath = new osg::AnimationPath(*(picker->_animPath));
_animationPath->setLoopMode(osg::AnimationPath::NO_LOOPING);
double periodsecond = 1/fps;//!<每一帧的间隔时间,为了保存avi视频是自定义帧数,此不可忽略。
///对新建相机的一些属性进行设置。
osg::ref_ptr<osg::Camera> slaveCamera = new osg::Camera;
//mViewer->addSlave(slaveCamera);
slaveCamera->addChild(mModel);
mRoot->addChild(slaveCamera);
slaveCamera->setProjectionMatrix(mViewer->getCamera()->getProjectionMatrix());
slaveCamera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.6f, 1.0f));
slaveCamera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
slaveCamera->setAllowEventFocus(false);
slaveCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
slaveCamera->setViewport(0,0,width,height);
slaveCamera->setRenderOrder(osg::Camera:RE_RENDER);
slaveCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
osg::ref_ptr<osg::Image> posterImage = 0;
osg::AnimationPath::ControlPoint cp;
//设置路径的时间
double animTime = 0;
//double _timeOffset = _animationPath->getFirstTime()-time;//时间差
osg::Matrixd _matrix;//观察矩阵
osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence;
//判断路径漫游是否播放完毕
while (animTime <= _animationPath->getLastTime())
{
_animationPath->getInterpolatedControlPoint( animTime, cp );
cp.getInverse(_matrix);
posterImage = new osg::Image;
posterImage->allocateImage( width, height, 1, GL_RGB, GL_UNSIGNED_BYTE );
slaveCamera->setViewMatrix(_matrix);//每一次重新设置相机的视点矩阵
slaveCamera->detach( osg::Camera::COLOR_BUFFER );
slaveCamera->attach( osg::Camera::COLOR_BUFFER, posterImage.get(), 0, 0 );
//osgDB::writeImageFile( *image, image->getName()+"."+_outputTileExt );
imageSequence->addImage(posterImage);
osgDB::writeImageFile( *posterImage, "F:\\test.jpg" );
animTime += periodsecond;
}
还望大侠指教! |
|