using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using SkinnedModelLibrary;
using Primitives3D;

namespace FredriksdalAssault2
{
    public class Soldier
    {

        #region Variables

        // Variables for clip number and rotation matrix.
        public byte clipNumber = 2;
        public Matrix rotationMatrix;

        // Variables used to create a world matrix.
        public Vector3 position;
        public Quaternion rotationQuaternion;

        #endregion

        #region Constructors

        /// <summary>
        /// Create a new soldier.
        /// </summary>
        /// <param name="position"></param>
        public Soldier(Vector3 position)
        {
            // Set the position and the rotation matrix.
            this.position = position;
            this.rotationMatrix = Matrix.Identity;

            // Set the rotation quaternion
            rotationQuaternion = Quaternion.CreateFromRotationMatrix(this.rotationMatrix);
   
        }

        #endregion

        #region Methods

        /// <summary>
        /// Set the clip number.
        /// </summary>
        /// <param name="clipNumber"></param>
        public void StartClip(byte clipNumber)
        {
            this.clipNumber = clipNumber;
        }

        /// <summary>
        /// This method is used to update the position and rotation for a player soldier.
        /// </summary>
        /// <param name="cameraPosition"></param>
        /// <param name="turnAmount"></param>
        public void UpdateSoldierPositionRotation(Vector3 cameraPosition, float turnAmount, Vector3 cameraDirection)
        {
            // Update the rotation matrix for the soldier
            this.rotationMatrix *= Matrix.CreateRotationY(turnAmount);

            // Set the model in front of or behind the camera with this variable.
            Vector3 modelOffset = cameraDirection;

            // Set the position for the soldier.
            this.position = cameraPosition + modelOffset;

            // Update the rotation quaternion.
            this.rotationQuaternion = Quaternion.CreateFromRotationMatrix(this.rotationMatrix);
        }

        #endregion
    }
}
