本文整理汇总了C#中Texture2D.GetData方法的典型用法代码示例。如果您正苦于以下问题:C# Texture2D.GetData方法的具体用法?C# Texture2D.GetData怎么用?C# Texture2D.GetData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture2D
的用法示例。
在下文中一共展示了Texture2D.GetData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateTreePositions
private static List<Vector3> generateTreePositions(Texture2D treeMap, GroundMap groundMap, ColorSurface normals)
{
var treeMapColors = new Color[treeMap.Description.Width*treeMap.Description.Height];
treeMap. GetData(treeMapColors);
var sz = new Size2(treeMap.Description.Width, treeMap.Description.Height);
var noiseData = new int[sz.Width,sz.Height];
for (var x = 0; x < sz.Width; x++)
for (var y = 0; y < sz.Height; y++)
noiseData[x, y] = treeMapColors[y + x*sz.Height].R;
var treeList = new List<Vector3>();
var random = new Random();
var minFlatness = (float) Math.Cos(MathUtil.DegreesToRadians(15));
for (var y = normals.Height - 2; y > 0; y--)
for (var x = normals.Width - 2; x > 0; x--)
{
var terrainHeight = groundMap[x, y];
if ((terrainHeight <= 8) || (terrainHeight >= 14))
continue;
var flatness1 = Vector3.Dot(normals.AsVector3(x, y), Vector3.Up);
var flatness2 = Vector3.Dot(normals.AsVector3(x + 1, y + 1), Vector3.Up);
if (flatness1 <= minFlatness || flatness2 <= minFlatness)
continue;
var relx = (float) x/normals.Width;
var rely = (float) y/normals.Height;
float noiseValueAtCurrentPosition = noiseData[(int) (relx*sz.Width), (int) (rely*sz.Height)];
float treeDensity;
if (noiseValueAtCurrentPosition > 200)
treeDensity = 3;
else if (noiseValueAtCurrentPosition > 150)
treeDensity = 2;
else if (noiseValueAtCurrentPosition > 100)
treeDensity = 1;
else
treeDensity = 0;
for (var currDetail = 0; currDetail < treeDensity; currDetail++)
{
var rand1 = (float) random.NextDouble();
var rand2 = (float) random.NextDouble();
treeList.Add(new Vector3(
x + rand1,
groundMap.GetExactHeight(x, y, rand1, rand2),
y + rand2));
}
}
return treeList;
}
示例2: getPixel
public static int getPixel(int x, int y)
{
if ((x > 0 && y > 0 && x < gxtkApp.game.app.graphics.Width()) && (y < gxtkApp.game.app.graphics.Height()))
{
Texture2D backBufferData = new Texture2D(
gxtkApp.game.app.graphics.device,
gxtkApp.game.app.graphics.Width(),
gxtkApp.game.app.graphics.Height());
Rectangle sourceRectangle = new Rectangle(x, y, 1, 1);
Color[] retrievedColor = new Color[1];
backBufferData.GetData<Color>(
0,
sourceRectangle,
retrievedColor,
0,
1);
bb_std_lang.Print("x="+x+",y="+y+" col="+retrievedColor[0].ToString());
}
return 0;
}
示例3: CopyTextureData
private static Color[,] CopyTextureData(Texture2D texture)
{
Color[] data = new Color[texture.Width * texture.Height];
texture.GetData(data);
Color[,] result = new Color[texture.Height, texture.Width];
for (int y = 0; y < texture.Height; y++)
{
for (int x = 0; x < texture.Width; x++)
{
result[y, x] = data[(y * texture.Width) + x];
}
}
return result;
}