Sanat, The code I gave you assumes that your VPB terrain was built using the --geocentric flag (e.g. round earth). If not, then you must resort to what Glenn recommended in his email and handle the coordinate conversions correctly from a flat UTM (or whatever) to a round earth.
If you do decide to build your VPB terrain using --geocentric, the X,Y,Z coordinates have their origin at (0,0,0) (i.e. the center of the earth) so your Z coordinate in convertXYZToLatLongHeight(276119.7034106, 4685765.312, 0.0,...) should never be zero unless you're exactly at the equator (yielding a latitude of zero). In your call convertLatLongHeightToXYZ(osg::DegreesToRadians(42.291966f), osg::DegreesToRadians(-83.715645f), 0.0f,...) an altitude of zero will only give you an X,Y,Z point on the ellipsoid. -Shayne -----Original Message----- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Sanat Talmaki Sent: Friday, April 08, 2011 11:07 PM To: osg-users@lists.openscenegraph.org Subject: Re: [osg-users] Unable to place model on vpb terrain. How To ? 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: Code: osg::ref_ptr<osg::EllipsoidModel> em = csnVisitor.coordinateSystemNode->getEllipsoidModel(); if(!em) { 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. Code: csnVisitor.coordinateSystemNode->getEllipsoidModel()-> convertLatLongHeightToXYZ(osg::DegreesToRadians(42.291966f), osg::DegreesToRadians(-83.715645f), 0.0f, terrainPosition.x(), terrainPosition.y(), terrainPosition.z()); double latitude, longitude, height; csnVisitor.coordinateSystemNode->getEllipsoidModel()->convertXYZToLatLon gHeight(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: Code: 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 Sincerely, Sanat. ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38350#38350 Attachments: http://forum.openscenegraph.org//files/northcampus6levels_134.osg _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or g _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org