[osg-users] Unable to place model on vpb terrain. How To ?

Sanat Talmaki sanat.schumi at gmail.com
Fri Apr 8 22:07:05 PDT 2011

Hi Shayne,

Thanks for your reply. I have tried a few different things and have a few questions from that:

First of, when I try something like this:

osg::ref_ptr<osg::EllipsoidModel> em = csnVisitor.coordinateSystemNode->getEllipsoidModel();
    std::cout << "ellipsoid model is null\n";
  //where csnVisitor has a data member storing coordsystemnode

To get over this, I need to set the ellipsoid model first and then try the above. This seemed strange but since the ctor is overloaded, I didn't think much of it. But now that the convertXYZToLatLong and vice versa are giving me incorrect results, I am wondering if this maybe a cause??

Second, when I tried using a set of coords for which I had precomputed the geocentric (XYZ) coords from lat-long using osgEarth, I got incorrect numbers. 

                   convertLatLongHeightToXYZ(osg::DegreesToRadians(42.291966f), osg::DegreesToRadians(-83.715645f), 0.0f, 
                   terrainPosition.x(), terrainPosition.y(), terrainPosition.z());
  double latitude, longitude, height;
  csnVisitor.coordinateSystemNode->getEllipsoidModel()->convertXYZToLatLongHeight(276119.7034106, 4685765.312, 0.0,
                                                                                  latitude, longitude, height);

I think I have these functions right. But cannot figure out what maybe causing this error. 

Third, when I try to get the height above terrain like:

osgSim::HeightAboveTerrain::computeHeightAboveTerrain(terrain, terrainPosition)
//where terrain position is from the convert to XYZ function

This gives me a wrong height value. 

I wanted to know what it is that I can check or that I maybe doing wrong. I have attached the terrain file (osg) that I am using in case that helps.

Thank you


Read this topic online here:


More information about the osg-users mailing list