Recursive Drawing

MstWntd

Newcomer
Hello,

I have a tree image which I am billboarding.

I want to be able to draw this tree around 20 times randomly along my plane

Code:
		glBegin( GL_POLYGON );
		{
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-1.f, -1.0f, 0.0f);

			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(1.0f, -1.0f, 0.0f);

			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(1.0f, 1.0f, 0.0f);

			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-1.0f, 1.0f, 0.0f);
		}
		glEnd();

The above will draw one instance of my tree, I tried to loop it and have that run 20 time...

Code:
	for (float x=1.0f;x<100;x+=5.0f){
			glBegin( GL_POLYGON );
			{
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(-x, -xf, 0.0f);

				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(x, -xf, 0.0f);

				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(x, xf, 0.0f);

				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(-x, xf, 0.0f);
			}
			glEnd();
	}

But the above code gives me a totally wacked out tree..as in one really wide tree...
 
But the above code gives me a totally wacked out tree..as in one really wide tree...

From the looks of it, you are using the loop variable to scale the X coordinates of the tree's vertices. This gives you 20 trees all appearing in the same location, with each tree getting wider and wider, finally leaving you with a single visible, ultra-wide tree.

For a more meaningful effect, you might want instead to *add* the loop variable to the X coordinate:
Code:
	for (float x=1.0f;x<100;x+=5.0f){
			glBegin( GL_POLYGON );
			{
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f([b][color=red]-1.0f + x[/color][/b], -xf, 0.0f);

				glTexCoord2f(1.0f, 0.0f);
				glVertex3f([b][color=red]1.0f + x[/color][/b], -xf, 0.0f);

				glTexCoord2f(1.0f, 1.0f);
				glVertex3f([b][color=red]1.0f + x[/color][/b], xf, 0.0f);

				glTexCoord2f(0.0f, 1.0f);
				glVertex3f([b][color=red]-1.0f + x[/color][/b], xf, 0.0f);
			}
			glEnd();
	}
 
Thank you!!

Actually what I wanted was the make the SAME looking tree over and over in different places with the same Y value..

When you highlighted the fact that I am scaling the trees and moving them around I realised my main mistake.

I need to translate them in the for loop...so it be the same tree..in different places!

Sorry if I wasnt being clear and thanks for eye opener!
 
Back
Top