osgGA::AnimationPathManipulator的使用(实现固定路径漫游)
首先定义AnimationPathManipulato操纵器,在构造函数中输入路径文件名字,然后将其加入键盘选择器(keyswitchManipulator)。
l 可以直接设置操纵器
viewer.setCameraManipulator(apm.get());
l 也可以通过keyswitchManipulator设置
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
viewer.setCameraManipulator( keyswitchManipulator.get() );
l 下面是osgViewer的一段代码:
// set up the camera manipulators.
{
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() );
keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() );
keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() );
keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() );
std::string pathfile;
char keyForAnimationPath = '5';
while (arguments.read("-p",pathfile))
{
osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile);
if (apm || !apm->valid())
{
unsigned int num = keyswitchManipulator->getNumMatrixManipulators();
keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm );
keyswitchManipulator->selectMatrixManipulator(num);
++keyForAnimationPath;
}
}
viewer.setCameraManipulator( keyswitchManipulator.get() );
}