首页 > 其他 > 详细

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

时间:2016-08-11 19:12:24      阅读:175      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!