Dear all,

I have a geode that is a simple line which I obtain using the function 
"SetupLine" described below. I then modify the position of the end points of 
the line durng an update loop.

It all works fine and works as expected so long as the startPos and endPos used 
when first setting up the line (in SetupLine) are not colocated. When the init 
end point positions of the line are colocated then whatever I do and although 
these two points are not colocated anymore when updating the line, the line 
never shows up.

Now if create the line with NON-colocated end points and then update it with 
the same end points thereafter, then I have no problem and everything performs 
as expected...

Any idea of what happens? Could that be a bug?

Regards,

Antoine.

osg::ref_ptr<osg::Geode> SetupLine(const osg::Vec3f& startPos, const 
osg::Vec3f& endPos, const osg::Vec4f& color)
{
        osg::ref_ptr<osg::Geode> geode = new osg::Geode();
        assert(geode);
        osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();
        assert(geometry);
        osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array();
        assert(vertices);
        osg::ref_ptr<osg::DrawElementsUInt> primitiveSet = new 
osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
        assert(primitiveSet);
        osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();
        assert(colors);

        // Setup.
        geode->addDrawable(geometry);
        geometry->setVertexArray(vertices);
        geometry->addPrimitiveSet(primitiveSet);
        geometry->setColorArray(colors);

        // Vertices.
        vertices->push_back(startPos);
        vertices->push_back(endPos);

        // Primitive set.
        primitiveSet->push_back(0);
        primitiveSet->push_back(1);

        // Colors.
        colors->push_back(color);

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

        // State.
        osg::ref_ptr<osg::StateSet> state = geode->getOrCreateStateSet();
        assert(state);

        state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
        state->setAttributeAndModes(new osg::LineWidth(GOAL_LINE_THICKNESS), 
osg::StateAttribute::ON);

        return geode;
}

Code used to modify the line geode (where m_line is the geode returned by the 
above mentioned function):

        osg::ref_ptr<osg::Geometry> geometry = 
static_cast<osg::Geometry*>(m_line->getDrawable(0));
        assert(geometry);
        osg::ref_ptr<osg::Vec3Array> vertices = 
static_cast<osg::Vec3Array*>(geometry->getVertexArray());
        assert(vertices);

        vertices->at(0) = SkToOsgVector3(cPos);
        vertices->at(1) = SkToOsgVector3(tPos);

        geometry->dirtyDisplayList();

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=36975#36975





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to