#include <eigen3/Eigen/Geometry>
#include <fstream>
#include <QImage>
#include "object.h"
#include "utils.h"

using namespace Eigen;

Object::Object()
    : _shader(0), _geometry(0),
    _transformation(Matrix4f::Identity()),
    _renderType(0)
{
}

void Object::attachMesh(Mesh* mesh)
{
    _geometry = mesh;
}

void Object::attachShader(const Shader* shad)
{
    _shader = shad;
}

void Object::setRenderType(int type)
{
    _renderType = type;
}

void Object::setScale(float s)
{
    cout << "----- SCALING not implemented -----" << endl;
}

void Object::setRotation(const Affine3f& r)
{
    cout << "----- ROTATION not implemented -----" << endl;
}

void Object::setTranslation(const Translation3f &t)
{
    cout << "----- TRANSLATION not implemented-----" << endl;
}

void Object::setId(float id)
{
    _id = id;
}

void Object::draw()
{
    if(!_shader->valid())
        return;

    // active shader
    _shader->activate();

    // send uniforms
    glUniformMatrix4fv(glGetUniformLocation(_shader->id(),"mat_obj"),  1, GL_FALSE, _transformation.matrix().data());
    glUniform1i(glGetUniformLocation(_shader->id(),"renderType"), _renderType);
    glUniform1f(glGetUniformLocation(_shader->id(),"objectId"), _id);

    // draw mesh
    _geometry->draw_geometry(_shader->id());
    GL_TEST_ERR;
}
