How to translate screen coordinate to texture coordiante?
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!
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
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.
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
This may be a helpful topic.
Improved Ray Picking
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement