draw osg geometry(triangle) on osgEarth

classic Classic list List threaded Threaded
3 messages Options
alvin alvin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

draw osg geometry(triangle) on osgEarth

hi there~ I'm new to osg&osgEarth, any idea on why won't show the desired triangle on osgEarth for the following code snippet ? thx in advance.

        osg::ref_ptr<osg::Geometry> spGeometry = new osg::Geometry();
        osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
        osg::ref_ptr<osg::Vec3Array>   _vertices = new osg::Vec3Array;
        osg::ref_ptr<osg::DrawElementsUInt> _triangles = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0);

        const SpatialReference* srs = SpatialReference::get("+datum=WGS84 +proj=UTM +zone=49 +no_defs");
        const SpatialReference* geosrs = SpatialReference::get("wgs84");
        GeoPoint point1(srs, 561964.5, 3582750.0, 1900, ALTMODE_ABSOLUTE);
        GeoPoint point2(srs, 561000.5, 3582750.0, 1900, ALTMODE_ABSOLUTE);
        GeoPoint point3(srs, 561000.5, 3581750.0, 1900, ALTMODE_ABSOLUTE);

        osg::ref_ptr<GeoTransform> geotran = new GeoTransform();
        geotran->setTerrain(m_mapNode->getTerrain());
        bool b = geotran->setPosition(point1);
        GeoPoint p1geo = point1.transform(geosrs);
        GeoPoint p2geo = point2.transform(geosrs);
        GeoPoint p3geo = point3.transform(geosrs);
        GeoPoint pgeoori(p1geo);
        osg::Vec3 p1(p1geo.x()-pgeoori.x(), p1geo.y()-pgeoori.y(), p1geo.z()-pgeoori.z());
        _vertices->push_back(p1);
        _triangles->push_back(0);

        osg::Vec3 p2(p2geo.x()-pgeoori.x(), p2geo.y()-pgeoori.y(), p2geo.z()-pgeoori.z());
        _vertices->push_back(p2);
        _triangles->push_back(1);

        osg::Vec3 p3(p3geo.x()-pgeoori.x(), p3geo.y()-pgeoori.y(), p3geo.z()-pgeoori.z());
        _vertices->push_back(p3);
        _triangles->push_back(2);
        spGeometry->setVertexArray(_vertices.get());
        spGeometry->addPrimitiveSet(_triangles.get());
        unsigned int count = spGeometry->getVertexArray()->getNumElements();
        colors->assign(count, osgEarth::Symbology::Color::Green);
        spGeometry->setColorArray(colors, osg::Array::BIND_PER_VERTEX);
        osg::ref_ptr<osg::Geode> spGeode = new osg::Geode;
        spGeode->addDrawable(spGeometry);
        geotran->addChild(spGeode);
        osgEarth::Registry::shaderGenerator().run( geotran );
        m_sky->addChild(geotran);
examyes examyes
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: draw osg geometry(triangle) on osgEarth

 m_sky->addChild(geotran);

why add the 'geotran' to 'm_sky'?
what does 'm_sky' stand for?
alvin alvin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: draw osg geometry(triangle) on osgEarth

hi~ examyes
   m_sky = osgEarth::Util::SkyNode::create(m_mapNode);
   m_sky->attach(m_pViewer,0);//m_pViewer is an osgViewer::Viewer
   m_sky->addChild(m_mapNode);

I've changed m_sky->addChild(geotran); to m_mapNode->addChild(geotran);
still no show triangle :(
Loading...