public static TextureBase FromVectors(string name, int size, double magnitude, params Vector2d[] dataset) { var data = new float[size, size]; for (int i = 0; i < dataset.Length; i++) { var fpixel = Vector2d.Multiply (dataset[i], 0.5 * size/magnitude) + new Vector2d(size * 0.5); data[(int)fpixel.Y % size, (int)fpixel.X % size] = 1; } var texture = new DataTexture<float> { Name = "from_vectors_" + name, InternalFormat = PixelInternalFormat.R32f, Data2D = data, Params = new TextureBase.Parameters { GenerateMipmap = false, MinFilter = TextureMinFilter.Linear, MagFilter = TextureMagFilter.Linear }}; return texture; }
private static ColorRamp FromValues(string name, params OpenTK.Graphics.Color4[] colors) { var sizeX = 2; var sizeY = 1; var data = new Color4[sizeY, sizeX]; //var dX = sizeX / (float)colors.Length; //var dY = sizeY / (float)colors.Length; // var colorIndex = 0; for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { //var t = dX * (j / colors.Length); var cindex = j % colors.Length; data[i, j] = colors[cindex]; } } var texture = new DataTexture<Color4> { Name = "color-ramp-" + name, InternalFormat = PixelInternalFormat.Rgb, Data2D = data, Params = new TextureBase.Parameters { GenerateMipmap = false, MinFilter = TextureMinFilter.Linear, MagFilter = TextureMagFilter.Linear }}; return new ColorRamp(name, texture); }
float HauteurPourPts(int posX, int posY) { return(DataTexture[DataTexture.GetLength(0) - CarteTerrain.Width * (posY + 1) + posX].B / MAX_COULEUR * Étendue.Y); }
public SpawnDataModel[] ParseTexture(string LevelName, int Row) { Texture2D DataTexture; if (m_TextureCaching.ContainsKey(LevelName)) { DataTexture = m_TextureCaching [LevelName]; } else { DataTexture = Resources.Load <Texture2D>(SPAWN_DATA_PATH + LevelName); } Color[] Pixels = DataTexture.GetPixels(); int len_x = DataTexture.width; SpawnDataModel[] SpawnDataSet = new SpawnDataModel[len_x]; // Skip if row is bigger than texture height if (DataTexture.height - 1 < Row) { return(SpawnDataSet); } for (int x = 0; x < len_x; x++) { SpawnDataSet [x] = new SpawnDataModel(); SpawnDataSet [x].Position = x; Color c = Pixels [x + Row * len_x]; if (c.Equals(NONE)) { SpawnDataSet [x].SpawnPattern = SpawnPattern.NONE; } else if (c.Equals(CURRENT_LEVEL)) { SpawnDataSet [x].SpawnPattern = SpawnPattern.CURRENT_LEVEL; } else if (c.Equals(CURRENT_LEVEL_PLUS_1)) { SpawnDataSet [x].SpawnPattern = SpawnPattern.CURRENT_LEVEL_PLUS_1; } else if (c.Equals(CURRENT_LEVEL_PLUS_2)) { SpawnDataSet [x].SpawnPattern = SpawnPattern.CURRENT_LEVEL_PLUS_2; } else if (c.Equals(OBSTACLE_BREAKABLE)) { SpawnDataSet [x].SpawnPattern = SpawnPattern.OBSTACLE_BREAKABLE; } else if (c.Equals(OBSTACLE_UNBREAKABLE)) { SpawnDataSet [x].SpawnPattern = SpawnPattern.OBSTACLE_UNBREAKABLE; } else { Debug.Log(CURRENT_LEVEL_PLUS_1); Debug.Log(CURRENT_LEVEL_PLUS_2); Debug.Log(OBSTACLE_BREAKABLE); Debug.Log(OBSTACLE_UNBREAKABLE); Debug.LogError("[-] No match color found." + c); Debug.Log(x + ", " + Row); Debug.Break(); } } return(SpawnDataSet); }