From cfe376b644e242ee3268b41ce7c68d1f99e40d77 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Mar 2004 16:12:11 +0000 Subject: [PATCH] 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." --- include/osgSim/GeographicLocation | 87 +++++++++++++++++++++++++++++++ src/osgPlugins/flt/FltFile.cpp | 32 +++++++++++- src/osgPlugins/flt/FltFile.h | 1 + 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 include/osgSim/GeographicLocation diff --git a/include/osgSim/GeographicLocation b/include/osgSim/GeographicLocation new file mode 100644 index 000000000..e0b9c5269 --- /dev/null +++ b/include/osgSim/GeographicLocation @@ -0,0 +1,87 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGSIM_GEOGRAPHICLOCATION +#define OSGSIM_GEOGRAPHICLOCATION 1 + +#include +#include + +#include + +namespace osgSim { + +/** Stores a double precision geographic location, latitude and longitude. + Derived from Referenced so it can be used as an osg::Object userData. +*/ + +class GeographicLocation : public osg::Referenced +{ + public: + + GeographicLocation() { _v[0]=0.; _v[1]=0.; } + GeographicLocation( double lat, double lon ) { _v[0]=lat; _v[1]=lon; } + + inline bool operator == ( const GeographicLocation& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; } + inline bool operator != ( const GeographicLocation& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; } + inline bool operator < ( const GeographicLocation& v) const + { + if (_v[0]v._v[0]) return false; + else if (_v[1] #include +#include + #include @@ -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 loc = new osgSim::GeographicLocation; + double lat, lon; + getOrigin( lat, lon ); + loc->set( lat, lon ); + model->setUserData( loc.get() ); + + osg::notify(osg::INFO)<<"FltFile::readNode("<