#include "glm/geometric.hpp"
#include <mesh.hpp>

gb::Mesh::Mesh(
        const uv4& va,
        const uv4& vb,
        const uv4& vc,
        const uv2& vta,
        const uv2& vtb,
        const uv2& vtc,
        const uv4& vna,
        const uv4& vnb,
        const uv4& vnc
        )
    : m_va(va),
      m_vb(vb),
      m_vc(vc),
      m_ta(vta),
      m_tb(vtb),
      m_tc(vtc),
      m_na(vna),
      m_nb(vnb),
      m_nc(vnc)
{}

gb::mesh_compute gb::Mesh::apply(const glm::mat4& mat) const
{
    auto a =  gb::mesh_compute {
        .m_va = mat * *m_va,
        .m_vb = mat * *m_vb,
        .m_vc = mat * *m_vc,
        .m_ta = *m_ta,
        .m_tb = *m_tb,
        .m_tc = *m_tc,
        .m_na = mat * *m_na,
        .m_nb = mat * *m_nb,
        .m_nc = mat * *m_nc,
    };
    a.m_va /= a.m_va.w;
    a.m_vb /= a.m_vb.w;
    a.m_vc /= a.m_vc.w;
    a.m_na /= a.m_na.w;
    a.m_nb /= a.m_nb.w;
    a.m_nc /= a.m_nc.w;
    return a;
}

/*
::std::ostream& ::std::ostream::operator<<(::std::ostream& stream, const gb::Mesh& mesh)
{
    stream << "Dimension: " << mesh.dim.x << ' ' << mesh.dim.y << ' '                                    << '\n'
           << "m_a: "       << mesh.m_a.x << ' ' << mesh.m_a.y << ' ' << mesh.m_a.z << ' ' << mesh.m_a.w << '\n'
           << "m_b: "       << mesh.m_b.x << ' ' << mesh.m_b.y << ' ' << mesh.m_b.z << ' ' << mesh.m_b.w << '\n'
           << "m_c: "       << mesh.m_c.x << ' ' << mesh.m_c.y << ' ' << mesh.m_c.z << ' ' << mesh.m_c.w ;
    return stream;
}
*/
