[osg-users] Straight lines are broken during rotation

Adrian Jelffs adrian.jelffs at makai.com
Thu Jan 18 17:57:16 PST 2018


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




More information about the osg-users mailing list