[osg-users] Straight lines are broken during rotation

Robert Osfield robert.osfield at gmail.com
Sat Jan 20 03:34:53 PST 2018


Hi Adrian,

>From the info given it's not possible to know exactly what is wrong as
there are several possibilities depending upon what the rest of your
application is doing, and the data itself, none of which we have
knowledge of. The best I can do is back some general statements about
handling this type of data.

First up, OpenGL graphics hardware works mostly with floats so that
when working with large vertex values precision can be a big issue,
causing jitter.  The way to avoid precision issues when rendering with
the OSG is to create your geometry with a local origin and decorate
this with a Transform node that places this subgraph in it's final
location.  The OSG uses doubles to accumulate the Camera View matrix
and all the internal Transform nodes to maintain precision as long as
possible before passing to OpenGL where it'll be cast down to floats.
This technique has been discussed many times in the osg-users mailing
list/forum so have a look through the archives.  The osgEarth and
osgTerrain NodeKit's use these technique to handle whole earth
databases with precision problems,

The next possibility is z fighting.  You mix discussion of line and
mesh in your post and the picture kinda looks like you might have a
line and mesh together, if you do and the line is
appearing/disappearing if could be due to z fighting.  This another
topic discussed many times in the OSG community and out on the web so
have a search.

Robert.

On 19 January 2018 at 01:57, Adrian Jelffs <adrian.jelffs at makai.com> wrote:
> Hi,
>
> I am pretty new to OSG but have been working on it for the past few weeks. I have an application that is rendering a 2D terrain with a constant width. When I rotate my display the line sometime appears broken.
>
> There are no other layers present. I have attached an example. This terrain should be solid and sometimes is depending upon the viewing angle.
>
> Does anyone have any suggestions as to what is happening or what I might be able to do to fix it?
>
> Thank you!
>
> Cheers,
> Adrian
>
>
> Code:
>     osg::ref_ptr<osg::Vec3Array> vertexData = new osg::Vec3Array;
>
>     osg::Vec4Array* colors = new osg::Vec4Array;
>     colors->push_back(_settingPtr->int2osgColor(3394636));
>     _terrain2dGeom->setColorArray(colors, osg::Array::BIND_OVERALL);
>     _terrain2dGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
>     _terrain2dGeom->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
>     _terrain2dGeom->addPrimitiveSet(new osg::DrawArrays(GL_QUAD_STRIP, 0, 2 * TerrainData.size()));
>
>     osg::Vec3d _frontVec, _up, _sideVec , _prevPos;
>
>     for (int i = 0; i < TerrainData.size(); i++)
>     {
>         VbTerrainData terrainItem = TerrainData.at(i);
>         osg::Vec3d longlat = osg::Vec3d(terrainItem.y, terrainItem.x, terrainItem.z);
>
>         _up = lonlat2Metric(osg::Vec3d(longlat.x(), longlat.y(), longlat.z()));
>
>         if (i == 0)
>         {
>             _prevPos = _up;
>             VbTerrainData terrainNextItem = TerrainData.at(1);
>             osg::Vec3d nextlonglat = osg::Vec3d(terrainNextItem.y, terrainNextItem.x, terrainNextItem.z);
>
>             _frontVec = lonlat2Metric(osg::Vec3d(nextlonglat.x(), nextlonglat.y(), nextlonglat.z())) - _prevPos;
>         }
>         else
>         {
>             _frontVec = _up - _prevPos;
>             _prevPos = _up;
>         }
>
>          _sideVec = _up ^ _frontVec;
>         _sideVec.normalize();
>
>         vertexData->push_back(_up + _sideVec*width/2);
>         vertexData->push_back(_up - _sideVec*width/2);
>     }
>
>     _terrain2dGeom->setVertexArray(vertexData.get());
>
>     _swTerrain->addChild(_terrain2dGeom);
>     _swTerrain->setValue(0, true);
>
>
>
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=72783#72783
>
>
>
>
> Attachments:
> http://forum.openscenegraph.org//files/terrain_172.jpg
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


More information about the osg-users mailing list