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();
    
    }
  • 相关阅读:
    Windows打开软件老是弹出无法验证发布者
    SpringMvc接受特殊符号参数被转义
    时代更替中的方正
    你应该知道的c# 反射详解
    C#使用System.Data.SQLite操作SQLite
    C# 动态调用WebService
    C# API: 生成和读取Excel文件
    11个强大的Visual Studio调试小技巧
    .Net 垃圾回收和大对象处理
    Visual Studio原生开发的10个调试技巧(一)
  • 原文地址:https://www.cnblogs.com/linxuemufeng/p/11235156.html
Copyright © 2011-2022 走看看