• OSG学习:矩阵变换节点示例


    #include<osgViewerViewer>
    
    #include<osgNode>
    #include<osgGeode>
    #include<osgGroup>
    #include<osgMatrixTransform>
    
    #include<osgDBReadFile>
    #include<osgDBWriteFile>
    
    #include<osgUtilOptimizer>
    
    int main()
    {
    	//创建Viewer对象,场景浏览器
    	osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
    
    	//创建场景组节点
    	osg::ref_ptr<osg::Group> root = new osg::Group();
    
    	//创建一个节点,读取牛的模型
    	osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("cow.osg");
    
    	//创建矩阵变换节点mt1
    	osg::ref_ptr<osg::MatrixTransform> mt1 = new osg::MatrixTransform();
    	//创建一个矩阵
    	osg::Matrix m;
    	//在X方向平移10个单位
    	m.makeTranslate(osg::Vec3(10.0f, 0.0f, 0.0f));
    	//绕X轴旋转45度
    	m.makeRotate(45.0f, 1.0f, 0.0f, 0.0f);
    	//设置矩阵
    	mt1->setMatrix(m);
    	//添加子节点
    	mt1->addChild(node.get());
    
    	//创建矩阵变换节点mt2
    	osg::ref_ptr<osg::MatrixTransform> mt2 = new osg::MatrixTransform();
    	//创建一个矩阵
    	osg::Matrix t;
    	//在X方向平移10个单位
    	t.makeTranslate(osg::Vec3(-10.0f, 0.0f, 0.0f));
    	//设置矩阵
    	mt2->setMatrix(t);
    	//添加子节点
    	mt2->addChild(node.get());
    	
    	//添加到场景
    	root->addChild(mt1.get());
    	root->addChild(mt2.get());
    
    	//优化场景数据
    	osgUtil::Optimizer optimizer;
    	optimizer.optimize(root.get());
    
    	//设置场景数据
    	viewer->setSceneData(root.get());
    
    	//初始化并创建窗口
    	viewer->realize();
    
    	//开始渲染
    	viewer->run();
    
    	return 0;
    
    
    }
  • 相关阅读:
    到具体某一天的倒计时
    angular2 2种方式----获取子组件的类属性和类方法
    页面刷新
    angular父子组件传值
    div垂直居中,文字垂直居中!!!
    Python 基础数据类型 II (列表)
    Python 基础数据类型 I (str等)
    学习笔记411
    20190407 Word合并单元格
    VBA正则笔记 理解肯定环视
  • 原文地址:https://www.cnblogs.com/huahai/p/7270948.html
Copyright © 2020-2023  润新知