zoukankan      html  css  js  c++  java
  • 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;
    
    
    }
  • 相关阅读:
    PHP应用目录结构设计
    php 项目性能优化
    Zend Framework的PHP编码规范【1】
    php 如何做在线人数统计
    linux 文件权限
    总结:常用的通用数据处理指令
    全排列(含递归和非递归的解法)
    局部变量,静态局部变量,全局变量,静态全局变量在内存中的存放区别(转)
    C++中引用详解
    Pascal三角形
  • 原文地址:https://www.cnblogs.com/huahai/p/7270948.html
Copyright © 2011-2022 走看看