31
Graphics / Re: how to render line with SFML?
« on: December 03, 2015, 08:46:45 am »
I got it
Code is here:
So simple primitive and so complicated code with SFML...
Code is here:
public static void DrawLine(this RenderTarget target, Vector2f start, Vector2f end, float thickness, Color color)
{
var dv = end - start;
var dl = (float)Math.Sqrt(dv.X * dv.X + dv.Y * dv.Y);
var uv = dv / dl;
var up = new Vector2f(-uv.Y, uv.X);
var offset = up * (thickness / 2F);
var array = new[]
{
new Vertex(start + offset, color),
new Vertex(end + offset, color),
new Vertex(end - offset, color),
new Vertex(start - offset, color),
};
target.Draw(array, PrimitiveType.Quads);
}
{
var dv = end - start;
var dl = (float)Math.Sqrt(dv.X * dv.X + dv.Y * dv.Y);
var uv = dv / dl;
var up = new Vector2f(-uv.Y, uv.X);
var offset = up * (thickness / 2F);
var array = new[]
{
new Vertex(start + offset, color),
new Vertex(end + offset, color),
new Vertex(end - offset, color),
new Vertex(start - offset, color),
};
target.Draw(array, PrimitiveType.Quads);
}
So simple primitive and so complicated code with SFML...