Added EllipsoidLocator.
This commit is contained in:
parent
37dd2851e9
commit
e76e4e82db
@ -22,41 +22,6 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
class MyLocator : public osgTerrain::Locator
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
MyLocator(double x, double y, double width, double height):
|
||||
_x(x),
|
||||
_y(y),
|
||||
_width(width),
|
||||
_height(height) {}
|
||||
|
||||
|
||||
bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world)
|
||||
{
|
||||
world.x() = _x + local.x()*_width;
|
||||
world.y() = _y + local.y()*_height;
|
||||
world.z() = _z + local.z();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local)
|
||||
{
|
||||
local.x() = (world.x()- _x) / _width;
|
||||
local.y() = (world.y() - _y) / _height;
|
||||
local.z() = world.z() - _z;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
double _x;
|
||||
double _y;
|
||||
double _z;
|
||||
double _width;
|
||||
double _height;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@ -72,7 +37,7 @@ int main(int argc, char** argv)
|
||||
double h = 1.0;
|
||||
|
||||
osg::ref_ptr<osgTerrain::TerrainNode> terrain = new osgTerrain::TerrainNode;
|
||||
osg::ref_ptr<osgTerrain::Locator> locator = new MyLocator(0.0, 0.0, 1.0, 1.0);
|
||||
osg::ref_ptr<osgTerrain::Locator> locator = new osgTerrain::EllipsoidLocator(-osg::PI, -osg::PI*0.5, 2.0*osg::PI, osg::PI, 0.0);
|
||||
|
||||
|
||||
bool readParameter = false;
|
||||
@ -81,9 +46,10 @@ int main(int argc, char** argv)
|
||||
readParameter = false;
|
||||
std::string filename;
|
||||
|
||||
if (arguments.read("-l",x,y,w,h))
|
||||
if (arguments.read("-e",x,y,w,h))
|
||||
{
|
||||
locator = new MyLocator(x,y,w,h);
|
||||
// define the extents.
|
||||
locator = new osgTerrain::EllipsoidLocator(x,y,w,h,0);
|
||||
readParameter = true;
|
||||
}
|
||||
|
||||
@ -112,7 +78,7 @@ int main(int argc, char** argv)
|
||||
|
||||
}
|
||||
|
||||
if (arguments.read("-e",filename) || arguments.read("--elevation-image",filename))
|
||||
if (arguments.read("-h",filename) || arguments.read("--elevation-image",filename))
|
||||
{
|
||||
readParameter = true;
|
||||
osg::notify(osg::NOTICE)<<"--elevation-image "<<filename<<" x="<<x<<" y="<<y<<" w="<<w<<" h="<<h<<std::endl;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Vec3d>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
#include <osgTerrain/Export>
|
||||
|
||||
@ -32,8 +33,8 @@ class OSGTERRAIN_EXPORT Locator : public osg::Object
|
||||
|
||||
META_Object(osgTerrain, Locator);
|
||||
|
||||
virtual bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) { return false; };
|
||||
virtual bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) { return false; };
|
||||
virtual bool convertLocalToModel(const osg::Vec3d& /*local*/, osg::Vec3d& /*world*/) { return false; };
|
||||
virtual bool convertModelToWorld(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) { return false; };
|
||||
|
||||
protected:
|
||||
|
||||
@ -41,6 +42,40 @@ class OSGTERRAIN_EXPORT Locator : public osg::Object
|
||||
|
||||
};
|
||||
|
||||
class OSGTERRAIN_EXPORT EllipsoidLocator : public osgTerrain::Locator
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
EllipsoidLocator(double longitude, double latitude, double deltaLongitude, double deltaLatitude, double height=0.0);
|
||||
|
||||
void setExtents(double longitude, double latitude, double deltaLongitude, double deltaLatitude, double height=0.0);
|
||||
|
||||
double getLongitude() const { return _longitude; }
|
||||
double getDeltaLongitude() const { return _deltaLongitude; }
|
||||
|
||||
double getLatitude() const { return _latitude; }
|
||||
double getDeltaLatitude() const { return _deltaLatitude; }
|
||||
|
||||
double getHeight() const { return _height; }
|
||||
|
||||
osg::EllipsoidModel* getEllipsoidModel() { return _em.get(); }
|
||||
const osg::EllipsoidModel* getEllipsoidModel() const { return _em.get(); }
|
||||
|
||||
bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world);
|
||||
bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local);
|
||||
|
||||
protected:
|
||||
|
||||
osg::ref_ptr<osg::EllipsoidModel> _em;
|
||||
|
||||
double _longitude;
|
||||
double _latitude;
|
||||
double _deltaLongitude;
|
||||
double _deltaLatitude;
|
||||
double _height;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -15,6 +15,10 @@
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Locator
|
||||
//
|
||||
Locator::Locator()
|
||||
{
|
||||
}
|
||||
@ -27,3 +31,55 @@ Locator::Locator(const Locator& Locator,const osg::CopyOp& copyop):
|
||||
Locator::~Locator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// EllipsoidLocator
|
||||
//
|
||||
EllipsoidLocator::EllipsoidLocator(double longitude, double latitude, double deltaLongitude, double deltaLatitude, double height):
|
||||
_longitude(longitude),
|
||||
_latitude(latitude),
|
||||
_deltaLongitude(deltaLongitude),
|
||||
_deltaLatitude(deltaLatitude),
|
||||
_height(height)
|
||||
|
||||
{
|
||||
_em = new osg::EllipsoidModel;
|
||||
}
|
||||
|
||||
|
||||
void EllipsoidLocator::setExtents(double longitude, double latitude, double deltaLongitude, double deltaLatitude, double height)
|
||||
{
|
||||
_longitude = longitude;
|
||||
_latitude = latitude;
|
||||
_deltaLongitude = deltaLongitude;
|
||||
_deltaLatitude = deltaLatitude;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
bool EllipsoidLocator::convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world)
|
||||
{
|
||||
double longitude = _longitude + local.x() * _deltaLongitude;
|
||||
double latitude = _latitude + local.y() * _deltaLatitude;
|
||||
double height = _height + local.z();
|
||||
|
||||
_em->convertLatLongHeightToXYZ(latitude, longitude, height,
|
||||
world.x(), world.y(), world.z());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EllipsoidLocator::convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local)
|
||||
{
|
||||
double longitude, latitude, height;
|
||||
|
||||
_em->convertXYZToLatLongHeight(world.x(), world.y(), world.z(),
|
||||
latitude, longitude, height );
|
||||
|
||||
local.x() = (longitude-_longitude)/_deltaLongitude;
|
||||
local.y() = (latitude-_latitude)/_deltaLatitude;
|
||||
local.z() = height-_height;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user