Fixed unity terrain generation bug.

This commit is contained in:
2015-03-19 12:34:58 +02:00
parent 8f9f935796
commit 68140b11a7
40 changed files with 326 additions and 245 deletions

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace TransportGame.MapViewer.Model
{
public class Bitmap24
{
/// <summary>
/// Gets the width of the bitmap
/// </summary>
public int Width { get; private set; }
/// <summary>
/// Gets the height of the bitmap
/// </summary>
public int Height { get; private set; }
/// <summary>
/// Gets the raw bytes of the bitmap
/// </summary>
public byte[] Raw { get; private set; }
/// <summary>
/// Initializes a bitmap
/// </summary>
/// <param name="w"></param>
/// <param name="h"></param>
public Bitmap24(int w, int h)
{
Width = w;
Height = h;
Raw = new byte[w * h * 3];
}
/// <summary>
/// Gets or sets a pixel
/// </summary>
/// <param name="x">x coordinate of pixel</param>
/// <param name="y">y coordinate of pixel</param>
public Color this[int x, int y]
{
get
{
int index = RawIndexOf(x, y);
return Color.FromRgb(Raw[index], Raw[index + 1], Raw[index + 2]);
}
set
{
int index = RawIndexOf(x, y);
Raw[index] = value.R;
Raw[index + 1] = value.G;
Raw[index + 2] = value.B;
}
}
private int RawIndexOf(int x, int y)
{
if (x < 0 || x >= Width)
throw new ArgumentOutOfRangeException("x is out of range");
if (y < 0 || y >= Height)
throw new ArgumentOutOfRangeException("x is out of range");
return 3 * (x + y * Width);
}
}
}