Hi,
the following code displays a grid when we enter in the 'if' part, but if i
press the key which displayed the grid before the else doen't delete this
object.
How can i do ?
void GmlOsgObject::createGrid()
{
osg::ref_ptr <osg::PositionAttitudeTransform> root =
CameraManager::getSingletonPtr()->getRoot();
osg::ref_ptr <osg::Geode> gridGeode = new osg::Geode();
osg::ref_ptr <osg::Geometry> gridGeometryV = new osg::Geometry();
osg::ref_ptr <osg::Geometry> gridGeometryH = new osg::Geometry();
if(/*!gridGeodePtr*/gridDisplayed==false )
{
root->addChild(gridGeode.get());
gridGeode->addDrawable(gridGeometryV.get());
gridGeode->addDrawable(gridGeometryH.get());
osg::Vec3Array* gridVerticesVertical = new osg::Vec3Array;
osg::Vec3Array* gridVerticesHorizontal = new osg::Vec3Array;
long int iterationNumber = 0 ;
for( int i = -100 ; i <= 100 ; i =i++ )
{
gridVerticesVertical->push_back(osg::Vec3(i*10, -1000, 0));
gridVerticesHorizontal->push_back(osg::Vec3(-1000, i*10, 0));
iterationNumber++ ;
}
for( int i = -100 ; i <= 100 ; i =i++ )
{
gridVerticesVertical->push_back(osg::Vec3(i*10, 1000, 0));
gridVerticesHorizontal->push_back(osg::Vec3(1000, i*10, 0));
iterationNumber++ ;
}
gridGeometryV->setVertexArray(gridVerticesVertical);
gridGeometryH->setVertexArray(gridVerticesHorizontal);
osg::DrawElementsUInt* horizontalLines = new
osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
osg::DrawElementsUInt* verticalLines = new
osg::DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
for(int i = (iterationNumber - 1) ; i > (iterationNumber/2) ; i--)
{
verticalLines->push_back(i);
verticalLines->push_back(i-(iterationNumber/2));
horizontalLines->push_back(i);
horizontalLines->push_back(i-(iterationNumber/2));
}
gridGeometryV->addPrimitiveSet(verticalLines);
gridGeometryH->addPrimitiveSet(horizontalLines);
gridGeode->setNodeMask(1);
gridDisplayed=true ;
//gridGeodePtr = gridGeode ;
}
else
{
//gridGeometryV->releaseGLObjects();
//gridGeometryH->releaseGLObjects();
gridGeode->setNodeMask(0);
root->removeChild(gridGeode.get());
//gridGeode->deleteUsingDeleteHandler();
//gridGeode.release();
gridDisplayed=false ;
/*gridGeodePtr = NULL ;*/
}
}
_________________________________________________________________
Retouchez, classez et partagez vos photos gratuitement avec le logiciel Galerie
de Photos !
http://www.windowslive.fr/galerie/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org