diff --git a/src/osgViewer/ViewerEventHandlers.cpp b/src/osgViewer/ViewerEventHandlers.cpp index 46123ef8a..e8e7af0fb 100644 --- a/src/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgViewer/ViewerEventHandlers.cpp @@ -20,7 +20,11 @@ #include #include + #include +#include +#include +#include #include #include @@ -647,11 +651,38 @@ bool InteractiveImageHandler::mousePosition(osgViewer::View* view, osg::NodeVisi tc = tc1*r1 + tc2*r2 + tc3*r3; } } - } - x = int( float(_image->s()) * tc.x() ); - y = int( float(_image->t()) * tc.y() ); + osg::TexMat* activeTexMat = 0; + osg::Texture* activeTexture = 0; + + if (geometry->getStateSet()) + { + osg::TexMat* texMat = dynamic_cast(geometry->getStateSet()->getTextureAttribute(0,osg::StateAttribute::TEXMAT)); + if (texMat) activeTexMat = texMat; + + osg::Texture* texture = dynamic_cast(geometry->getStateSet()->getTextureAttribute(0,osg::StateAttribute::TEXTURE)); + if (texture) activeTexture = texture; + } + + if (activeTexMat) + { + osg::Vec4 tc_transformed = osg::Vec4(tc.x(), tc.y(), 0.0f,0.0f) * activeTexMat->getMatrix(); + tc.x() = tc_transformed.x(); + tc.y() = tc_transformed.y(); + } + + if (dynamic_cast(activeTexture)) + { + x = int( tc.x() ); + y = int( tc.y() ); + } + else + { + x = int( float(_image->s()) * tc.x() ); + y = int( float(_image->t()) * tc.y() ); + } + return true; }