/// <summary> /// Convert a texture to an sbtye array compatible with ApplyData(). /// </summary> /// <param name="texture">Texture to convert.</param> /// <param name="tester"></param> /// <returns></returns> public static sbyte[,] ConvertTextureToData(Texture2D texture, TerrainTester tester) { sbyte[,] data = new sbyte[texture.Width, texture.Height]; Color[] colorData = new Color[texture.Width * texture.Height]; texture.GetData(colorData); for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { bool inside = tester(colorData[(y * texture.Width) + x]); if (!inside) { data[x, y] = 1; } else { data[x, y] = -1; } } } return(data); }
/// <summary> /// Apply a texture to the terrain using the specified TerrainTester. /// </summary> /// <param name="texture">Texture to apply.</param> /// <param name="position">Top left position of the texture relative to the terrain.</param> /// <param name="tester">Delegate method used to determine what colors should be included in the terrain.</param> public void ApplyTexture(Texture2D texture, Vector2 position, TerrainTester tester) { Color[] colorData = new Color[texture.Width * texture.Height]; texture.GetData(colorData); for (int y = (int)position.Y; y < texture.Height + (int)position.Y; y++) { for (int x = (int)position.X; x < texture.Width + (int)position.X; x++) { if (x >= 0 && x < _localWidth && y >= 0 && y < _localHeight) { bool inside = tester(colorData[((y - (int)position.Y) * texture.Width) + (x - (int)position.X)]); if (!inside) { _terrainMap[x, y] = 1; } else { _terrainMap[x, y] = -1; } } } } // generate terrain for (int gy = 0; gy < _ynum; gy++) { for (int gx = 0; gx < _xnum; gx++) { //remove old terrain object at grid cell if (_bodyMap[gx, gy] != null) { for (int i = 0; i < _bodyMap[gx, gy].Count; i++) { World.RemoveBody(_bodyMap[gx, gy][i]); } } _bodyMap[gx, gy] = null; //generate new one GenerateTerrain(gx, gy); } } }
/// <summary> /// Apply a texture to the terrain using the specified TerrainTester. /// </summary> /// <param name="texture">Texture to apply.</param> /// <param name="position">Top left position of the texture relative to the terrain.</param> /// <param name="tester">Delegate method used to determine what colors should be included in the terrain.</param> public void ApplyTexture(int texture, Vector2 position, TerrainTester tester) { throw new System.NotImplementedException(); //Color[] colorData = new Color[texture.Width * texture.Height]; //texture.GetData(colorData); //for (int y = (int)position.Y; y < texture.Height + (int)position.Y; y++) //{ // for (int x = (int)position.X; x < texture.Width + (int)position.X; x++) // { // if (x >= 0 && x < _localWidth && y >= 0 && y < _localHeight) // { // bool inside = tester(colorData[((y - (int)position.Y) * texture.Width) + (x - (int)position.X)]); // if (!inside) // _terrainMap[x, y] = 1; // else // _terrainMap[x, y] = -1; // } // } //} //// generate terrain //for (int gy = 0; gy < _ynum; gy++) //{ // for (int gx = 0; gx < _xnum; gx++) // { // //remove old terrain object at grid cell // if (_bodyMap[gx, gy] != null) // { // for (int i = 0; i < _bodyMap[gx, gy].Count; i++) // { // World.RemoveBody(_bodyMap[gx, gy][i]); // } // } // _bodyMap[gx, gy] = null; // //generate new one // GenerateTerrain(gx, gy); // } //} }
/// <summary> /// Convert a texture to an sbtye array compatible with ApplyData(). /// </summary> /// <param name="texture">Texture to convert.</param> /// <param name="tester"></param> public static sbyte[,] ConvertTextureToData(int texture, TerrainTester tester) { throw new System.NotImplementedException(); //sbyte[,] data = new sbyte[texture.Width, texture.Height]; //Color[] colorData = new Color[texture.Width * texture.Height]; //texture.GetData(colorData); //for (int y = 0; y < texture.Height; y++) //{ // for (int x = 0; x < texture.Width; x++) // { // bool inside = tester(colorData[(y * texture.Width) + x]); // if (!inside) // data[x, y] = 1; // else // data[x, y] = -1; // } //} //return data; }
/// <summary> /// Apply a texture to the terrain using the specified TerrainTester. /// </summary> /// <param name="texture">Texture to apply.</param> /// <param name="position">Top left position of the texture relative to the terrain.</param> /// <param name="tester">Delegate method used to determine what colors should be included in the terrain.</param> public void ApplyTexture(Texture2D texture, Vector2 position, TerrainTester tester) { Color[] colorData = new Color[texture.Width * texture.Height]; texture.GetData(colorData); for (int y = (int)position.Y; y < texture.Height + (int)position.Y; y++) { for (int x = (int)position.X; x < texture.Width + (int)position.X; x++) { if (x >= 0 && x < _localWidth && y >= 0 && y < _localHeight) { bool inside = tester(colorData[((y - (int)position.Y) * texture.Width) + (x - (int)position.X)]); if (!inside) _terrainMap[x, y] = 1; else _terrainMap[x, y] = -1; } } } // generate terrain for (int gy = 0; gy < _ynum; gy++) { for (int gx = 0; gx < _xnum; gx++) { //remove old terrain object at grid cell if (_bodyMap[gx, gy] != null) { for (int i = 0; i < _bodyMap[gx, gy].Count; i++) { World.RemoveBody(_bodyMap[gx, gy][i]); } } _bodyMap[gx, gy] = null; //generate new one GenerateTerrain(gx, gy); } } }
/// <summary> /// Convert a texture to an sbtye array compatible with ApplyData(). /// </summary> /// <param name="texture">Texture to convert.</param> /// <param name="tester"></param> /// <returns></returns> public static sbyte[,] ConvertTextureToData(Texture2D texture, TerrainTester tester) { sbyte[,] data = new sbyte[texture.Width, texture.Height]; Color[] colorData = new Color[texture.Width * texture.Height]; texture.GetData(colorData); for (int y = 0; y < texture.Height; y++) { for (int x = 0; x < texture.Width; x++) { bool inside = tester(colorData[(y * texture.Width) + x]); if (!inside) data[x, y] = 1; else data[x, y] = -1; } } return data; }
/// <summary> /// Convert a texture to an sbtye array compatible with ApplyData(). /// </summary> /// <param name="texture">Texture to convert.</param> /// <param name="tester"></param> /// <returns></returns> public static sbyte[,] ConvertTextureToData(int texture, TerrainTester tester) { throw new System.NotImplementedException(); //sbyte[,] data = new sbyte[texture.Width, texture.Height]; //Color[] colorData = new Color[texture.Width * texture.Height]; //texture.GetData(colorData); //for (int y = 0; y < texture.Height; y++) //{ // for (int x = 0; x < texture.Width; x++) // { // bool inside = tester(colorData[(y * texture.Width) + x]); // if (!inside) // data[x, y] = 1; // else // data[x, y] = -1; // } //} //return data; }