socrates25 0 Newbie Poster

For my assignment i need to turn a Hilbert Curve with recursion into a Moore Curve using recursion. We are using GLUT to draw the lines to the screen. I can see the pattern i need to use with the recursion but im not sure if i need to change any of the functions that plot the points.
Here is part of the original code:

void drawLine(float dx, float dy)
{
	float x1 = 2*x - 1;
	float y1 = 2*y - 1;
	float x2 = 2*(x+dx) - 1;
	float y2 = 2*(y+dy) - 1;
	glVertex2f(x1,y1);
	glVertex2f(x2,y2);

	x += dx;
	y += dy;
}

void display()
{	
	dist = 1;
	dist /= (1 << level);
	x = dist/2;
	y = dist/2;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glBegin(GL_LINES);
	glColor3f(0.0f,1.0f,0.0f); // rgb
	cout << "Working on level " << level << " ..." << endl;
	A(level); // start recursion
	cout << "Level " << level << " done!" << endl;
	glEnd();

	glutSwapBuffers();
}

void A (int l) {
	if (l > 0) {
		C(l-1); 
		drawLine(0,dist);
		A(l-1); 
		drawLine(dist,0);
		A(l-1); 
		drawLine(0,-dist);
		B(l-1);
	}
}

void B (int l) {
	if (l > 0) {
		D(l-1);
		drawLine(dist,0);
		B(l-1); 
		drawLine(0,dist);
		B(l-1); 
		drawLine(-dist,0);
		A(l-1);
	}
}

void C (int l) {
	if (l > 0) {
		A(l-1);
		drawLine(-dist,0);
		C(l-1); 
		drawLine(0,-dist);
		C(l-1); 
		drawLine(dist,0);
		D(l-1);
	}
}

void D (int l) {
	if (l > 0) {
		B(l-1); 
		drawLine(0,-dist);
		D(l-1); 
		drawLine(-dist,0);
		D(l-1); 
		drawLine(0,dist);
		C(l-1);
	}
}

And here is what i have changed:

void drawLine(float dx, float dy)
{
	float x1 = 2*x - 1;
	float y1 = 2*y - 1;
	float x2 = 2*(x+dx) - 1;
	float y2 = 2*(y+dy) - 1;
	glVertex2f(x1,y1);
	glVertex2f(x2,y2);

	x += dx;
	y += dy;
}

void display()
{	
	dist = 1;
	dist /= (1 << level);
	x = dist/2;
	y = dist/2;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glBegin(GL_LINES);
	glColor3f(0.0f,1.0f,0.0f); // rgb
	cout << "Working on level " << level << " ..." << endl;
	A(level); // start recursion
	cout << "Level " << level << " done!" << endl;
	glEnd();

	glutSwapBuffers();
}
void A (int l) {
	if (l > 0) {
		C(l-1); 
		drawLine(0,dist);
		A(l-1); 
		drawLine(dist,0);
		A(l-1); 
		drawLine(0,-dist);
		B(l-1);
	}
}

void B (int l) {
	if (l > 0) {
		D(l-1);
		drawLine(-dist,0);
		B(l-1); 
		drawLine(0,dist);
		B(l-1); 
		drawLine(dist,0);
		A(l-1);
	}
}

void C (int l) {
	if (l > 0) {
		A(l-1);
		drawLine(dist,0);
		C(l-1); 
		drawLine(0,-dist);
		C(l-1); 
		drawLine(-dist,0);
		D(l-1);
	}
}

void D (int l) {
	if (l > 0) {
		B(l-1); 
		drawLine(0,-dist);
		D(l-1); 
		drawLine(-dist,0);
		D(l-1); 
		drawLine(0,dist);
		C(l-1);
	}
}

Any help would be great.
Here is a link to a picture of the Moore Curve (ignore the color changes that is not applied to this assignment) http://en.wikipedia.org/wiki/Moore_curve

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.