Hi,

try dirtyBound function on your objects that you change.

jp

Adrien Joly wrote:
Hi,

I am currently trying to build a "dynamic line". I mean the extremities of the 
segment can be attached to a node and change everytime the node position relativelly to 
the world change. Actually, I have a NodeCullback redefined class and a geode redefined 
class.

Here is the code :

Code:

void Trail::_initBefore(){
  _drawable = new osg::Geometry;
  _bounds = new osg::Vec3Array(2);
  _color = new osg::Vec4Array(1);
  osg::Vec3Array* normals = new osg::Vec3Array;
  normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
  ((osg::Geometry*)_drawable)->setNormalArray(normals);
  ((osg::Geometry*)_drawable)->setNormalBinding(osg::Geometry::BIND_OVERALL);
  ((osg::Geometry*)_drawable)->setVertexArray(_bounds);
  ((osg::Geometry*)_drawable)->setColorBinding(osg::Geometry::BIND_OVERALL);
  ((osg::Geometry*)_drawable)->setColorArray(_color);
  ((osg::Geometry*)_drawable)->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,2));
  _width = new osg::LineWidth(DEF_WIDTH);
        
((osg::Geometry*)_drawable)->getOrCreateStateSet()->setAttribute(_width, 
osg::StateAttribute::ON);
        
((osg::Geometry*)_drawable)->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
        
}

void Trail::updateNode(osg::Vec3 source, osg::Vec3 target, osg::Vec3 
sourceCenter, osg::Vec3 targetCenter){
  (*_bounds)[0].set(source);
  (*_bounds)[1].set(target);

  osg::PrimitiveSet* ps = ((osg::Geometry*)_drawable)->getPrimitiveSet(0);
  ((osg::Geometry*)_drawable)->setPrimitiveSet(0, ps);
}




The method "updateNode" is called everytime one of the extremity of the segment 
change of position.

My problem is that when the extremities of the segment are not on the view, the 
line color change to blue and the line sometimes disappear.
I don't understand wher the problem might be.

I have the same problem with trace (a Line_Strip that follow an object). In 
this case, it is worst because the entire scene disappear under some points of 
view.

Here is the code (it's basically the same principle as above)


Code:


void Trace::_initBefore(){
        _drawable = new osg::Geometry;
        _bounds = new osg::Vec3Array;
        _color = new osg::Vec4Array;
        _color->push_back(osg::Vec4(1, 1, 1, 1));
        ((osg::Geometry*)_drawable)->setVertexArray(_bounds);
        ((osg::Geometry*)_drawable)->setColorArray(_color);
        
((osg::Geometry*)_drawable)->setColorBinding(osg::Geometry::BIND_OVERALL);
        _width = new osg::LineWidth(DEF_WIDTH);
        
((osg::Geometry*)_drawable)->getOrCreateStateSet()->setAttribute(_width, 
osg::StateAttribute::ON);
        
((osg::Geometry*)_drawable)->getOrCreateStateSet()->setMode(GL_LIGHTING, 
osg::StateAttribute::OFF);
        osg::Vec3Array* normals = new osg::Vec3Array;
        normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
        ((osg::Geometry*)_drawable)->setNormalArray(normals);
        
((osg::Geometry*)_drawable)->setNormalBinding(osg::Geometry::BIND_OVERALL);
        ((osg::Geometry*)_drawable)->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,2));
}

void Trace::updateNode(osg::Vec3 source, osg::Vec3 target, osg::Vec3 
sourceCenter, osg::Vec3 targetCenter){
        if(!(source == osg::Vec3() && target == osg::Vec3())){
                if(source != target || firstCallUpdate){
                        if(!firstCallUpdate){
                                unsigned int count = _bounds->size();
                                if(count >= 2){
                                        (*_bounds)[count-1] = _oldPosition;
                                }
                                else{
                                        _bounds->push_back(_oldPosition);
                                        _bounds->push_back(target);
                                }
                        
                                _bounds->push_back(target);
                                _oldPosition = targetCenter;
                        }
                        else{
                                _oldPosition = targetCenter;
                                firstCallUpdate = false;
                        }
                        setSource(targetCenter);
                        osg::DrawArrays* ps = 
((osg::DrawArrays*)((osg::Geometry*)_drawable)->getPrimitiveSet(0));
                        ps->setCount(ps->getCount() + 2);
                        ((osg::Geometry*)_drawable)->setPrimitiveSet(0, ps);
                }
        }
}





I need some help !
Thank you!

Cheers,
Adrien

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





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


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

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

Reply via email to