Hi, You can make this easier. There is a class for what You are trying to do. Have a look in osg::Shape, HeightField
Nick On Sat, Sep 28, 2013 at 6:16 AM, WillScott <[email protected]> wrote: > 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 > > -- trajce nikolov nick
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

