On Sun, Dec 6, 2009 at 7:53 AM, Lv Qing <[email protected]> wrote: > > Glenn Waldron wrote: > > Lv, > > > > convertLatLongHeightToXYZ gives you a point on the surface of the > ellipsoid, but the actual polygons in the terrain model are just a > tessellated approximation of that ellipsoid. So if you want the point on the > triangulated surface, you have to convert to XYZ and then "clamp" down to > the surface (using the local up-vector at that point). > > > > Glenn Waldron : Pelican Mapping : http://pelicanmapping.com ( > http://pelicanmapping.com) : +1.703.652.4791 > > > > > > On Sat, Dec 5, 2009 at 10:19 AM, Lv Qing < ()> wrote: > > > > > Hi, > > > > > > I have build a geocentric coordinate earth model using VPB and want to > put a simple model on the suface of the earth. > > > > > > I use the convertLatLongHeightToXYZ function to convert the > BLH(Lat,Long,Height) of the simple model to XYZ of the > > > geocentric coordinate system.The result of X and Y seems OK,but the Z > coordinate is always a bit higher above the earth suface(about 5000 m). > > > > > > > > > > > > Code: > > > > > > // load the earth model > > > osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode; > > > csn->setEllipsoidModel(new osg::EllipsoidModel()); > > > osg::Node* TerrainNode= osgDB::readNodeFile("earth.osga"); > > > csn->addChild(TerrainNode); > > > > > > //convert the BLH(50,130,0) to XYZ,I set height 0. > > > osg::Vec3d m_surface; > > > > csn->getEllipsoidModel()->convertLatLongHeightToXYZ(osg:egreesToRadians(50.0f),osg:egreesToRadians(130.0f),0.0f,double(m_surface.x()),double(m_surface.y()),double(m_surface.z())); > > > > > > //draw a simple yellow line from center of the earth (osg::Vec3(0,0,0)) > to the surface (osg::Vec3d m_surface); > > > > > > osg::Geode *geode_line = new osg::Geode; > > > osg::Geometry *geom = new osg::Geometry(); > > > geode_line->addDrawable(geom); > > > csn->addChild(geode_line); > > > osg::Vec3Array *v = new osg::Vec3Array(); > > > v->push_back(osg::Vec3(0,0,0)); > > > v->push_back(m_center); > > > geom->setVertexArray(v); > > > osg::Vec4Array *vc = new osg::Vec4Array(); > > > vc->push_back(osg::Vec4(1.0f,0.5f,0.0f,1.0f)); > > > geom->setColorArray(vc); > > > geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE); > > > geom->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet:INES,0,2)); > > > > > > > > > > > > > > > > > > As the result ,the end of the yellow line is obviously higher than the > surface.Please tell me where I am wrong,THX! > > > Thank you! > > > > > > Cheers, > > > Lv > > > > > > ------------------ > > > Read this topic online here: > > > http://forum.openscenegraph.org/viewtopic.php?p=20950#20950 ( > http://forum.openscenegraph.org/viewtopic.php?p=20950#20950) > > > > > > > > > > > > > > > Attachments: > > > http://forum.openscenegraph.org//files/getattachment1_418.jpg ( > http://forum.openscenegraph.org//files/getattachment1_418.jpg) > > > > > > > > > _______________________________________________ > > > osg-users mailing list > > > () > > > > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org( > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org) > > > > > > > > > ------------------ > > Post generated by Mail2Forum > > > > Thank you !How can I use the local up-vector at that point? > > > Is that? > > > Code: > > osg::Vec3d m_center; > > > csn->getEllipsoidModel()->convertLatLongHeightToXYZ(osg::inDegrees(40.0f),osg::inDegrees(120.0f),0.0f,double(m_center.x()),double(m_center.y()),double(m_center.z())); > > osg::Vec3d center; > > > center.set(csn->getEllipsoidModel()->computeLocalUpVector(m_center.x(),m_center.y(),m_center.z())); >
1) Get the XYZ using convertLatLongHeightToXYZ (lat/long must be in radians). 2) Get the local normalized UP vector at that point, as in your code above. (you need revision 10536 or newer for this method to work correctly -- if you are using an older version, just copy the newer code and do it manually). 3) Start at your XYZ, and extend along the up vector in each direction to create a line segment long enough to intersect the terrain. 4) Use the osgUtil::LineSegmentIntersector to find the intersection point. Keep in mind that the intersection point will be different for each LOD in your VPB terrain ... but that's another topic. Glenn Waldron : Pelican Mapping : http://pelicanmapping.com : +1.703.652.4791
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

