[osg-users] Newbie question about concave polygons
Michele Bosi
michele.bosi at gmail.com
Thu Apr 24 03:07:31 PDT 2008
Hi Schwantes,
yes, OpenGL (and DirectX) don't directly support concave polygons, you have
to use several triangles to make a polygon look concave.
You don't really need a Tessellator, you could simply divide your concave
polygon in a bunch of triangles like in the attached picture.
You simply specify a vertex for each corner of each triangle and then call:
geom->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0,
vertices->getNumElements()));
Good luck,
Michele
On Wed, Apr 23, 2008 at 9:34 PM, R Schwantes <rschwantes at gmail.com> wrote:
> Hi list,
>
> I've been a long time lurker. Finally have some free time to get my hands
> dirty with OSG. I'm new to computer graphics, and so far its definitely
> been an adventure.
>
> I'm stuck trying to draw a concave polygon, it looks like I need to use
> tessellation to break the geometry down into smaller convex parts? I wrote
> some code using osgUtil::Tessellator but it doesn't work quite right. If I
> set boundryOnly = true, it looks how I would want it. If boundryOnly is set
> to false the polygon is not shaped correctly, and in this example is
> splintered into two parts.
>
> I've attached my code, can someone point me in the right direction?
>
>
> Thanks,
> Rick
>
> .....
>
> /* Polygon should look similar to
> *
> * _______
> * | |
> * |____ |_
> * | |
> * | |
> * | |
> * |____|
> */
> osg::Geometry* geom = new osg::Geometry;
>
> osg::Vec3Array* vertices = new osg::Vec3Array;
> vertices->push_back(osg::Vec3(0,68,0));
> vertices->push_back(osg::Vec3(0,57,0));
> vertices->push_back(osg::Vec3(86,57,0));
> vertices->push_back(osg::Vec3(86,0,0));
> vertices->push_back(osg::Vec3(98,0,0));
> vertices->push_back(osg::Vec3(98,57,0));
> vertices->push_back(osg::Vec3(92,57,0));
> vertices->push_back(osg::Vec3(92,68,0));
> geom->setVertexArray(vertices);
> geom->addPrimitiveSet(new
> osg::DrawArrays(GL_POLYGON,0,vertices->getNumElements()));
> osgUtil::Tessellator* tessellator = new osgUtil::Tessellator();
>
> tessellator->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
> tessellator->setBoundaryOnly(True);
> tessellator->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD);
> tessellator->retessellatePolygons(*geom);
> buildingGeode->addDrawable(geom);
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080424/6438a907/attachment.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: triangles.PNG
Type: image/png
Size: 3474 bytes
Desc: not available
Url : http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080424/6438a907/attachment.png
More information about the osg-users
mailing list