Hej,
I have a problem calculating texture coordinates.
Here is what I want to do:
farm3.static.flickr.com/2669/3923137706_a3e91e513b.jpg
(Sorry, I am not allowed to include the image directly.)
I have a texture to the left and a (2d) shape with multiple vertices to the right. The shape should function like a mask for the texture.
I try to draw the shape with the correct texture coordinates but it seems that I am too stupid to get the calculations right.
If the texture would be rectangular as shown in the image it would be easy ... something like this I suppose:
Code:for (int i = 0; i < 5; i++) {
vertex(p[i].x, p[i].y,(p[i].x-k[0].x)/(k[1].x-k[0].x),(p[i].y-k[1].y)/(k[2].y-k[1].y));
}
Where 5 is the amount of vertices and p[] are the vertices of the (mask)shape and k[] are the imaginary coordinates of the texture around the shape. I tried it and it seems to work.
But when it comes to a not rectangular shape I am helpless.
I would really appreciate some hints (or code ... or formulas).
Thanks!
P.S.: In case you are wondering: I want to render some animation offscreen and then draw shapes for projection mapping with the mouse (while projecting on geometry) and afterwards add four points around each shape for an imaginary texture frame. The shapes then should be drawn with a texture. At the end I have serveral non rectangular canvases to display the offscreen animation.