osg 矩阵操作

  • Post author:
  • Post category:其他


osg::ref_ptr node=new osg::Node;

node=osgDB::readNodeFile(“glide.osg”);//这种先将node指向new,然后指nodeDB,所以node不再指向new,内存泄漏,经常会出错,一般是用下面另一种

osg::ref_ptrnode=osgDB::readNodeFile(“glider.osg”)

#include<osg/MatrixTransform>
osg::ref_ptr<osg::Node> MatrixOperation()
{
osg::ref_ptr<osg::Group> group=new osg::Group;
osg::ref_ptr<osg::MatrixTransform> max=new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> max2=new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> max3=new osg::MatrixTransform;
osg::ref_ptr<osg::MatrixTransform> max4=new osg::MatrixTransform;
osg::ref_ptr<osg::Node>node=osgDB::readNodeFile("glider.osg")

max2->addChild(node.get());
max2->setMatrix(osg::Matrix::translate(5.0,0.0,0.0));
max->setUpadataCallback(new osg::AnimationPathCallback((osg::Vec3(5.0,0.0,0.0),osg::Z_AXIS,1.0));
//参数:旋转中心旋转轴,角速度,
max->addChild(max.get());

max4->addChild(node.get());
max4->setMatrix(osg::Matrix::translate(-5.0,0.0,0.0));
max3->setUpadataCallback(new osg::AnimationPathCallback((osg::Vec3(-5.0,0.0,0.0),osg::Z_AXIS,1.0));
max3->addChild(max.get());

group->addChild(node.get());
group->addChild(max.get());

return group;

}



int main()
{
osg::ref_ptr<osgViewer::Viewer>viewer=new osgViewer::Viewer;
osg::ref_ptr<osg::Group> group=new osg::Group;
group->addChild(osgDB::readNodeFile("glider.osg"));
group->addChild();
viewer->setSceneData(MatrixOperation().get());
return viewer->run();
}

2.旋转



版权声明:本文为qq_37802138原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。