Hi,
I want to obtain the latitude, longitude and height when I click with the
mouse. Here is my code :
osgGA::GUIEventAdapter ea;
osgUtil::LineSegmentIntersector::Intersections intersections;
std::string gdlist=;
float x = ea.getX();
float y = ea.getY();
osg::ref_ptr osgUtil::LineSegmentIntersector picker = new
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, x, y);
osgUtil::IntersectionVisitor iv(picker.get());
view-getCamera()-accept(iv);
if (picker-containsIntersections())
{
intersections = picker-getIntersections();
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr =
intersections.begin();
hitr != intersections.end();
++hitr)
{
std::ostringstream os;
if (!hitr-nodePath.empty()
!(hitr-nodePath.back()-getName().empty()))
{
// the geodes are identified by name.
osObject
\hitr-nodePath.back()-getName()\std::endl;
}
else if (hitr-drawable.valid())
{
osObject
\hitr-drawable-className()\std::endl;
}
osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode;
csn-setEllipsoidModel(new osg::EllipsoidModel());
csn-addChild(TerrainNode);
oslocal coords vertex(
hitr-getLocalIntersectPoint())std::endl;
osworld coords vertex(
hitr-getWorldIntersectPoint())std::endl;
osg::Vec3 point = hitr-getWorldIntersectPoint();
double latitude;
double longitude;
double height;
csn-getEllipsoidModel()-convertXYZToLatLongHeight(point.x(),point.y(),point.z(),latitude,longitude,height);
latitude = osg::RadiansToDegrees(latitude);
longitude = osg::RadiansToDegrees(longitude);
oslat,long,height( latitude , longitude
, height ) std::endl;
gdlist += os.str();
}
}
This works well when I don't make a translation or rotation on the terrain.
But when I make a translation for example :
TerrainNode= osgDB::readNodeFile(geo.osg);
osg::ref_ptrosg::Group group = new osg::Group;
osg::ref_ptrosg::MatrixTransform mat = new osg::MatrixTransform;
group-addChild(mat);
mat-addChild(TerrainNode);
osg::Matrix trans;
trans.makeTranslate(osg::Vec3f(1000,5000,1500));
mat-preMult(trans);
the values of latitude, longitude and height are false and it's normal.
I would prefer to use local point hitr-getLocalIntersectPoint(), which does
not change when I make a translation, to calculate the latitude, longitude and
height but I don't how to do this.
Can you help me?
Thank you!
Cheers,
lucie
--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30174#30174
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org