Chris 'Xenon' Hanson wrote:
> On 9/13/2011 12:44 PM, Ethan Fahy wrote:
> 
> > Now I just need to find a forum post I saw that shows how to place an 
> > object on the terrain based on an  lat/lot...
> > 
> 
> http://forum.openscenegraph.org/viewtopic.php?t=6734
> 


After reading those postings it looks like the relevant part to my case would 
be the following:

Code:

This is how you would place your model...

osg::Matrixd position;
ellipsoid->computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadia
ns(lat),
osg::DegreesToRadians(lon), altitude, position);
transform->setMatrix(position);

where "transform" is an osg::MatrixTransform node that has your model as a
child node.

The X,Y,Z geocentric Cartesian coordinates from the lat,lon,alt can be
extracted by:

osg::Vec3d pos = position.getTrans(); 



I'm a little unclear on the full implementation of this though.  Do I wrap that 
code up into something like this after reading in both the terrain and a tree 
for example:


Code:

osg::ref_ptr<osg::EllipsoidModel> ellipsoid = new osg::EllipsoidModel();
        osg::ref_ptr<osg::MatrixTransform> transform = new 
osg::MatrixTransform();
        float lat = 50.0;
        float lon = 50.0;
        float altitude = 1000.0;
        osg::Matrixd position;
        
ellipsoid->computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(lat),osg::DegreesToRadians(lon),
 altitude, position);
        transform->setMatrix(position);

osg::ref_ptr<osg::Group> root = new osg::Group();
        root->addChild(terrain);
        root->addChild(transform);
        transform->addChild(tree);




------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=42745#42745





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to