I would like to provide a user of osgWidget with the ability to get the
color value of any textured Widget, particularly whatever 2D coord the
mouse is currently over. I've played with a number of implementations
for doing this, but I wanted to get some opinions on what the BEST way
to do it is. (Also: this is just for osg::Texture2D at the moment)

When I want to calculate the color value I have access to the following

        - The GLOBAL mouse coords
        - The LOCAL mouse coords (relative to the Widget itself)
        - The tex coords of all 4 points of the quad (Widget)
        - The dimensions of the Widget (width, height, etc.)

In the simplest case, assuming the quad is "fully mapped" by the
texture, I can do something like the following:

        x = LocalMouseX / WidgetWidth
        y = LocalMouseY / WidgetHeight

...which, easily enough, will also give me the tex coord that I can pass
to osg::Image::getColor(). However, things become more complicated when
you only use a portion of the Image in your Widget's tex coord mapping,
and I've come up alternative ways of handling those scenarios, none of
which feel very "clean" or "proper."

Is there an arbitrary way to translate mouse coordinates (given the data
I have access to) into texture coordinates? I don't need the code to do
this, just some ideas to push me in the right direction...

osg-users mailing list

Reply via email to