zoukankan      html  css  js  c++  java
  • osg学习笔记3 简单几何模型

    osg::Geode (geometry node)

    osg::Geode类表示场景中的渲染几何叶节点,它包含了渲染用的几何信息,没有子节点。

    要绘制的几何数据保存在osg::Geode管理的一组osg::Drawable对象中。osg::Drawable是一个接口,它有很多实现类渲染模型,图像,文本到OpenGL管线。这些可渲染统称为drawables.

    osg::Geode提供了几个方法来绑定和解绑drawables:

    1. addDrawable()
    2. removeDrawable(), removeDrawables()
    3. getDrawable()
    4. getNumDrawables()

    渲染基本模型Shape

    osg::ShapeDrawable继承自osg::Drawable。

    setShape()方法通常分配和设置一个模型shape,如:

    shapeDrawable->setShape( new osg::Box(osg::Vec3(1.0f, 0.0f, 0.0f), 10.0f, 10.0f, 5.0f) );

    示例

    #include <osg/ShapeDrawable>
    #include <osg/Geode>
    #include <osgViewer/Viewer>
    
    int main(int argc, char **argv)
    {
        osg::ref_ptr<osg::ShapeDrawable> shape1 = new osg::ShapeDrawable;
        shape1->setShape(new osg::Box(osg::Vec3(-3.0f, 0.0f, 0.0f),
            2.0f, 2.0f, 1.0f));
        osg::ref_ptr<osg::ShapeDrawable> shape2 = new osg::ShapeDrawable;
        shape2->setShape(new osg::Sphere(osg::Vec3(3.0f, 0.0f, 0.0f),
            1.0f));
        shape2->setColor(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
        osg::ref_ptr<osg::ShapeDrawable> shape3 = new osg::ShapeDrawable;
        shape3->setShape(new osg::Cone(osg::Vec3(0.0f, 0.0f, 0.0f),
            1.0f, 1.0f));
        shape3->setColor(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f));
    
        osg::ref_ptr<osg::Geode> root = new osg::Geode;
        root->addDrawable(shape1.get());
        root->addDrawable(shape2.get());
        root->addDrawable(shape3.get());
    
        osgViewer::Viewer viewer;
        viewer.setSceneData(root.get());
        return viewer.run();
    }
  • 相关阅读:
    mysql 官网下载,以及安装配置
    SQL 完美解决用逗号分隔存放在一个字段数据
    centos7 开机自动执行shell脚本
    ansible 通过shell脚本执行MySQL语句
    查找让mysql cpu达到100%的罪魁祸首
    查看mysql数据库容量大小
    docker安装zabbix-proxy
    docker zabbix 环境变量
    zabbix 时区不对-误差5个小时--持续更新
    zabbix钉钉告警
  • 原文地址:https://www.cnblogs.com/yaoyu126/p/5762145.html
Copyright © 2011-2022 走看看