osg create shape

Posted herd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了osg create shape相关的知识,希望对你有一定的参考价值。

osg::ref_ptr<osg::Node> OSG_Qt_::createSimple()

    osg::ref_ptr<osg::Geode> geode = new osg::Geode;
    osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;

    //申请顶点
    osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array;
    //申请颜色
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    //申请法向量
    osg::ref_ptr<osg::Vec3Array> norms = new osg::Vec3Array;

    //设置顶点关联方式
    geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::Mode::QUADS,0,4));

    coords->push_back(osg::Vec3(-10.0,0.0,-10.0));
    coords->push_back(osg::Vec3(10.0, 0.0, -10.0));
    coords->push_back(osg::Vec3(10.0, 0.0, 10.0));
    coords->push_back(osg::Vec3(-10.0, 0.0, 10.0));

    //颜色赋值
    colors->push_back(osg::Vec4f(1.0,0.0,0.0,1.0));
    colors->push_back(osg::Vec4f(0.0, 1.0, 0.0, 1.0));
    colors->push_back(osg::Vec4f(0.0, 0.0, 1.0, 1.0));
    colors->push_back(osg::Vec4f(1.0, 1.0, 0.0, 1.0));

    //法向量赋值
    norms->push_back(osg::Vec3(0.0,-1.0,0.0));


    //设置顶点
    geometry->setVertexArray(coords.get());
    //设置颜色
    geometry->setColorArray(colors.get());
    //颜色绑定方式
    geometry->setColorBinding(osg::Geometry::AttributeBinding::BIND_PER_VERTEX);
    //设置法向量
    geometry->setNormalArray(norms.get());
    //法向量绑定
    geometry->setNormalBinding(osg::Geometry::AttributeBinding::BIND_OVERALL);

    geode->addDrawable(geometry.get());
    return geode;

 

以上是关于osg create shape的主要内容,如果未能解决你的问题,请参考以下文章

[osg]OSG相机添加动画路径

osg qt 三维模型加载

osg学习(五十八)cow.osg解析过程

OSG中的几何体

osg指定向量旋转指定角度

osg:node和osg:geode的区别