karcios Newbie
Joined: 12 Feb 2016 Posts: 11
|
Posted: Wed Apr 11, 2018 12:45 pm Post subject: OSG & QtQuick(QML) & setMirrorVertically mouse position problem with Picking |
|
|
Hi,
QtQuick is integrated with OpenSceneGraph (osgEarth) via method 'QQuickFramebufferObject'
In QQuickFramebufferObject I had to use setMirrorVertically(true);
to get the right osg view (without mirror reflection).
The problem is with picking objects.
To get world coords from mouse position I use:
Code:
|
...
osg::Matrixd matrix;
matrix.postMult(camera->getViewMatrix());
matrix.postMult(camera->getProjectionMatrix());
matrix.postMult(camera->getViewport()->computeWindowMatrix());
...
|
but it doesn't work
If I remove line:
Code:
|
matrix.postMult(camera->getViewport()->computeWindowMatrix());
|
everything works fine.
But I also checked other solution and when I use
Code:
|
...
osg::Matrixd matrix;
matrix.postMult(camera->getViewMatrix());
matrix.postMult(camera->getProjectionMatrix());
//ORIGINAL Viewport:
//inline const osg::Matrix computeWindowMatrix() const
//{
//return osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*width(),0.5*height(),0.5f)*osg::Matrix::translate(x(),y(),0.0f); // usually x()=0, y()=0, camera->setViewport(new osg::Viewport(0, 0, width(), height()));
//}
osg::Matrix testWindowMatrix = osg::Matrix::translate(1.0,1.0,1.0)*osg::Matrix::scale(0.5*WindowWidth(),0.5*WindowHeight(),0.5f)*osg::Matrix::translate(-MousePositionX, -WindowHeight()+MousePositionY,0.0f);
matrix.postMult(testWindowMatrix);
...
|
then everything is fine.
Is it possible to inject somewhere MousePositionX,MousePositionY into the osg system?
(Then I would use osgEarth IntersectionPicker/getWorldCoordsUnderMouse() out of box)
Or maybe
ProjectionMatrix and WindowMatrix should be const, so It looks like a problem with ViewMatrix (wrong/inverted mouse positions etc)
Any ideas?
Thank you!
Cheers,
Wojtek |
|