My camera looks like this:
I am trying to add 2D polygons to the screen based on the percentage that they take up of a 1920x1080 pixel canvas. Therefore, I calculate this and then use Camera.ViewportToWorldPoint() to determine the world point for the mesh vertices. Below you can see how I declare vertices and uvs (I am confident my triangles are correct) for the polygon.
foreach (var point in poly.path)
{
uv.Add(new Vector2((float)(point.X - envelope.left) / (envelope.right - envelope.left), (float)(point.Y - envelope.bottom) / (envelope.top - envelope.bottom)));
}
I assume this is the correct way to calculate the uvs since they are basically the percentage that vertices lie within the bounds of the polygon's bounding envelope.
Here is what I am not so sure on. When I set the vertices like so (assume temp is the array of vertices used):
var temp = new List<Vector3>();
var envelope = GetEnvelope();
foreach (var point in path)
{
var vect = new Vector3((float)(point.X - envelope.left) / (envelope.right - envelope.left),
(float)(point.Y - envelope.bottom) / (envelope.top - envelope.bottom), 1.0f);
temp.Add(camera.ViewportToWorldPoint(vect));
}
return temp.ToArray();
everything works and the polygon is displayed to my screen except it scales so that the polygon draws as though the viewport is the entire envelope. I expect this, however it is not the functionality I want. So instead I try and declare vertices like so in order to have the polygon displayed in its correct relative position on the screen:
var temp = new List<Vector3>();
foreach (var point in path)
{
var vect = new Vector3((float)point.X/1920,
(float)point.Y/1080, 1.0f);
temp.Add(camera.ViewportToWorldPoint(vect));
}
return temp.ToArray();
however when I set the vertices this way, I no longer see the meshes being rendered. My goal with changing the code to this is to have the polygons be their true size on the screen as they are on the 1920x1080 canvas rather than being skewed as they are in the code that I said was working. Am I misunderstanding how vertices and uvs relate?
Thank for any help!