Reeseoo 0 Newbie Poster

Hi.. I have an image of what my code is drawing attached, although the code is meant to draw multiple trapeziums and now the extra line lol. I was wondering if anyone could tell me where i was going wrong. Here's the code..

void DrawPolygon(POLYGON *p)
{
	int current_Left, current_Right;
	float ytop,ybottom,xLeft,xRight;
	int top_Vert = 0;
	bool changeLeft = false;

	for (int i = 0;i<p->nv; i++)
	{
		if (p->vert[i].y < p->vert[top_Vert].y)
		{
			top_Vert = i;
			current_Left = i;
			current_Right =i;
		}
	}

	ytop = p->vert[top_Vert].y;

	int next_Left = current_Left - 1;
	int next_Right = current_Right+1;
	if (next_Left < 0)
	{
		next_Left = p->nv - 1;
	}
	if (next_Right >= p->nv)
	{
		next_Right = 0;
	}
	if (p->vert[next_Left].y <p->vert[next_Right].y)
	{
		ybottom = p->vert[next_Left].y;
		changeLeft = true;
	}
	else
	{
		ybottom = p->vert[next_Right].y;
		changeLeft = false;
	}

	float leftSlopeTemp,rightSlopeTemp;
	leftSlopeTemp = ((p->vert[current_Left].x - p->vert[next_Left].x)/(p->vert[current_Left].y - p->vert[next_Left].y));
	rightSlopeTemp = ((p->vert[current_Right].x - p->vert[next_Right].x)/(p->vert[current_Right].y - p->vert[next_Right].y));
	xLeft = p->vert[current_Left].x;
	xRight = p->vert[current_Right].x;
	DrawTrapezium(p->colour,xLeft,xRight,leftSlopeTemp,rightSlopeTemp,ytop,ybottom);

	do 
	{

		ytop = ybottom;

	switch (changeLeft)
	{
	case true:
		{
			ybottom = p->vert[next_Right].y;
			current_Left = next_Left;
			next_Left = current_Left - 1;
			if(next_Left < 0)
			{
				next_Left = p->nv - 1;
			}
			leftSlopeTemp = ((p->vert[current_Left].x - p->vert[next_Left].x)/(p->vert[current_Left].y - p->vert[next_Left].y));
			xLeft = p->vert[current_Left].x; 
			changeLeft = false;
			break;
		}
	case false:
		{
			ybottom = p->vert[next_Left].y;
			current_Right = next_Right;
			next_Right = current_Right + 1;
			if(next_Right > 0)
			{
				next_Right = 0;
			}
			rightSlopeTemp = ((p->vert[current_Right].x - p->vert[next_Right].x)/(p->vert[current_Right].y - p->vert[next_Right].y));
			xRight = p->vert[current_Right].x; 
			changeLeft = true;
			break;
		}
	}

	DrawTrapezium(p->colour,xLeft,xRight,leftSlopeTemp,rightSlopeTemp,ytop,ybottom);

	}
	while (next_Left != next_Right);
}

Many thanks

or there is a pastebin copy here: http://pastebin.com/ZweU1u2L

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.