
#include "painters_poly.h"

#include <GL/gl.h>

#include "vec4.h"
#include "vertex.h"
#include "halfedge.h"


PaintersPoly::PaintersPoly() {

	cerr << "Error: PaintersPoly default constructor called" << endl;
	exit(-1);
}

PaintersPoly::PaintersPoly(const JLmatrix &VT, HalfEdge *he) : PaintersObj() {

	Vec4 Center;

	HalfEdge *loop = he;
	int count = 0;
	do {
		Vec4FastAdd(Center, Center, loop->_v->Point());
		loop->_flag = 1;
		count++;
		loop = loop->_link->_other_half;
	} while (loop != he);
	Center /= count;

	Center.SetWto1();
	Init(Center, VT);

	_he = he;
}

PaintersPoly::~PaintersPoly() {
}

PaintersPoly& PaintersPoly::CopyFrom(const PaintersPoly &) {

	cerr << "Error: PaintersPoly::CopyFrom() called" << endl;
	exit(-1);

	return *this;
}

void PaintersPoly::Draw() {

	glColor4f(0.25, 0.25, 1, 0.5);

	glBegin(GL_POLYGON);

	HalfEdge *loop = _he;
	do {
		glVertex3f(loop->_v->Point().x(),
				   loop->_v->Point().y(),
				   loop->_v->Point().z());
		loop = loop->_link->_other_half;
	} while (loop != _he);

	glEnd();
}
