zoukankan      html  css  js  c++  java
  • OSG的“hello world”

    #include <osgViewer/Viewer>
    
    #include <osg/Node>
    #include <osg/Geode>
    #include <osg/Group>
    #include <osg/MatrixTransform>
    #include <osg/AnimationPath>
    
    #include <osgDB/ReadFile>
    #include <osgDB/WriteFile>
    
    #include <osgUtil/Optimizer>
    
    osg::ref_ptr<osg::Node> MatrixOperation()
    {
        osg::ref_ptr<osg::Group> group = new osg::Group();
        osg::ref_ptr<osg::MatrixTransform> matrix = new osg::MatrixTransform();
        osg::ref_ptr<osg::MatrixTransform> matrix1 = new osg::MatrixTransform();
        osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("glider.osg");
    
        matrix->addChild(osgDB::readNodeFile("glider.osg"));
        //matrix->setMatrix(osg::Matrix::translate(5.0, 0.0, 0.0));
        matrix->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(6.0, 0.0, 0.0), osg::Z_AXIS, 1.0));
        matrix->addChild(matrix1.get());
    
        matrix1->addChild(node.get());
        matrix1->setMatrix(osg::Matrix::translate(5.0, 0.0, 0.0));
    
    
        //group->addChild(osgDB::readNodeFile("glider.osg"));
        group->addChild(node.get());
        group->addChild(matrix.get());
    
        return group;
    }
    
    
    int main()
    {
        //创建场景对象  场景浏览器
        osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
        //创建场景组节点
        osg::ref_ptr<osg::Group>  group = new osg::Group;
        //创建一个节点 ,读取牛得模型
        osg::ref_ptr<osg::Node>  node = osgDB::readNodeFile("cow.osg");
        //添加到场景
        group->addChild(node);
        //优化场景数据
        osgUtil::Optimizer optimizer;
        optimizer.optimize(group.get());
    
        //设置场景数据
        viewer->setSceneData(MatrixOperation().get());
    
        //初始化并创建窗口
        viewer->realize();
        //开始渲染
        return viewer->run();
    
    }
  • 相关阅读:
    搜索引擎 中 排序学习 的小思考
    《算法导论》之分治策略与动态规划
    《算法导论》之基础篇
    中文文本信息处理的原理与应用读书笔记1
    python 类变量 在多线程下的共享与释放问题
    日志管理
    《领导梯队》读书分享
    初见微服务之服务注册与发现
    初见微服务之RESTful API
    初见微服务之架构概述
  • 原文地址:https://www.cnblogs.com/linxuemufeng/p/11235156.html
Copyright © 2011-2022 走看看