#ifndef _TPFOBJ_C
#define _TPFOBJ_C

#include <stdlib.h>
#include "obj.h"
#include "ang.h"
#include "vec.h"
#include "tex.h"

tpfObj *TpfObj_New()
{
	tpfObj *o = (tpfObj *) malloc(sizeof(tpfObj));
	o->pos.x = o->pos.y = o->pos.z = 0;
	o->rot = 0;
	o->numsides = 0;
	o->sides = 0;
	o->flags = 0;
	return o;
}

void TpfObj_Delete(tpfObj *o)
{
	if (o->sides != 0)
		free(o->sides);
	free(o);
}

void TpfObj_SetPos(tpfObj *o,tpfVec v)
{
	o->pos = v;
}

tpfVec *TpfObj_GetPos(tpfObj *o)
{
	return &(o->pos);
}

void TpfObj_SetAng(tpfObj *o,tpfAng a)
{
	o->rot = a;
}

tpfAng TpfObj_GetAng(tpfObj *o)
{
	return o->rot;
}

void TpfObj_SetSides(tpfObj *o,int s)
{
	o->numsides = s;
	if (o->sides != 0)
		free(o->sides);
	if (s != 0)
	{
		o->sides = (tpfTex **) malloc(4*s);
		while (s > 0)
			o->sides[--s] = 0;
	}
	else
		o->sides = 0;
}

int TpfObj_GetSides(tpfObj *o)
{
	return o->numsides;
}

void TpfObj_SetSide(tpfObj *o,int s,tpfTex *t)
{
	/* Assume it's OK */
	o->sides[s] = t;
}

tpfTex *TpfObj_GetSide(tpfObj *o,int s)
{
	return o->sides[s];
}

void TpfObj_SetFlags(tpfObj *o,int f)
{
	o->flags = f;
}

int TpfObj_GetFlags(tpfObj *o)
{
	return o->flags;
}

#endif
