How to translate screen coordinate to texture coordiante?

Started by
3 comments, last by langtudontinh 19 years, 2 months ago
I have an image texture displayed on screen, the problem is I want to get mouse input and translate its position to texture coordinate. Just want to draw multi-line on the texture. I greatly appreciate your answer!
Advertisement
Assuming that the texture is on a rect whose top-left corner is at (x,y)
tu = (screen_x - x)/texture_width
tv = (screen_y - y)/texture_height

Thank for your reply.
I understand the formula, but I think you missed my question. I don't know howto map the mouse-clicked position (2D space) to 3D space (the camera placed at any position in world space), then this point will be translated to a texture coordinate.
What you are trying to do is commonly referred to as "picking". There are lots of topics floating around here about it (unfortunately, the search has been "Temporarily Disabled" for like a billion freaking days - you can still do a less-effective Google search though).

This may be a helpful topic.
Improved Ray Picking
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
That's the thing I need, thank you very much!!!

This topic is closed to new replies.

Advertisement