Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zoom to mouse makes map disappear #2293

Open
OlaRune opened this issue Jun 1, 2023 · 2 comments
Open

Zoom to mouse makes map disappear #2293

OlaRune opened this issue Jun 1, 2023 · 2 comments
Labels
defect It's busted

Comments

@OlaRune
Copy link
Contributor

OlaRune commented Jun 1, 2023

Using the following earth file:

<map>
    <options>
	<profile>spherical-mercator</profile>
    </options>
    <GDALImage name="World">
        <url>../geodata/world.tif</url>
    </GDALImage>
</map>

Using the following code:

#define NOMINMAX // To force windows.h to not define macros that interfere with std::min and std::max
#include <windows.h> // Needed by openGL

#include <osgDB/ReadFile>

#include <osgEarth/MapNode>
#include <osgEarth/EarthManipulator>
#include <osgViewer/Viewer>
#include <osgEarth/GLUtils>

int main()
{
	osgEarth::setNotifyLevel(osg::INFO); // FATAL WARN NOTICE INFO DEBUG_INFO
	std::string earthPath = "world_spherical_mercator.earth";
	osgEarth::MapNode* mapNode = osgEarth::MapNode::get(osgDB::readNodeFile(earthPath));

	// Setup viewer
	osgViewer::Viewer* viewer = new osgViewer::Viewer();
	osgEarth::GLUtils::setGlobalDefaults(viewer->getCamera()->getOrCreateStateSet());
	viewer->setUpViewInWindow(0, 0, 1024, 768);
	viewer->setSceneData(mapNode);

	osg::ref_ptr<osg::Camera> camera = viewer->getCamera();
	osgEarth::GLUtils::setGlobalDefaults(camera->getOrCreateStateSet());
	camera->setDrawBuffer(GL_BACK);
	camera->setReadBuffer(GL_BACK);
	double left = 0.0;
	double right = left + 1024.0;
	double bottom = 0.0;
	double top = bottom + 768.0;
	double zNear = 1.0;
	double zFar = 100000000.0; // Not sure what value is reasonable here to be able to zoom far out, but it doesn't seem to affect my problem
	camera->setProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar);

	// Setup manipulator
	osg::ref_ptr<osgEarth::EarthManipulator> manipulator = new osgEarth::EarthManipulator();
        manipulator->getSettings()->setZoomToMouse(true); // For some reason this makes the map disappear when zooming out
	viewer->setCameraManipulator(manipulator);

	return viewer->run();
}

When zooming out too far the map disappears, but grabbing it with LMB and panning a bit makes it reappear. Commenting out the setZoomToMouse(true) line fixes the issue. The issue is only present when zooming out with the scroll wheel, zooming out with double right click works as intended.

If I skip defining my own projection matrix the map doesn't disappear, but instead locks up when zooming out too far, and doesn't let me zoom back in. Any ideas? Is there a problem with the calculations for zoom to mouse, or am I doing something wrong?

@gwaldron
Copy link
Owner

gwaldron commented Jun 1, 2023

There may be issues with zoom-to-mouse in orthographic mode. One workaround may be to call manipulator->setMinMaxDistance() to restrict how far out you can zoom.

We also pushed a patch that was preventing zoom-to-mouse from doing anything in ortho mode. It still doesn't seem to actually zoom to the mouse.

@gwaldron gwaldron added the defect It's busted label Jun 1, 2023
@OlaRune
Copy link
Contributor Author

OlaRune commented Jun 2, 2023

There may be issues with zoom-to-mouse in orthographic mode. One workaround may be to call manipulator->setMinMaxDistance() to restrict how far out you can zoom.

We also pushed a patch that was preventing zoom-to-mouse from doing anything in ortho mode. It still doesn't seem to actually zoom to the mouse.

Thanks! I'll just not use zoom to mouse for now.

Just to let you know it seems to zoom to mouse correctly with an orthographic matrix for me, using the latest released version of OSG Earth. I just have the disappearing issue..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect It's busted
Projects
None yet
Development

No branches or pull requests

2 participants