Added handling of texture matrices and texture rectangles in InteractiveImageHandler

This commit is contained in:
Robert Osfield
2008-11-03 16:31:44 +00:00
parent 9bba7bbee0
commit c73f33d27c

View File

@@ -20,7 +20,11 @@
#include <sstream>
#include <osgDB/FileNameUtils>
#include <osg/Geometry>
#include <osg/TexMat>
#include <osg/TextureRectangle>
#include <osg/io_utils>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
@@ -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<osg::TexMat*>(geometry->getStateSet()->getTextureAttribute(0,osg::StateAttribute::TEXMAT));
if (texMat) activeTexMat = texMat;
osg::Texture* texture = dynamic_cast<osg::Texture*>(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<osg::TextureRectangle*>(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;
}