Hi Here,
     Recently , I want to build a grid model by OSG. However , the model really 
bother me a lot. The following is core codes I have use:
   
 for (int u = 0; u < XSize; u++)
    {
  osg::ref_ptr<osg::Geometry> linesGeom = new osg::Geometry();
  osg::ref_ptr<osg::Vec3Array> pointsVec = new osg::Vec3Array();
 
        for (int v = 0; v < YSize; v ++)
        {
           pointsVec->push_back(osg::Vec3(u,v,0));
     }
       
     linesGeom->setVertexArray(pointsVec.get());
     linesGeom->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,pointsVec->size()));
        
     geode->addDrawable(linesGeom.get());
  }
   // Approximation in u direction.
    for (int v = 0; v < YSize; v ++)
    {
       osg::ref_ptr<osg::Geometry> linesGeom = new osg::Geometry();
       osg::ref_ptr<osg::Vec3Array> pointsVec = new osg::Vec3Array();
    for (int u = 0; u < XSize; u ++)
    {
     pointsVec->push_back(osg::Vec3(u, v, 0));
    }
       // Set vertex array.
       linesGeom->setVertexArray(pointsVec);
       linesGeom->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, pointsVec->size()));
        
       geode->addDrawable(linesGeom.get());
    }
 
How can I use only   osg::ref_ptr<osg::Geometry> linesGeom  
osg::ref_ptr<osg::Vec3Array> pointsVec just one time as a local variable  as 
the following form?
       osg::ref_ptr<osg::Geometry> linesGeom = new osg::Geometry();
      osg::ref_ptr<osg::Vec3Array> pointsVec = new osg::Vec3Array();
  
 for (int u = 0; u < XSize; u++)
    {
         for (int v = 0; v < YSize; v ++)
        {
           pointsVec->push_back(osg::Vec3(u,v,0));
        }
     linesGeom->setVertexArray(pointsVec.get());
     linesGeom->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,pointsVec->size()));
        
     geode->addDrawable(linesGeom.get());
  }
   // Approximation in u direction.
    for (int v = 0; v < YSize; v ++)
    {
        for (int u = 0; u < XSize; u ++)
       {
          pointsVec->push_back(osg::Vec3(u, v, 0));
        }
       // Set vertex array.
       linesGeom->setVertexArray(pointsVec);
       linesGeom->addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, pointsVec->size()));

       geode->addDrawable(linesGeom.get());
     }
 
 
 
 
                                          
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to