Example #1
0
        public void BuildMesh()
        {
            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
                vertexBuffer.Dispose();
            }

            VertexTexture[] waterVertices = new VertexTexture[4];
            int             i             = 0;

            float x, y, width, height;

            x      = 0;
            y      = 0;
            width  = info.width;
            height = info.height;

            float size = 1;

            waterVertices[i++] = new VertexTexture(new Vector3(x, info.waterLevel, y), new Vector2(0, 0));
            waterVertices[i++] = new VertexTexture(new Vector3(x, info.waterLevel, height), new Vector2(0, size));
            waterVertices[i++] = new VertexTexture(new Vector3(width, info.waterLevel, y), new Vector2(size, 0));
            waterVertices[i++] = new VertexTexture(new Vector3(width, info.waterLevel, height), new Vector2(size, size));

            indices       = new short[] { 0, 3, 1, 0, 2, 3 };
            IndicesLength = indices.Length;

            indexBuffer = new Buffer(Display.device, DataStream.Create(indices, false, false), new BufferDescription(indices.Length * 4, ResourceUsage.Default, BindFlags.IndexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            vertexBuffer = Buffer.Create <VertexTexture>(Display.device, waterVertices, new BufferDescription(4 * VertexTexture.SizeInBytes, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
        }
        public static VertexTexture Parse(string line)
        {
            string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            VertexTexture vertexTexture = new VertexTexture();

            vertexTexture.U = parts[0].ParseInvariantFloat();
            vertexTexture.V = (parts.Length > 1) ? parts[1].ParseInvariantFloat() : 0;
            vertexTexture.W = (parts.Length > 2) ? parts[2].ParseInvariantFloat() : 0;

            return(vertexTexture);
        }