(1)最顶层Viewer

osgViewer::Viewer viewer

(2)接着是grp

osg::Group* grp = new osg::Group;
viewer.setSceneData(grp);

(3)grp里面是root

osg::Group* root = new osg::Group;
grp->addChild(root);

(4)root里面定义了坐标轴和矩阵变换

osg::ref_ptr<osg::Geode> axe = createAxis();
osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform();
root->addChild(axe.get());
root->addChild(trans.get());

(5)矩阵变换中定义了物体

osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, 0.0f), 1)));
trans->addChild(geode.get());

在grp中可定义动画管理器

osgAnimation::BasicAnimationManager* mng = new osgAnimation::BasicAnimationManager();
grp->setUpdateCallback(mng);

动画管理器中可定义不同的动画

osgAnimation::Animation* anim1 = new osgAnimation::Animation;
mng->registerAnimation(anim1);

动画中可定义不同的动画通道

osgAnimation::Vec3LinearChannel* channelAnimation1 = new osgAnimation::Vec3LinearChannel;
anim1->addChannel(channelAnimation1);

以下为OSG教程的学习笔记 

 

 

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐