Improved background sprite placement logic: orientation of the cell edges determined by their normals instead of their position relative to the cell

This commit is contained in:
Regalis
2016-09-27 20:18:55 +03:00
parent 7f543c394a
commit 9b15d2f894
3 changed files with 59 additions and 37 deletions

View File

@@ -218,10 +218,25 @@ namespace Voronoi2
{
return cell1;
}
else
return null;
}
/// <summary>
/// Returns the normal of the edge that points outwards from the specified cell
/// </summary>
public Vector2 GetNormal(VoronoiCell cell)
{
Vector2 dir = Vector2.Normalize(point1 - point2);
Vector2 normal = new Vector2(dir.Y, -dir.X);
if (cell != null && Vector2.Dot(normal, Vector2.Normalize(Center - cell.Center)) < 0)
{
return null;
normal = -normal;
}
return normal;
}
}