Texture Maps / Coordinate Systems

Started by
6 comments, last by LoPing 18 years, 10 months ago
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.
Advertisement
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
Quote:Original post by Fahrenheit451
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



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!


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.               .. . . . . . . . .

Quote:Original post by James Trotter
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
. .
. . . . . . . . .


Thank you :)
Quote:Original post by James Trotter
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.               .. . . . . . . . .


Thank you :)
http://www.opengl.org/documentation/specs/version1.2/opengl1.2.1.pdf

Download that file. Read page 71. It explains how the formulae used in OpenGL to interpolate texture coordinates (and other things).
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!

This topic is closed to new replies.

Advertisement