Ejemplo n.º 1
0
        private void SetBuffers(GraphicsDevice device, VertexMultitextured[] vertices, int[] indices)
        {
            vBuffer = new VertexBuffer(device, vertices.Length * VertexMultitextured.SizeInBytes, BufferUsage.WriteOnly);
            vBuffer.SetData(vertices);

            iBuffer = new IndexBuffer(device, typeof(int), indices.Length, BufferUsage.WriteOnly);
            iBuffer.SetData(indices);
        }
Ejemplo n.º 2
0
        private VertexMultitextured[] SetVertices()
        {
            VertexMultitextured[] Vertices = new VertexMultitextured[width * length];

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < length; y++)
                {
                    float x0, y0, z0, w0, p0;
                    Vertices[x + y * width].Position = new Vector3(x, Altitudes[x, y], -y);
                    Vertices[x + y * width].TextureCoordinate.X = (float)x / maxAlt;
                    Vertices[x + y * width].TextureCoordinate.Y = (float)y / maxAlt;
                    p0 = Altitudes[x, y] / maxAlt;
                    x0 = MathHelper.Clamp(1.0f - Math.Abs(p0 - 0.0f) * 6, 0, 1);
                    y0 = MathHelper.Clamp(1.0f - Math.Abs(p0 - 0.33f) * 5, 0, 1);
                    z0 = MathHelper.Clamp(1.0f - Math.Abs(p0 - 0.67f) * 5, 0, 1);
                    w0 = MathHelper.Clamp(1.0f - Math.Abs(p0 - 1.0f) * 5, 0, 1);
                    float isum = 1 / (x0 + y0 + z0 + w0);
                    Vertices[x + y * width].TexWeights.X = x0 * isum;
                    Vertices[x + y * width].TexWeights.Y = y0 * isum;
                    Vertices[x + y * width].TexWeights.Z = z0 * isum;
                    Vertices[x + y * width].TexWeights.W = w0 * isum;
                }
            }

            return Vertices;
        }
Ejemplo n.º 3
0
        private VertexMultitextured[] CalculateNormals(VertexMultitextured[] vertices, int[] indices)
        {
            for (int i = 0; i < vertices.Length; i++)
                vertices[i].Normal = new Vector3(0, 0, 0);

            for (int i = 0; i < indices.Length / 3; i++)
            {
                int index1 = indices[i * 3];
                int index2 = indices[i * 3 + 1];
                int index3 = indices[i * 3 + 2];

                Vector3 side1 = vertices[index1].Position - vertices[index3].Position;
                Vector3 side2 = vertices[index1].Position - vertices[index2].Position;
                Vector3 normal = Vector3.Cross(side1, side2);

                vertices[index1].Normal += normal;
                vertices[index2].Normal += normal;
                vertices[index3].Normal += normal;
            }

            for (int i = 0; i < vertices.Length; i++)
                vertices[i].Normal.Normalize();

            return vertices;
        }