查看: 2405|回复: 5

请教osgart 模型运动问题

[复制链接]

该用户从未签到

发表于 2011-1-5 21:23:55 | 显示全部楼层 |阅读模式
本帖最后由 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();
// 是节点的问题还是回调的问题啊

该用户从未签到

发表于 2011-1-6 09:07:55 | 显示全部楼层
osgART的节点是受到内部回调的控制(为了对应marker的位置)的,因此您如果把carMT放在arTransform之下,那么后者的位置变化会直接影响到前者。

该用户从未签到

 楼主| 发表于 2011-1-6 19:54:30 | 显示全部楼层
那怎么才能在osgart中运用osg中的AnimationPath来实现路径动画呢?还是要用别的方法实现?

该用户从未签到

发表于 2011-1-7 08:29:39 | 显示全部楼层
只要它不是osgART节点的子节点,我想就没有问题

该用户从未签到

 楼主| 发表于 2011-1-7 11:17:08 | 显示全部楼层
谢谢了!我再试试

该用户从未签到

发表于 2012-1-5 16:25:22 | 显示全部楼层
请教下,oagART应该怎么加入自己的模型啊!能不能发段例子看看。多谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表