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

osg create shape

时间:2019-06-23 20:56:35      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:node   push   tco   arrays   rms   mode   attribute   geo   creat   

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

标签:node   push   tco   arrays   rms   mode   attribute   geo   creat   

原文地址:https://www.cnblogs.com/herd/p/11073983.html

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