Example #1
0
void Curve::fillPolygonG(TripleField cell, int comp, double shift)
{
	std::sort(cell.begin(), cell.end(), tripleLessThan);

	Triple left = cell.front();
	cell.erase(cell.begin());
	Triple right = cell.back();
	cell.pop_back();

	TripleField ccwPoints, cwPoints;
	ccwPoints.push_back(left);
	cwPoints.push_back(left);
	unsigned int points = cell.size();
	for (unsigned int i = 0; i < points; i++){
		Triple p = cell[i];
		if (ccw(left, right, p))
			ccwPoints.push_back(p);
		else
			cwPoints.push_back(p);
	}
	cwPoints.push_back(right);
	ccwPoints.push_back(right);

	std::sort(cwPoints.begin(), cwPoints.end(), tripleLessThan);
	std::sort(ccwPoints.begin(), ccwPoints.end(), tripleLessThan);

	bool projection = (comp >= 0);
	if (projection){
		glBegin(GL_POLYGON);
		points = cwPoints.size();
		for (unsigned int i = 0; i < points; i++)
			drawVertex(cwPoints[i], shift, comp);
		glEnd();

		glBegin(GL_POLYGON);
		points = ccwPoints.size();
		for (unsigned int i = 0; i < points; i++)
			drawVertex(ccwPoints[i], shift, comp);
		glEnd();
	} else {
		glBegin(GL_POLYGON);
		points = cwPoints.size();
		for (unsigned int i = 0; i < points; i++){
			Triple p = cwPoints[i];
			glVertex3d(p.x, p.y, p.z);
		}
		glEnd();

		glBegin(GL_POLYGON);
		points = ccwPoints.size();
		for (unsigned int i = 0; i < points; i++){
			Triple p = ccwPoints[i];
			glVertex3d(p.x, p.y, p.z);
		}
		glEnd();
	}
}