Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the height and width of a polygon on a certain plane
    text
    copied!<p>I'm currently using the following to apply a texture to a polygon formed by TriangleList</p> <pre><code>public static VertexPositionColorTexture[] TextureMapping(VertexPositionColorTexture[] vertices, float xScale, float yScale) { bool initialized = false; float x, y; float lX = 0, hX = 0, lY = 0, hY = 0; for (int i = 0; i &lt; vertices.Length; i++) { x = vertices[i].Position.X; y = vertices[i].Position.Y; if (!initialized) { hX = x; lX = x; hX = y; hY = y; initialized = true; } else { if (x &gt; hX) { hX = x; } else if (x &lt; lX) { lX = x; } if (y &gt; hY) { hY = y; } else if (y &lt; lY) { lY = y; } } } float width = (Math.Abs(lX) + Math.Abs(hX)) / xScale; float height = (Math.Abs(lY) + Math.Abs(hY)) / yScale; for (int i = 0; i &lt; vertices.Length; i++) { vertices[i].TextureCoordinate.X = vertices[i].Position.X / width; vertices[i].TextureCoordinate.Y = vertices[i].Position.Y / height; } return vertices; </code></pre> <p>This currently works fine for a polygon that has points that all have Z=0 (example: (0,0,0) (0,10,0) (10,10,0) (10,0,0)) but doesn't work for any that are rotated or not flat along the z (example (0,0,0) (0,0,10) (0,10,10) (0,10,0)). The only solution I have come with is to get the plane that the polygon lies on (it will always be flat) and somehow rotate or translate the vertices in the above method to flatten it to the xy line to allow for the correct height and width to be determined. Anyone point me in the right direction, or suggest something else?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload