8.osg中使用Tesselator分格化(三角剖分)

在球的基础上进行操作。

效果为与主窗口和子窗口添加一个边框

        osg::ref_ptrvertice2 = new osg::Vec3Array(8);

        //外边界逆针

        (*vertice2)[0].set(1,1,0);

        (*vertice2)[1].set(w-1,1,0);

        (*vertice2)[2].set(w-1,h-1,0);

        (*vertice2)[3].set(1,h-1,0);

        //内边界顺时针

        (*vertice2)[4].set(100,100,0);

        (*vertice2)[5].set(100,h-100,0);

        (*vertice2)[6].set(w-100,h-100,0);

        (*vertice2)[7].set(w-100,100,0);

 

        osg::ref_ptr geom =new osg::Geometry();

       

        geom->setVertexArray(vertice2);

 

        osg::Vec3Array* normals = newosg::Vec3Array;

        normals->push_back(osg::Vec3(0.0f,0.0f, 1.0f));

        geom->setNormalArray(normals);

        geom->setNormalBinding(osg::Geometry::BIND_OVERALL);

 

        osg::Vec4Array* colors = newosg::Vec4Array;

        colors->push_back(osg::Vec4(0.0f,0.0f,0.0f,1.0f));

        geom->setColorArray(colors);

        geom->setColorBinding(osg::Geometry::BIND_OVERALL);

 

        geom->addPrimitiveSet(newosg::DrawArrays(osg::PrimitiveSet::QUADS,0,vertice2->size()));

执行到此处显然这两个矩形会覆盖整个屏幕,需要进行分格化操作。

 

分格化:

osg::ref_ptrtscx = new osgUtil::Tessellator();

tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);

tscx->setBoundaryOnly(false);//设置是否只显示边界

tscx->setWindingType(osgUtil::Tessellator::TESS_WINDING_NONZERO);

tscx->retessellatePolygons(*geom);

geode->addDrawable(geom);

//TESS_WINDING_POSITIVE渲染环绕数为正的区域

//TESS_WINDING_NEGETIVE渲染环绕数为负的区域

//TESS_WINDING_ODD渲染环绕数为奇数的区域

//TESS_WINDING_NONZERO渲染环绕数不为0的区域

//TESS_WINDING_ABS_GEQ_TWO渲染环绕数绝对值大于2的区域

//逆时针为正,顺时针为负

效果如下:

8.osg中使用Tesselator分格化(三角剖分)_第1张图片

你可能感兴趣的:(osg)