Ejemplo n.º 1
0
        public Terrain CreateTerrain()
        {
            var terrain = new Terrain()
            {
                AmbientColor = new Vector3(0.1f, 0.1f, 0.1f),
                DiffuseColor = Color.White.ToVector3(),
                SpecularColor = Color.White.ToVector3(),
                Shininess = 40,
                Texture = PrimaryTexture,
                SecondaryTexture = SecondaryTexture,
                MarkTexture = MarkTexture
            };

            GenerateVertices(terrain, GeneratePositions());

            for(int i = 0; i < SquareCount; ++i)
                for (int j = 0; j < SquareCount; ++j)
                {
                    terrain.AddIndex((i + 1) * (SquareCount + 1) + j);
                    terrain.AddIndex(i * (SquareCount + 1) + j + 1);
                    terrain.AddIndex(i*(SquareCount + 1) + j);

                    terrain.AddIndex((i + 1)*(SquareCount + 1) + j);
                    terrain.AddIndex((i + 1)*(SquareCount + 1) + j + 1);
                    terrain.AddIndex(i*(SquareCount + 1) + j + 1);
                }

            terrain.InitializePrimitive(GraphicsDevice);
            return terrain;
        }
Ejemplo n.º 2
0
        private void GenerateVertices(Terrain terrain, Vector3[,] positions)
        {
            for(int i = 0; i < SquareCount+1; ++i)
                for (int j = 0; j < SquareCount + 1; ++j)
                {
                    var textureCoordinates = new Vector2(i / (float)SquareCount, (float)j / (float)SquareCount);

                    var normal = (i == 0 || j == 0 || i == SquareCount || j == SquareCount)
                        ? Vector3.Up
                        : CalculateNormal(i, j, positions);

                    terrain.AddVertex(positions[i, j], normal, textureCoordinates);
                }
        }