5,保存4个一级节点

前面是一个牛和一个滑翔机,位置都在原点,

远处是牛,近处是滑翔机,可以自然而然地把牛当作0级节点,滑翔机作为一级节点,那么,能不能输出四个不同位置的滑翔机,类似于四叉树一样。

没有什么不可以。

输出四个不同位置的osg::MatrixTransform即可。

复制代码
for (int childIndex = 0; childIndex < 4; childIndex++)
{

	std::string strOutputName = strOutputDir + 
		"root_" + std::to_string(rootIndex) +
		"_level_" + std::to_string(level) + 
		"_child_" + std::to_string(childIndex) +".osg";
	osg::Vec3 center = centerVector[childIndex];
	osg::Matrix mat;
	mat.setTrans(center);
	osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform();
	trans->setMatrix(mat);
	trans->addChild(node);
	osgDB::writeNodeFile(*trans, strOutputName);
}

代码如下:

#include <osgViewer/Viewer>

#include <osg/Node>

#include <osgdb/ReadFile>

#include <osgDB/WriteFile>

#include <osg/PagedLod>

#include <osgGA/TrackballManipulator>

#include <osg/MatrixTransform>

#include <osg/Matrix>

int main()

{

int rootIndex = 0;

int level = 1;

std::string strOutputDir = "d:/test/1/";

osg::Vec3 center_child0(-5, 0, -5);

osg::Vec3 center_child1(-5, 0, 5);

osg::Vec3 center_child2(5, 0, -5);

osg::Vec3 center_child3(5, 0, 5);

复制代码
std::vector<osg::Vec3> centerVector;
centerVector.clear();
centerVector.push_back(center_child0);
centerVector.push_back(center_child1);
centerVector.push_back(center_child2);
centerVector.push_back(center_child3);
std::string strInputName = "D:/install/osg365_oe210_vs2019/OpenSceneGraph-Data/glider.osg";
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(strInputName);

for (int childIndex = 0; childIndex < 4; childIndex++)
{

	std::string strOutputName = strOutputDir + 
		"root_" + std::to_string(rootIndex) +
		"_level_" + std::to_string(level) + 
		"_child_" + std::to_string(childIndex) +".osg";
	osg::Vec3 center = centerVector[childIndex];
	osg::Matrix mat;
	mat.setTrans(center);
	osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform();
	trans->setMatrix(mat);
	trans->addChild(node);
	osgDB::writeNodeFile(*trans, strOutputName);
}

}

相关推荐
扶尔魔ocy3 天前
【qt openGL入门笔记】windows编译MinGW版本的osgearth(2.10.1)
qt·opengl·osg
扶尔魔ocy4 天前
【QT OpenGL】知识点编目及传送门
qt·opengl·osg
扶尔魔ocy17 天前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行并进行态势标绘(四)
qt·opengl·osg
扶尔魔ocy19 天前
【qt openGL入门笔记】OSG实现显示飞机模型飞行的点迹(二)
qt·opengl·osg
扶尔魔ocy19 天前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行(三)
opengl·osg
扶尔魔ocy20 天前
【qt openGL入门笔记】OSG实现飞机模型在网格图上飞行
qt·opengl·osg
directx3d_beginner8 个月前
10,cookbook的lod示例
osg
directx3d_beginner8 个月前
8,将0级简模文件和精模文件同时放入pagedlod
osg
directx3d_beginner8 个月前
9,0级建模文件和0级精模文件写成根节点
osg