|
本帖最后由 buptwenze 于 2011-1-5 21:30 编辑
//在osg下模型可以运动,但是到了osgart中无法运动,,,,
osg::ref_ptr<osg::MatrixTransform> carMT = new osg::MatrixTransform();
carMT->addChild(osgDB::readNodeFile("car.osg"));
carMT->addUpdateCallback(new osg::AnimationPathCallback(slerpPath1));//slerpPath1是路径
// create a root node
osg::ref_ptr<osg::Group> root = new osg::Group;
osgViewer::Viewer viewer;
// attach root node to the viewer
viewer.setSceneData(root.get());
// add relevant handlers to the viewer
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.addEventHandler(new osgViewer::ThreadingHandler);
viewer.addEventHandler(new osgViewer::HelpHandler);
// preload the video and tracker
int _video_id = osgART:luginManager::instance()->load("osgart_video_artoolkit2");
int _tracker_id = osgART::PluginManager::instance()->load("osgart_tracker_artoolkit2");
// Load a video plugin.
osg::ref_ptr<osgART::Video> video =
dynamic_cast<osgART::Video*>(osgART::PluginManager::instance()->get(_video_id));
// check if an instance of the video stream could be started
if (!video.valid())
{
// Without video an AR application can not work. Quit if none found.
osg::notify(osg::FATAL) << "Could not initialize video plugin!" << std::endl;
exit(-1);
}
// Open the video. This will not yet start the video stream but will
// get information about the format of the video which is essential
// for the connected tracker
video->open();
osg::ref_ptr<osgART::Tracker> tracker =
dynamic_cast<osgART::Tracker*>(osgART::PluginManager::instance()->get(_tracker_id));
if (!tracker.valid())
{
// Without tracker an AR application can not work. Quit if none found.
osg::notify(osg::FATAL) << "Could not initialize tracker plugin!" << std::endl;
exit(-1);
}
// get the tracker calibration object
osg::ref_ptr<osgART::Calibration> calibration = tracker->getOrCreateCalibration();
// load a calibration file
if (!calibration->load("data/camera_para.dat"))
{
// the calibration file was non-existing or couldnt be loaded
osg::notify(osg::FATAL) << "Non existing or incompatible calibration file" << std::endl;
exit(-1);
}
// create a stats collector
osg::ref_ptr<osg::Stats> myStats = new osg::Stats("osgART timings");
// attach stats collector to the tracker
tracker->setStats(myStats.get());
// attach stats collector to the video
video->setStats(myStats.get());
// create reporting callback
root->setUpdateCallback(new StatsCallback(myStats.get()));
// set the image source for the tracker
tracker->setImage(video.get());
osgART::TrackerCallback::addOrSet(root.get(), tracker.get());
osg::ref_ptr<osgART::Marker> marker = tracker->addMarker("single;data/patt.hiro;80;0;0");
if (!marker.valid())
{
// Without marker an AR application can not work. Quit if none found.
osg::notify(osg::FATAL) << "Could not add marker!" << std::endl;
exit(-1);
}
marker->setActive(true);
osg::ref_ptr<osg::MatrixTransform> arTransform = new osg::MatrixTransform();
osgART::attachDefaultEventCallbacks(arTransform.get(),marker.get());
//****************************************************************************************************************
arTransform->addChild(carMT.get());
arTransform->addUpdateCallback (new osg::AnimationPathCallback(slerpPath1));
arTransform->getOrCreateStateSet()->setRenderBinDetails(100, "RenderBin");
osg::ref_ptr<osg::Group> videoBackground = createImageBackground(video.get());
videoBackground->getOrCreateStateSet()->setRenderBinDetails(0, "RenderBin");
osg::ref_ptr<osg::Camera> cam = calibration->createCamera();
cam->addChild(arTransform.get());
cam->addChild(videoBackground.get());
root->addChild(cam.get());
video->start();
return viewer.run();
// 是节点的问题还是回调的问题啊 |
|