using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
using System.Drawing;

namespace Obligatorisk
{
    class Ground
    {
        Device theDevice;
        Matrix theWorld;
        private Texture ground = null;
        private Material material = new Material();
        CustomVertex.PositionTextured[] vertices;

        public Ground(Device aDevice)
        {
            theDevice = aDevice;
            theWorld = Matrix.Identity;
            vertices = new CustomVertex.PositionTextured[6];
            vertices[0].Position = new Vector3(400f, 0f, 400f);
            vertices[0].Tu = 1;
            vertices[0].Tv = 0;
            vertices[1].Position = new Vector3(-400f, 0f, -400f);
            vertices[1].Tu = 0;
            vertices[1].Tv = 1;
            vertices[2].Position = new Vector3(400f, 0f, -400f);
            vertices[2].Tu = 1;
            vertices[2].Tv = 1;
            vertices[3].Position = new Vector3(-400f, 0f, -400f);
            vertices[3].Tu = 0;
            vertices[3].Tv = 1;
            vertices[4].Position = new Vector3(400f, 0f, 400f);
            vertices[4].Tu = 1;
            vertices[4].Tv = 0;
            vertices[5].Position = new Vector3(-400f, 0f, 400f);
            vertices[5].Tu = 0;
            vertices[5].Tv = 0;
            LoadTexture();
        }

        private void LoadTexture()
        {
            String path = @"..\..\";
            material.Diffuse = Color.White;
            material.Specular = Color.LightGray;
            material.SpecularSharpness = 15.0F;
            theDevice.Material = material;
            ground = TextureLoader.FromFile(theDevice, path + @"Tracks\track01.jpg");
        }

        public void Render()
        {
            theDevice.RenderState.Lighting = false;
            //device.Transform.View = this.View;
            theDevice.Transform.World = theWorld;
            theDevice.VertexFormat = CustomVertex.PositionTextured.Format;
            theDevice.SetTexture(0, ground);
            theDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 2, vertices);
        }
    }
}
