# Texture Maps / Coordinate Systems

This topic is 4952 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've got a problem I've been racking my brain over and I can't seem to figure it out. Say I have a polygon, and it's on a plane, and it has 4 vertices. Now, I have a texture as well. Now, I know already how to map a texture to the polygon itself. However, what I want to do is map it the other way around. Basically, if I click on a texture pixel, I want to know what the approximate point within the polygon that texture pixel will be applied to. Or simply put another way, I want to map the coordinates of the polygon to the texture. The situation looks like this: Non-rectangle 4 vertex Polygon P: (x1,y1) ....... (x2,y2) . . . . . . . . (x4,y4) ............ (x5,y5) Texture T: (where width and height are in pixels and px & py is an arbitrary point) 1000 p . . . . . . . . . . . . .(px,py) . 500 p . . . . . . . . . . . So the idea is how can you figure out which coordinate pair on Polygon P do pixels px & py on the texture correspond to.

##### Share on other sites
It's not quite the right approach for finding points within a polygon, but I think your not after that exactly. What sounds to be the right thing to research are the various interpolation methods - especially bilinear. Based on what you descibe as wanting to do, I think bilinear interpolation would help find a point within your polygon (assuming the 4 vertices are on the same plane), which you can then use to calculate the appropriate pixel of your texture... if I am following you that is :-) There were some recent topics on interpolation methods, so you should get some quick ideas from doing a search of reading back through the threads here.

Sorry I can't be of more help. Perhaps things will become clearer as the dialogue/thread continues.

hth
F451

##### Share on other sites
Quote:
 Original post by Fahrenheit451It's not quite the right approach for finding points within a polygon, but I think your not after that exactly. What sounds to be the right thing to research are the various interpolation methods - especially bilinear. Based on what you descibe as wanting to do, I think bilinear interpolation would help find a point within your polygon (assuming the 4 vertices are on the same plane), which you can then use to calculate the appropriate pixel of your texture... if I am following you that is :-) There were some recent topics on interpolation methods, so you should get some quick ideas from doing a search of reading back through the threads here.Sorry I can't be of more help. Perhaps things will become clearer as the dialogue/thread continues.hthF451

Thank you for responding. I was looking into different interpolation methods, including anisotropic filters. I guess my issue is sort of like texture mapping in reverse, i'm mapping a polygon to a texture. Anyhow I suppose I'll just keep on searching and thinking about it, thanks again for the reply!

##### Share on other sites
I fixed up your ASCII diagrams. You can use the < pre > < /pre > tags.

Non-rectangle 4 vertex Polygon P:
(x1,y1) ....... (x2,y2)	.      .	.       .	.        .	.         .(x4,y4) ............ (x5,y5)

Texture T: (where width and height are in pixels and px & py is an arbitrary point)
1000 p . . . . . . . . ..               ..    .(px,py)   . 500 p.               .. . . . . . . . .

##### Share on other sites
Quote:
 Original post by James TrotterI fixed up your ASCII diagrams. You can use the < pre > < /pre > tags.Non-rectangle 4 vertex Polygon P: (x1,y1) ....... (x2,y2) . . . . . . . .(x4,y4) ............ (x5,y5)Texture T: (where width and height are in pixels and px & py is an arbitrary point)1000 p . . . . . . . . .. .. .(px,py) . 500 p. .. . . . . . . . .

Thank you :)

##### Share on other sites
Quote:
 Original post by James TrotterI fixed up your ASCII diagrams. You can use the < pre > < /pre > tags.Non-rectangle 4 vertex Polygon P: (x1,y1) ....... (x2,y2) . . . . . . . .(x4,y4) ............ (x5,y5)Texture T: (where width and height are in pixels and px & py is an arbitrary point)1000 p . . . . . . . . .. .. .(px,py) . 500 p. .. . . . . . . . .

Thank you :)

##### Share on other sites
Thanks for the help all, I figured out a solution. It involved backsolving using least squares, and it works pretty well. Hopefully that will be a clue for anyone trying to figure out something similar in the future!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015505
×