//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// matrix_utils.cpp: Contains implementations for Mat4 methods.

#include "common/matrix_utils.h"

namespace angle
{

Mat4::Mat4() : Mat4(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f)
{}

Mat4::Mat4(const Matrix<float> generalMatrix)
{
    unsigned int minCols = std::min((unsigned int)4, generalMatrix.columns());
    unsigned int minRows = std::min((unsigned int)4, generalMatrix.rows());
    for (unsigned int i = 0; i < minCols; i++)
    {
        for (unsigned int j = 0; j < minRows; j++)
        {
            mElements[j * minCols + i] = generalMatrix.at(j, i);
        }
    }
}

Mat4::Mat4(const std::vector<float> &elements)
{
    std::copy(elements.begin(), std::min(elements.end(), elements.begin() + std::size(mElements)),
              mElements.data());
}

Mat4::Mat4(const float *elements)
{
    std::copy(elements, elements + std::size(mElements), mElements.data());
}

Mat4::Mat4(float m00,
           float m01,
           float m02,
           float m03,
           float m10,
           float m11,
           float m12,
           float m13,
           float m20,
           float m21,
           float m22,
           float m23,
           float m30,
           float m31,
           float m32,
           float m33)
{
    mElements[0]  = m00;
    mElements[1]  = m01;
    mElements[2]  = m02;
    mElements[3]  = m03;
    mElements[4]  = m10;
    mElements[5]  = m11;
    mElements[6]  = m12;
    mElements[7]  = m13;
    mElements[8]  = m20;
    mElements[9]  = m21;
    mElements[10] = m22;
    mElements[11] = m23;
    mElements[12] = m30;
    mElements[13] = m31;
    mElements[14] = m32;
    mElements[15] = m33;
}

// static
Mat4 Mat4::Rotate(float angle, const Vector3 &axis)
{
    if (axis.length() == 0.0f)
    {
        return Mat4();
    }

    auto axis_normalized = axis.normalized();
    float angle_radians  = angle * (3.14159265358979323f / 180.0f);
    float c              = cos(angle_radians);
    float ci             = 1.f - c;
    float s              = sin(angle_radians);

    float x = axis_normalized.x();
    float y = axis_normalized.y();
    float z = axis_normalized.z();

    float x2 = x * x;
    float y2 = y * y;
    float z2 = z * z;

    float xy = x * y;
    float yz = y * z;
    float zx = z * x;

    float r00 = c + ci * x2;
    float r01 = ci * xy + s * z;
    float r02 = ci * zx - s * y;
    float r03 = 0.f;

    float r10 = ci * xy - s * z;
    float r11 = c + ci * y2;
    float r12 = ci * yz + s * x;
    float r13 = 0.f;

    float r20 = ci * zx + s * y;
    float r21 = ci * yz - s * x;
    float r22 = c + ci * z2;
    float r23 = 0.f;

    float r30 = 0.f;
    float r31 = 0.f;
    float r32 = 0.f;
    float r33 = 1.f;

    return Mat4(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33);
}

// static
Mat4 Mat4::Translate(const Vector3 &t)
{
    float r00 = 1.f;
    float r01 = 0.f;
    float r02 = 0.f;
    float r03 = 0.f;

    float r10 = 0.f;
    float r11 = 1.f;
    float r12 = 0.f;
    float r13 = 0.f;

    float r20 = 0.f;
    float r21 = 0.f;
    float r22 = 1.f;
    float r23 = 0.f;

    float r30 = t.x();
    float r31 = t.y();
    float r32 = t.z();
    float r33 = 1.f;

    return Mat4(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33);
}

// static
Mat4 Mat4::Scale(const Vector3 &s)
{
    float r00 = s.x();
    float r01 = 0.f;
    float r02 = 0.f;
    float r03 = 0.f;

    float r10 = 0.f;
    float r11 = s.y();
    float r12 = 0.f;
    float r13 = 0.f;

    float r20 = 0.f;
    float r21 = 0.f;
    float r22 = s.z();
    float r23 = 0.f;

    float r30 = 0.f;
    float r31 = 0.f;
    float r32 = 0.f;
    float r33 = 1.f;

    return Mat4(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33);
}

// static
Mat4 Mat4::Frustum(float l, float r, float b, float t, float n, float f)
{
    float nn  = 2.f * n;
    float fpn = f + n;
    float fmn = f - n;
    float tpb = t + b;
    float tmb = t - b;
    float rpl = r + l;
    float rml = r - l;

    float r00 = nn / rml;
    float r01 = 0.f;
    float r02 = 0.f;
    float r03 = 0.f;

    float r10 = 0.f;
    float r11 = nn / tmb;
    float r12 = 0.f;
    float r13 = 0.f;

    float r20 = rpl / rml;
    float r21 = tpb / tmb;
    float r22 = -fpn / fmn;
    float r23 = -1.f;

    float r30 = 0.f;
    float r31 = 0.f;
    float r32 = -nn * f / fmn;
    float r33 = 0.f;

    return Mat4(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33);
}

// static
Mat4 Mat4::Perspective(float fov, float aspectRatio, float n, float f)
{
    const float frustumHeight = tanf(static_cast<float>(fov / 360.0f * 3.14159265358979323)) * n;
    const float frustumWidth  = frustumHeight * aspectRatio;
    return Frustum(-frustumWidth, frustumWidth, -frustumHeight, frustumHeight, n, f);
}

// static
Mat4 Mat4::Ortho(float l, float r, float b, float t, float n, float f)
{
    float fpn = f + n;
    float fmn = f - n;
    float tpb = t + b;
    float tmb = t - b;
    float rpl = r + l;
    float rml = r - l;

    float r00 = 2.f / rml;
    float r01 = 0.f;
    float r02 = 0.f;
    float r03 = 0.f;

    float r10 = 0.f;
    float r11 = 2.f / tmb;
    float r12 = 0.f;
    float r13 = 0.f;

    float r20 = 0.f;
    float r21 = 0.f;
    float r22 = -2.f / fmn;
    float r23 = 0.f;

    float r30 = -rpl / rml;
    float r31 = -tpb / tmb;
    float r32 = -fpn / fmn;
    float r33 = 1.f;

    return Mat4(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33);
}

Mat4 Mat4::product(const Mat4 &m)
{
    const float *a = mElements.data();
    const float *b = m.mElements.data();

    return Mat4(a[0] * b[0] + a[4] * b[1] + a[8] * b[2] + a[12] * b[3],
                a[1] * b[0] + a[5] * b[1] + a[9] * b[2] + a[13] * b[3],
                a[2] * b[0] + a[6] * b[1] + a[10] * b[2] + a[14] * b[3],
                a[3] * b[0] + a[7] * b[1] + a[11] * b[2] + a[15] * b[3],

                a[0] * b[4] + a[4] * b[5] + a[8] * b[6] + a[12] * b[7],
                a[1] * b[4] + a[5] * b[5] + a[9] * b[6] + a[13] * b[7],
                a[2] * b[4] + a[6] * b[5] + a[10] * b[6] + a[14] * b[7],
                a[3] * b[4] + a[7] * b[5] + a[11] * b[6] + a[15] * b[7],

                a[0] * b[8] + a[4] * b[9] + a[8] * b[10] + a[12] * b[11],
                a[1] * b[8] + a[5] * b[9] + a[9] * b[10] + a[13] * b[11],
                a[2] * b[8] + a[6] * b[9] + a[10] * b[10] + a[14] * b[11],
                a[3] * b[8] + a[7] * b[9] + a[11] * b[10] + a[15] * b[11],

                a[0] * b[12] + a[4] * b[13] + a[8] * b[14] + a[12] * b[15],
                a[1] * b[12] + a[5] * b[13] + a[9] * b[14] + a[13] * b[15],
                a[2] * b[12] + a[6] * b[13] + a[10] * b[14] + a[14] * b[15],
                a[3] * b[12] + a[7] * b[13] + a[11] * b[14] + a[15] * b[15]);
}

Vector4 Mat4::product(const Vector4 &b)
{
    return Vector4(
        mElements[0] * b.x() + mElements[4] * b.y() + mElements[8] * b.z() + mElements[12] * b.w(),
        mElements[1] * b.x() + mElements[5] * b.y() + mElements[9] * b.z() + mElements[13] * b.w(),
        mElements[2] * b.x() + mElements[6] * b.y() + mElements[10] * b.z() + mElements[14] * b.w(),
        mElements[3] * b.x() + mElements[7] * b.y() + mElements[11] * b.z() +
            mElements[15] * b.w());
}

void Mat4::dump()
{
    printf("[ %f %f %f %f ]\n", mElements[0], mElements[4], mElements[8], mElements[12]);
    printf("[ %f %f %f %f ]\n", mElements[1], mElements[5], mElements[9], mElements[13]);
    printf("[ %f %f %f %f ]\n", mElements[2], mElements[6], mElements[10], mElements[14]);
    printf("[ %f %f %f %f ]\n", mElements[3], mElements[7], mElements[11], mElements[15]);
}

}  // namespace angle
