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

在球的基礎上進行操作。

效果爲與主窗口和子窗口添加一個邊框

        osg::ref_ptr<osg::Vec3Array>vertice2 = 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<osg::Geometry> 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_ptr<osgUtil::Tessellator>tscx = 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的區域

//逆時針爲正,順時針爲負

效果如下:


發佈了25 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章