Hey, I have a map made out of polygons. The polygon is made out of edges (lines) containing two points (p0 and p1).
On the edges of these polygons I draw decoration using a placeholder tiling texture:
The Y texture coordinate is always either 0 or 1 because i only want to tile horizontally.
The issue I am having is to calculate a good tiling X coordinate for the texture.
I tried:
//centre = (0,0)
x1 = distance(centre, edge.p0);
x2 = distance(centre edge.p1);
UV coordinates for my decoration quad will be:
x1,0
x2,0
x2,1
x1,1
The issue is that if I have two points in a polygon / edge that have the same distance from the centre, the texture coordinate will be the same which means the decoration will be rendered wrongly (The horizontal texture scale will increase to infinity)
To partially fix this, I instead get the distance from the centre to one point on the edge, and add then add the distance to the other:
x1 = distance(centre, edge.p0);
x2 = x1 + distance(edge.p1, edge.p2);
This fixes a single edge, but if I have multiple edges, the texture coords don’t match up because it’s based on the distance from one point on the edge to the centre of the map, Since the distance between two edges isn’t the same as the difference between the distance from one edge to the centre of the map and the distance from the other edge to the centre of the map.
EDIT: I can loop around a single polygon with the above method, starting at a single point and just adding the distance from one point to the next. (So x1 = x0 + distance(x0, x1), x2 = x1 + distance(x1, x2) etc.) The first and last point won’t match up, however they only would if the width of my tiling texture is equal to the sum of the lengths of the edges in the first place. I guess this is the best I can do, however if anyone has a better idea I’d be happy to hear it!
Thanks,
Roland