Quantcast

I want to modify a vertex of a tile, change it's height in real time

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

I want to modify a vertex of a tile, change it's height in real time

struct MyHandler : public osgGA::GUIEventHandler {
        MyHandler()
        {}

        bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
        {
                if (ea.getEventType() == ea.DOUBLECLICK &&
                        ea.getButton() == ea.LEFT_MOUSE_BUTTON)
                {
                        osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
                        osg::Vec3d world;
                        osgUtil::LineSegmentIntersector::Intersections hits;
                        if (view->computeIntersections(ea.getX(), ea.getY(), hits)) {
                                world = hits.begin()->getWorldIntersectPoint();
                                for (auto it : hits.begin()->nodePath)
                                {
                                        std::string name = it->className();
                                        if (name == "TileDrawable") {
                                                osgEarth::Drivers::RexTerrainEngine::TileDrawable* drawable = (osgEarth::Drivers::RexTerrainEngine::TileDrawable*)it;
                                                drawable->_geom->getVertexArray();
                                                osg::Vec3Array* arr = (osg::Vec3Array*)drawable->_geom->getVertexArray();
                                                osg::Vec3Array* normals = (osg::Vec3Array*)drawable->_geom->getNormalArray();
                                                (*arr)[2] = (*arr)[2] + (*normals)[2] * 100000.f;
                                        }
                                }
                               
                        }

                        return true;
                }

                return false;
        }
};


I want to modify a vertex of a tile, change it's height,when i double click the earth, but it doesn't work.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: I want to modify a vertex of a tile, change it's height in real time

Leo,
There are various reasons why this will not work, especially with the Rex terrain engine.

1. If you modify a buffer object (like a vertex array) you need to call dirty() on the array so that it will be re-submitted to the GPU.

2. Tile geometries in are shared among multiple terrain tiles, so attempting to modify one will modify others as well.

3. Elevation in Rex is stored in a texture and not in the geometry itself, so the results might be unexpected.

In summary, you can't do this. You might have better luck with the MP engine.
Glenn Waldron / Pelican Mapping
leo leo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: I want to modify a vertex of a tile, change it's height in real time

@glennwaldron ,

How about modify vertex buffer before it will be rendered on the screen at the next frame?
leo leo
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: I want to modify a vertex of a tile, change it's height in real time

In reply to this post by gwaldron
gwaldron,
 Thanks a lot, I,ve  solved the problem by modify and dirty the vertex buffer during culling the scene.
Loading...