|
发表于 2016-3-23 09:15:35
|
显示全部楼层
官方例子太长了,我也没用过。但博客里给出了最简单的代码,虽然不完整。
osg::Group *root = new osg::Group();
osg::AnimationPath *ap = new osg::AnimationPath();
ap->setLoopMode(osg::AnimationPath:OOP);
ap->insert(0.0, osg::AnimationPath::ControlPoint(osg::Vec3(0, 0, 0)));
ap->insert(5.0, osg::AnimationPath::ControlPoint(osg::Vec3(20, 0, 0)));
ap->insert(10.0, osg::AnimationPath::ControlPoint(osg::Vec3(0, 0, 0)));
osg::AnimationPathCallback *apc = new osg::AnimationPathCallback();
apc->setAnimationPath(ap);
osg::MatrixTransform *mt = new osg::MatrixTransform();
mt->addUpdateCallback(apc);
osg::Node *glider = osgDB::readNodeFile("cessna.osg");
mt->addChild(glider);
root->addChild(mt);
osgGA::NodeTrackerManipulator *tm = new osgGA::NodeTrackerManipulator();
tm->setTrackerMode(osgGA::NodeTrackerManipulator::NODE_CENTER_AND_ROTATION);
tm->setRotationMode(osgGA::NodeTrackerManipulator::TRACKBALL);
tm->setTrackNode(glider);
root->addChild(osgDB::readNodeFile("cow.osg")); //作为参考
osgViewer::Viewer viewer;
viewer.setCameraManipulator(tm);
viewer.setSceneData(root);
viewer.setUpViewInWindow(20, 20, 1000, 800);
viewer.addEventHandler(new osgViewer::StatsHandler());
return viewer.run(); |
|