1
General discussions / Re: VertexArray transformations
« on: November 17, 2023, 12:08:12 am »
And here is refactored compact version if someone needs that kind of function.
public static VertexArray CreateMappedVertices(Vector2f position, IntRect textureRect, Transform transform)
{
VertexArray vertices = new VertexArray(PrimitiveType.Quads);
for (int i = 0; i < 4; ++i)
{
Vector2f point = transform.TransformPoint(new Vector2f(
(i == 1 || i == 2) ? textureRect.Width : 0,
(i == 2 || i == 3) ? textureRect.Height : 0
)) - position;
Vertex vertex = new Vertex(new Vector2f(position.X + point.X, position.Y + point.Y),
new Vector2f(textureRect.Left + ((i == 1 || i == 2) ? textureRect.Width : 0),
textureRect.Top + ((i == 2 || i == 3) ? textureRect.Height : 0)));
vertices.Append(vertex);
}
return vertices;
}
{
VertexArray vertices = new VertexArray(PrimitiveType.Quads);
for (int i = 0; i < 4; ++i)
{
Vector2f point = transform.TransformPoint(new Vector2f(
(i == 1 || i == 2) ? textureRect.Width : 0,
(i == 2 || i == 3) ? textureRect.Height : 0
)) - position;
Vertex vertex = new Vertex(new Vector2f(position.X + point.X, position.Y + point.Y),
new Vector2f(textureRect.Left + ((i == 1 || i == 2) ? textureRect.Width : 0),
textureRect.Top + ((i == 2 || i == 3) ? textureRect.Height : 0)));
vertices.Append(vertex);
}
return vertices;
}