From Paul Martz, with a couple of mods by Robert Osfield:

"Changes to return the lat/long origin of an
OpenFlight model as userData of the root node object."
This commit is contained in:
Robert Osfield
2004-03-02 16:12:11 +00:00
parent adcb6665d4
commit cfe376b644
3 changed files with 119 additions and 1 deletions

View File

@@ -13,6 +13,8 @@
#include <osgDB/FileUtils>
#include <osgDB/FileNameUtils>
#include <osgSim/GeographicLocation>
#include <string>
@@ -89,7 +91,21 @@ osg::Node* FltFile::readNode(const std::string& fileName)
if (readModel(fileName))
{
// Convert record tree to osg scene graph
return convert();
osg::Node* model = convert();
if (model)
{
// Store model origin in returned Node userData.
osg::ref_ptr<osgSim::GeographicLocation> loc = new osgSim::GeographicLocation;
double lat, lon;
getOrigin( lat, lon );
loc->set( lat, lon );
model->setUserData( loc.get() );
osg::notify(osg::INFO)<<"FltFile::readNode("<<fileName<<") lat="<<lat<<" lon="<<lon<<std::endl;
return model;
}
}
return NULL;
@@ -254,6 +270,20 @@ int FltFile::getFlightVersion() const
}
void FltFile::getOrigin( double& latitude, double& longitude ) const
{
if (_headerRecord.get())
{
SHeader* pSHeader = (SHeader*)_headerRecord.get()->getData();
if (pSHeader)
{
latitude = pSHeader->Origin.x();
longitude = pSHeader->Origin.y();
}
}
}
std::string FltFile::getDesiredUnitsString() const
{
switch (_desiredUnits)