using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using EVE.EVEObjects.EVEObjectComponents;
using EVE.EVEShaders;

namespace EVE.EVEObjects {
	public class EVEObject {
		protected Vector3 myPosition;
		protected Vector3 myScaling;
		protected Quaternion myRotation;

        protected Vector3 myDiffuseColor;
        protected float mySpecularPower;

        protected Matrix myWorldMatrix;

		protected string myShader;

        public Matrix WorldMatrix { get { return myWorldMatrix; } set { myWorldMatrix = value; } }
		public Vector3 Position { get { return myPosition; } set { myPosition = value; } }
		public Vector3 Scaling { get { return myScaling; } set { myScaling = value; } }
		public Quaternion Rotation { get { return myRotation; } set { myRotation = value; } }

        public Vector3 DiffuseColor { get { return myDiffuseColor; } set { myDiffuseColor = value; } }
        public float SpecularPower { get { return mySpecularPower; } set { mySpecularPower = value; } }


		public EVEObject() {
			myPosition = new Vector3(0, 0, 0);
			myScaling = new Vector3(1, 1, 1);
			myRotation = new Quaternion(0, 0, 0, 1);

            myDiffuseColor = new Vector3(0.5f, 0.5f, 0.5f);
            mySpecularPower = 16.0f;

            myWorldMatrix = Matrix.Identity;
		}

		public void SetShader(string newShader) {
			myShader = newShader;
		}
		
		public void Draw(GraphicsDevice myDevice) {
			if(this is IEVERenderable) {
				EVEShader objShader = EVEShaderManager.GetShader(myShader);

				if(objShader != null) {
					objShader.SetParameters(this);
					objShader.Effect.Begin();

					foreach(EffectPass pass in objShader.Effect.CurrentTechnique.Passes) {
						pass.Begin();
						((IEVERenderable)this).Render(myDevice);
						pass.End();
					}

					objShader.Effect.End();
				}
			}

			if(this is IEVEChildRenderer) ((IEVEChildRenderer)this).RenderChildren(myDevice);
			if(this is IEVEHasMaterial) ((IEVEHasMaterial)this).SetMaterialProperties();
		}
	}
}