码迷,mamicode.com
首页 > 其他好文 > 详细

osg学习笔记3 简单几何模型

时间:2016-08-11 19:14:41      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

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();
}

 

osg学习笔记3 简单几何模型

标签:

原文地址:http://www.cnblogs.com/yaoyu126/p/5762145.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!