#version 330

layout (location = 0) in vec3 in_Vertex;
layout (location = 1) in vec2 in_texCoord;
layout (location = 2) in vec3 in_rots;
layout (location = 3) in vec3 in_trans;

uniform mat4 modelviewProjection;
// could give a time global variable for animating

out vec2 texCoord;

mat4 rotateX(float _angle)
{
    mat4 rot;
    rot[0] = vec4(1, 0, 0, 0);
    rot[1] = vec4(0, cos(_angle), -sin(_angle), 0);
    rot[2] = vec4(0, sin(_angle), cos(_angle), 0);
    rot[3] = vec4(0, 0, 0, 1);

    return rot;
}

mat4 rotateY(float _angle)
{
    mat4 rot;
    rot[0] = vec4(cos(_angle), 0, sin(_angle), 0);
    rot[1] = vec4(0, 1, 0, 0);
    rot[2] = vec4(-sin(_angle), 0, cos(_angle), 0);
    rot[3] = vec4(0, 0, 0, 1);

    return rot;
}

mat4 rotateZ(float _angle)
{
    mat4 rot;
    rot[0] = vec4(cos(_angle), -sin(_angle), 0, 0);
    rot[1] = vec4(sin(_angle), cos(_angle), 0, 0);
    rot[2] = vec4(0, 0, 1, 0);
    rot[3] = vec4(0, 0, 0, 1);

    return rot;
}

void main()
{
    mat4 Rot = rotateZ(in_rots.z) * rotateX(in_rots.x) * rotateY(in_rots.y);
    vec4 vertR = Rot * vec4(vec3(in_Vertex.x, in_Vertex.y, in_Vertex.z), 1.0);

    gl_Position = modelviewProjection * (vertR + vec4(in_trans, 0.0));
    texCoord = in_texCoord;
}