On 8/8/2010 6:45 PM, Robert Youngren wrote:
Hi,

Right, I understand that I can make a call to osg::Image::getColor(s,t), 
however how do I convert from world coordinates (intersection on the object) to 
texture coordinates?  Is there a method in osg to do this, or do I need to come 
up with a coordinate transformation matrix?  Clearly this has had to have been 
done.

From your intersection, along with the actual point of intersection, you should be able to get the geometry and primitive that was intersected. From this, you can get the vertices and texture coordinates. To do this you'll need to look up the primitive itself in the primitive set, using the primitive index given by the intersection, then figure out which vertices go with that primitive (how you do this depends on what kind of primitive set is in use). You'll then have to use the local to world transform (also available from the intersection) to convert the primitive's vertices to world space. Once you have the point of intersection and the vertices (all in world coordinates), you can interpolate the texture coordinates associated with each vertex to find out precisely which texel was hit.

It's a bit tedious to write all the code to do this digging, but it is possible.


   I guess I can look at the osg source to see how an image is texture mapped 
onto a 3d object and just do the reverse?

Actually, no, because this is normally done by OpenGL on the graphics hardware for you. Also, you're not doing the reverse of texture mapping, you're actually emulating the texture mapping process exactly (i.e.: you're finding out what color goes on a given pixel, just like OpenGL does).

--"J"

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to