/// <summary> /// Charge une matrice de régions /// </summary> /// <param name="dimensions">Dimensions de la scène</param> /// <param name="hotspots">Liste de hotspots</param> /// <param name="matrixPrecision"></param> /// <returns>Matrice d'octets</returns> public void CreateRegionMatrix(VO_Stage stage, System.Drawing.Size dimensions, List <VO_StageRegion> hotspots, int matrixPrecision) { if (!Directory.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes))) { Directory.CreateDirectory(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes)); } StreamWriter sw = new StreamWriter(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_r"); byte[,] matrix = new byte[4096, 4096]; int height = dimensions.Height / matrixPrecision; int width = dimensions.Width / matrixPrecision; for (int y = 0; y <= height; y++) { for (int x = 0; x < width; x++) { matrix[x, y] = (byte)stage.Region; foreach (VO_StageRegion hotspot in hotspots) { if (FormsTools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points))) { matrix[x, y] = (byte)ConvertTools.CastInt(hotspot.Ratio); } } sw.Write(GetValueFromByte(matrix[x, y])); } sw.Write("\r\n"); } sw.Close(); }
/// <summary> /// Créer matrix walkable /// </summary> /// <param name="dimensions"></param> /// <param name="stage"></param> /// <param name="matrixPrecision"></param> private void CreateWalkableMatrix(System.Drawing.Size dimensions, VO_Stage stage, int matrixPrecision) { if (!Directory.Exists(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes))) { Directory.CreateDirectory(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes)); } StreamWriter sw = new StreamWriter(PathTools.GetProjectPath(Enums.ProjectPath.Matrixes) + stage.Id.ToString() + "_w"); byte[,] matrix = new byte[4096, 4096]; int height = dimensions.Height / matrixPrecision; int width = dimensions.Width / matrixPrecision; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { matrix[x, y] = 0; byte i = 1; foreach (VO_Layer layer in stage.ListLayers) { foreach (VO_StageHotSpot hotspot in layer.ListWalkableAreas) { if (FormsTools.PointInPolygon(new Point(x, y), ConvertPointsForMatrix(matrixPrecision, hotspot.Points))) { matrix[x, y] = i; break; } } i++; } sw.Write(GetValueFromByte(matrix[x, y])); } sw.Write("\r\n"); } sw.Close(); }