其他分享
首页 > 其他分享> > osg绘制球体

osg绘制球体

作者:互联网

osg绘制球体

#include <iostream>
#include <osgViewer/Viewer>
#include <osg/Node>

//#include <osgDB/ReadFile>
//#include <osgDB/WriteFile>

#include <osgUtil\Optimizer>
#include <osg/Geode>
#include <osg/Group>
#include <osg/ShapeDrawable>

//绘制几何体
osg::Geode* createShpe()
{
    //
    osg::Geode *geode = new osg::Geode();
    //半径
    float radius = 0.8f;
    //高度
    float height = 1.6f;

    //精细度
    osg::TessellationHints* hints1 = new osg::TessellationHints();
    //设置精细度
    hints1->setDetailRatio(1.1f);

    //创建球体
    osg::Sphere *sphere = new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius);
    osg::ShapeDrawable *draw1 = new osg::ShapeDrawable(sphere, hints1);

    geode->addDrawable(draw1);

    return geode;
}


int main()
{
    osgViewer::Viewer *viewer1 = new osgViewer::Viewer();
    osg::Group *root = new osg::Group();

    root->addChild(createShpe());

    osgUtil::Optimizer optimizer1;
    optimizer1.optimize(root);

    viewer1->setUpViewInWindow(200, 200, 700, 500, 0);

    //viewer1->addEventHandler(new osgViewer::GraphicsWindow::resized(0,0,640,480));
    viewer1->setSceneData(root);

    //viewer1->realize();
    viewer1->run();
    return 0;
}

 

############33

标签:viewer1,root,0.0,球体,new,include,绘制,osg
来源: https://www.cnblogs.com/herd/p/15124181.html