Hi,
I've done some research and I still think there is a bug in revision 13092.
I have rewritten the old code, and now I'm using osgQt::GraphicsWindowQt to
connect Qt and OSG. I based my implementation on the osgviewerQt example. The
osg code is used to show a map of the scene in Orthogonal projection. The idea
is to be able to move the map around with left mouse button. I would like the
map to be "glued" to the cursor (if you grab a map at one place and move tho
cursor, the part of land under the cursor is the same all the time). That is
why i need to set the projection matrix at every map widget resize with:
Code:
void MapViewWidget::resizeEvent( QResizeEvent* event ){
getCamera()->setProjectionMatrixAsOrtho( -event->size().width(),
event->size().width(), -event->size().height(), event->size().height(), 0.1,
10000 );
}
next the camera movement is calculated in a manipulator like this:
Code:
bool MapManipulator::performMovementLeftMouseButton( const double
eventTimeDelta, const double dx, const double dy )
{
if (disableMovement){
return false;
}
float scale = viewMatrix.getScale()[0];
osg::Matrixd translation;
double viewportWidth = 1.0;
double viewportHeight = 1.0;
if (camera.valid()){
viewportWidth = camera->getViewport()->width();
viewportHeight = camera->getViewport()->height();
}
viewMatrix = viewMatrix * translation.translate(-scale*dx*viewportWidth,
-scale*dy*viewportHeight, 0);
double desiredAlt =
altitudoMeter.calculateAltitude(viewMatrix.getTrans()[0],
viewMatrix.getTrans()[1]) + scaleToAltitude(scale);
viewMatrix = viewMatrix *
translation.translate(0,0,desiredAlt-viewMatrix.getTrans()[2]);
isFollowing = false;
return true;
}
so the camera movement is the wieportSize * mouseMovement * actualScale.
I expect the mouseMovement value to be normalized (between -1 and 1).
Now the problem is, that before revision 13092 the mouse movement was
normalized properly (devided by actual widget size). After the revision 13092
it is always devided by the value i use in traits when creating
osgQt::GraphicsWindowQt. So for example if i create osgQt::GraphicsWindowQt
like this:
Code:
QWidget* MapViewWidget::constructWidget(){
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->windowName = "MapWindowView";
traits->windowDecoration = false;
traits->x = 0;
traits->y = 0;
traits->width = 800;
traits->height = 600;
traits->doubleBuffer = true;
traits->supportsResize = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
traits->vsync = false;
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
osgQt::GraphicsWindowQt* graphicsWindowQt = new
osgQt::GraphicsWindowQt(traits.get());
graphicsWindowQt->realize();
camera->setGraphicsContext( graphicsWindowQt );
camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height)
);
camera->setProjectionMatrixAsOrtho( -800, 800, -600, 600, 0.1, 10000 );
setCamera( camera );
addEventHandler( new osgViewer::StatsHandler );
return graphicsWindowQt->getGLWidget();
}
Then the x mouse coordinate is normalized by 800 and y coordinate by 600.
Thank you!
Cheers,
Łukasz
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=48813#48813
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org