当前位置: 首页>>代码示例>>C#>>正文


C# Texture2D.GetData方法代码示例

本文整理汇总了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;
        }
开发者ID:danbystrom,项目名称:VisionQuest,代码行数:52,代码来源:ReimersBillboards.cs

示例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;
    }
开发者ID:AlexBaklanov,项目名称:Seahorse,代码行数:24,代码来源:diddy.xna.cs

示例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;
        }
开发者ID:robertkety,项目名称:Hero6,代码行数:17,代码来源:Room.cs


注:本文中的Texture2D.GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。