using GameApp.Entities;
using OpenGL;
using System;

namespace GameApp.Helper
{
    public class Maths
    {
        static Matrix4x4 _identityMatrix4x4;
        public static Matrix4x4 IdentityMatrix4x4
        {
            get { return _identityMatrix4x4; }
        }

        static Maths()
        {
            _identityMatrix4x4 = new Matrix4x4();
            _identityMatrix4x4.SetIdentity();
        }

        public static Matrix4x4 createTransformationMatrix(Vertex3f translation, float rx, float ry, float rz, float scale)
        {
            ModelMatrix matrix = new ModelMatrix(IdentityMatrix4x4);

            matrix.Translate(translation);
            matrix.RotateX(rx);
            matrix.RotateY(ry);
            matrix.RotateZ(rz);
            matrix.Scale(scale);

            return matrix;
        }

        public static Matrix4x4 createViewMatrix(Camera camera)
        {
            ModelMatrix matrix = new ModelMatrix(IdentityMatrix4x4);

            matrix.Rotate(new Quaternion(new Vertex3f(1, 0, 0), camera.Pitch));
            matrix.Rotate(new Quaternion(new Vertex3f(0, 1, 0), camera.Yaw));

            Vertex3f cameraPos = camera.Position;
            Vertex3f negativeCameraPos = new Vertex3f(-cameraPos.x, -cameraPos.y, -cameraPos.z);
            matrix.Translate(negativeCameraPos);

            return matrix;
        }

        public static float DegreeToRadian(float angle)
        {
            return (float)(Math.PI / 180) * angle;
        }

        public static float RadianToDegree(float angle)
        {
            return (float)(angle * (180.0 / Math.PI));
        }
    }
}
