#include "movable.h"

void movable_locate(movable *m) {
	glTranslatef(m->x, m->y, m->z);
	glRotatef(m->xa, 1.0, 0.0, 0.0);
	glRotatef(m->ya, 0.0, 1.0, 0.0);
	glRotatef(m->za, 0.0, 0.0, 1.0);
}

void movable_animate(movable *m, int elapsed) {
	m->x  += (m->xv  / 1000.) * elapsed;
	m->y  += (m->yv  / 1000.) * elapsed;
	m->z  += (m->zv  / 1000.) * elapsed;
	m->xa += (m->xav / 1000.) * elapsed;
	m->ya += (m->yav / 1000.) * elapsed;
	m->za += (m->zav / 1000.) * elapsed;
}

void movable_init(movable *m) {
	m->locate  = &movable_locate;
	m->animate = &movable_animate;
	m->x   = m->y   = m->z   = 0;
	m->xv  = m->yv  = m->zv  = 0;
	m->xa  = m->ya  = m->za  = 0;
	m->xav = m->yav = m->zav = 0;

	m->next = 0;
	m->duration = 0;
}

void movable_moveto(movable* m, movable* n) {
	m->x   = n->x;   m->y   = n->y;   m->z   = n->z;
	m->xv  = n->xv;  m->yv  = n->yv;  m->zv  = n->zv;
	m->xa  = n->xa;  m->ya  = n->ya;  m->za  = n->za;
	m->xav = n->xav; m->yav = n->yav; m->zav = n->zav;
}
