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

namespace Obligatorisk
{
    class House : ModelComponent
    {
        #region  3D-models (Frank & Kasper) 3. Maj
        public House(Model aModel, Device aDevice, Vector3 aPosition)
            : base(aModel, aDevice, aPosition)
        {
            CreateMesh();
        }
        
        public House(Model aModel, Device aDevice, Vector3 aPosition, BoundingBox boundingBox)
            : base(aModel, aDevice, aPosition, boundingBox)
        {
            CreateMesh();
        }
        #endregion


        public void CreateMesh()
        {

            ExtendedMaterial[] materials = null;
            String path = @"..\..\";
            this.Mesh = Mesh.FromFile(path + @"\3D-Models\house1.x", MeshFlags.SystemMemory, this.TheDevice, out materials);

            if (this.MeshTextures == null)
            {
                // Egenskaber for materialer og texture udtrækkes 
                this.MeshTextures = new Texture[materials.Length];
                this.MeshMaterials = new Material[materials.Length];
                for (int i = 0; i < materials.Length; i++)
                {
                    this.MeshMaterials[i] = materials[i].Material3D;
                    // Set the ambient color for the material (D3DX does not do this)
                    this.MeshMaterials[i].Ambient = this.MeshMaterials[i].Diffuse;
                    this.MeshTextures[i] = TextureLoader.FromFile(this.TheDevice, path + @"\3D-Models\cemrof.tga");
                 
                }
            }

        }



        #region  3D-models (Frank & Kasper) 3. Maj
        // DATO: 3. Maj 2007 ::: Ændret transform.World: flyttet Position uden for beregning, således at positionen bliver bibeholdt.
        // DATO: 2. Maj 2007 ::: lavet render metoden til en override af ModelComponents Render metode.
        public override void Render()
        {
            // tegn boundingbox
            if (true)
            {
                this.DrawBoundingBox();
            }

            // Kamera
            this.TheDevice.RenderState.Lighting = true;
            this.TheDevice.Transform.World = ((Matrix.RotationYawPitchRoll(Yaw, Pitch, Roll) * Matrix.Scaling(4.0f, 4.0f, 4.0f)) * Matrix.Translation(Position));
            for (int i = 0; i < this.MeshMaterials.Length; i++)
            {
                this.TheDevice.Material = this.MeshMaterials[i];
                this.TheDevice.SetTexture(0, this.MeshTextures[i]);
                this.Mesh.DrawSubset(i);
            }
        }
        #endregion



    }
}
