Created
September 25, 2015 18:32
-
-
Save battleguard/e644e5aaa5634684da4f to your computer and use it in GitHub Desktop.
initial state of coordinateTranslation has the Y axis inverted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <osgViewer\Viewer> | |
#include <osgEarthDrivers\gdal\GDALOptions> | |
#include <osgEarth\ImageLayer> | |
#include <osgEarth\MapNode> | |
#include <osgEarthUtil\EarthManipulator> | |
#include <iostream> | |
#include <osg\ShapeDrawable> | |
public class PointInCenterScreen : public osg::Operation { | |
public: | |
#define RADIUS 10000 | |
PointInCenterScreen(osgViewer::Viewer* viewer, | |
osgEarth::Util::EarthManipulator* manipulator) { | |
setKeep(true); | |
_viewer = viewer; | |
_manipulator = manipulator; | |
_box = new osg::Box(osg::Vec3d(), RADIUS); | |
_drawable = new osg::ShapeDrawable(_box); | |
_drawable->setColor(osg::Vec4(0.0, 1.0, 0.0, 1.0)); | |
osg::Group* root = reinterpret_cast<osg::Group*>(viewer->getSceneData()); | |
root->addChild(_drawable); | |
} | |
virtual void operator()(osg::Object *object) { | |
osg::Viewport* vp = _viewer->getCamera()->getViewport(); | |
osg::Vec3d world; | |
_manipulator->screenToWorld(vp->width() / 2.0, vp->height() / 2.0, _viewer->getCamera()->getView(), world); | |
_box->setCenter(world); | |
_drawable->dirtyDisplayList(); | |
_drawable->dirtyBound(); | |
if (_viewer->getFrameStamp()->getFrameNumber() % 60 == 0) { | |
osg::Vec3d geo; | |
_manipulator->getViewpoint().focalPoint()->getSRS()->transformFromWorld(world, geo); | |
std::cout << geo.x() << "," << geo.y() << "," << geo.z() << std::endl; | |
} | |
} | |
osgViewer::Viewer* _viewer; | |
osgEarth::Util::EarthManipulator* _manipulator; | |
osg::ShapeDrawable* _drawable; | |
osg::Box* _box; | |
}; | |
int main() { | |
osgViewer::Viewer* viewer = new osgViewer::Viewer; | |
viewer->setUpViewInWindow(100, 100, 1000, 1000, 0); | |
osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode; | |
viewer->setSceneData(mapNode.get()); | |
osgEarth::Drivers::GDALOptions gdalOptions; | |
gdalOptions.url() = osgEarth::URI("world.tif"); | |
gdalOptions.extensions() = "tif"; | |
mapNode->getMap()->addImageLayer(new osgEarth::ImageLayer(gdalOptions)); | |
osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator; | |
viewer->setCameraManipulator(manip); | |
manip->setViewpoint(osgEarth::Viewpoint("", 74.0, 42.0, 0.0, 0.0, -90.0, 1000000)); | |
osg::Operation* update = new ::PointInCenterScreen(viewer, manip); | |
viewer->addUpdateOperation(update); | |
viewer->run(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment