Exemplo n.º 1
0
        public MyGrassPatch(HeightMap heightMap, int size)
        {
            MyGrassPatch.width = size;
            MyGrassPatch.length = size;
            this.heightMap = heightMap;
            System.Random rSeed = new Random();

            //triangleCount = length * width * bladeBySquare * bladeBySquare * nbSegment * 2 * 4 * 2;
            triangleCount = length * width * bladeBySquare * bladeBySquare * nbSegment * 4;

            vertices = new DataStream((12+8) * triangleCount * 3, true, true);
            for (int i = 0; i < width;i++)
                for (int j = 0; j < length; j++)
                {
                    for (int xb = 0;xb < bladeBySquare;xb++)
                        for (int yb = 0; yb < bladeBySquare; yb++)
                        {
                            float x = i + xb * 1f / bladeBySquare + ((float)rSeed.NextDouble()-0.5f) * 0.2f;
                            float z = j + yb * 1f / bladeBySquare + ((float)rSeed.NextDouble() - 0.5f) * 0.2f;
                            //float x = i + xb * 1f / bladeBySquare;
                            //float z = j + yb * 1f / bladeBySquare;
                            addBlade(x, heightMap.getHeight(x, z), z, 1.0f + (float)rSeed.NextDouble() * 0.2f, (float)(rSeed.NextDouble()*Math.PI));
                        }
                }
            vertices.Position = 0;
        }
Exemplo n.º 2
0
        public MyTerrain(HeightMap heightMap,int size)
        {
            MyTerrain.width = size;
            MyTerrain.length = size;
            this.heightMap = heightMap;

            vertices = new DataStream((12+8) * triangleCount * 3, true, true);
            for (int i = 0; i < width;i++)
                for (int j = 0; j < length; j++)
                {
                    float height;
                    height = heightMap.getHeight((float)i, (float)j);
                    vertices.Write(new Vector3(0.0f + i, height, 0.0f + j));
                    vertices.Write(new Vector2(0.0f, 0.0f));
                    height = heightMap.getHeight((float)i, (float)j+1f);
                    vertices.Write(new Vector3(0.0f + i, height, 1.0f + j));
                    vertices.Write(new Vector2(0.0f, 0.0f));
                    height = heightMap.getHeight((float)i+1, (float)j);
                    vertices.Write(new Vector3(1.0f + i, height, 0.0f + j));
                    vertices.Write(new Vector2(0.0f, 0.0f));
                    height = heightMap.getHeight((float)i, (float)j + 1);
                    vertices.Write(new Vector3(0.0f + i, height, 1.0f + j));
                    vertices.Write(new Vector2(0.0f, 0.0f));
                    height = heightMap.getHeight((float)i + 1, (float)j + 1);
                    vertices.Write(new Vector3(1.0f + i, height, 1.0f + j));
                    vertices.Write(new Vector2(0.0f, 0.0f));
                    height = heightMap.getHeight((float)i + 1, (float)j);
                    vertices.Write(new Vector3(1.0f + i, height, 0.0f + j));
                    vertices.Write(new Vector2(0.0f, 0.0f));

                }
            vertices.Position = 0;
        }