Hi,

This is how I create four vertices and bind them to a MatrixTransform. It's not 
required to display the square drawn from four vertices:


Code:
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
        vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f ));
        vertices->push_back(osg::Vec3(50.0f, 0.0f, 0.0f ));
        vertices->push_back(osg::Vec3(50.0f, 50.0f, 0.0f ));
        vertices->push_back(osg::Vec3(0.0f, 50.0f, 0.0f ));

osg::ref_ptr<osg::Geode> geode= new osg::Geode;
osg::ref_ptr<osg::Geometry> geometry= new osg::Geometry;
geometry->setVertexArray(vertices);
geode->addDrawable(geometry.get());
matrixTransform->addChild(geode);



matrixTransform will be updated constantly, so will the vertice coordinates 
mapped to it. Now I want to retrieve the coordinates of each vertex with 
matrixTransform applied

The following code retrieves the same coordinates as I have pushed into the 
Vec3Array above.


Code:
osg::Vec3 v1;
osg::Vec3Array* vertices ;

vertices = 
static_cast<osg::Vec3Array*>(marker1->getChild(0)->asGeode()->getDrawable(0)->asGeometry()->getVertexArray()
 );
td::cout << "----" << std::endl;
for(unsigned int j=0; j<vertices->getNumElements(); j++){
        v1 = (*vertices)[j];
        std::cout << v1.x() << " " << v1.y() << " " << v1.z() << std::endl;
}



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





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

Reply via email to