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; }
QQ 3087438119