using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using OpenTK;

namespace ObjectManager
{
    public class Mesh
    {
        public List<Vertex> Vertices;
        public List<Vertex> TransformedVertices;
        public List<Face> Faces;
        public Material Material;

        //public Vector3d StaticRotation;
        public Vector3d StaticTranslation;

        #region Constructors

        //public Mesh(Vertex[] vertices, Face[] faces, Material material, double tX, double tY, double tZ, double rX, double rY, double rZ)
        //{
        //    this.Faces = new List<Face>(faces);
        //    this.Vertices = new List<Vertex>(vertices);
        //    this.Material = new Material(material);
        //    this.StaticTranslation = new Vector3d(tX, tY, tZ);
        //    //this.StaticRotation = new Vector3d(rX, rY, rZ);
        //    this.TransformedVertices = new List<Vertex>();
        //    this.RenewTransformedVertices();
        //}

        public Mesh(Vertex[] vertices, Face[] faces, Material material, double tX, double tY, double tZ)
        {
            this.Faces = new List<Face>(faces);
            this.Vertices = new List<Vertex>(vertices);
            this.Material = new Material(material);
            this.StaticTranslation = new Vector3d(tX, tY, tZ);
            //this.StaticRotation = Vector3d.Zero;
            this.TransformedVertices = new List<Vertex>();
            this.RenewTransformedVertices();
        }

        public Mesh(Vertex[] vertices, Face[] faces, Material material)
        {
            this.Faces = new List<Face>(faces);
            this.Vertices = new List<Vertex>(vertices);
            this.Material = new Material(material);
            this.StaticTranslation = Vector3d.Zero;
            //this.StaticRotation = Vector3d.Zero;
            this.TransformedVertices = new List<Vertex>();
            this.RenewTransformedVertices();
        }

        public Mesh(Vertex[] vertices, Face[] faces)
        {
            this.Faces = new List<Face>(faces);
            this.Vertices = new List<Vertex>(vertices);
            this.Material = new Material();
            this.StaticTranslation = Vector3d.Zero;
            //this.StaticRotation = Vector3d.Zero;
            this.TransformedVertices = new List<Vertex>();
            this.RenewTransformedVertices();
        }

        public Mesh()
        {
            this.Faces = new List<Face>();
            this.Vertices = new List<Vertex>();
            this.Material = new Material();
            this.StaticTranslation = Vector3d.Zero;
            //this.StaticRotation = Vector3d.Zero;
            this.TransformedVertices = new List<Vertex>();
            this.RenewTransformedVertices();
        }

        public Mesh(Mesh mesh)
        {
            this.Faces = new List<Face>(mesh.Faces);
            this.Material = new Material(mesh.Material);
            this.Vertices = new List<Vertex>(mesh.Vertices);
            this.StaticTranslation = mesh.StaticTranslation;
            //this.StaticRotation = mesh.StaticRotation;
            this.TransformedVertices = new List<Vertex>();
            foreach (Vertex i in mesh.Vertices)
            {
                this.TransformedVertices.Add(new Vertex(i));
            }
        }

        #endregion

        #region Methods

        public void RenewTransformedVertices()
        {
            TransformedVertices.Clear();
            foreach (Vertex i in Vertices)
            {
                TransformedVertices.Add(new Vertex(i));
            }
            //ObjectManager.Rotate(ref TransformedVertices, ObjectManager.Axis.X, StaticRotation.X);
            //ObjectManager.Rotate(ref TransformedVertices, ObjectManager.Axis.Y, StaticRotation.Y);
            //ObjectManager.Rotate(ref TransformedVertices, ObjectManager.Axis.Z, StaticRotation.Z);
            ObjectManager.Translate(ref TransformedVertices, StaticTranslation);
        }

        #endregion
    }
}
