#include "include.h"


Model::Model() {
	this->model = NULL;
}

Model::~Model() {
	if (this->model) {
		glmDelete(this->model);
	}
}

Model * Model::readOBJ(char * filename) {
	Model * m = new Model();
	m->model = glmReadOBJ(filename);
	glmFacetNormals(m->model);
	glmVertexNormals(m->model, 90.0f);
	m->setMode(GLM_MATERIAL | GLM_SMOOTH);
	return m;
}

void Model::setMode(GLuint mode) {
	this->displayList = glmList(this->model, mode);
}

void Model::draw() {
	glCallList(this->displayList);
}

void Model::trasladarOrigen(double x, double y, double z) {
	for (GLuint i = 0; i <= this->model->numvertices*3; i+= 3) {
		this->model->vertices[i] += x;
		this->model->vertices[i+1] += y;
		this->model->vertices[i+2] += z;
	}
}

void Model::unitize() {
	glmUnitize(this->model);
}
