squirrel

03-30-2006, 08:37 PM

Hello all!

Probably a noob question, but I am stumped on this one. I am trying to recursively create squares. However, their children are not comming out as planned.

C# code:

DoRecurse(1, 4, 1.0, 0.5, 3 );

private static void DoRecurse(int myNum, int numSides, double rad, double scale, int stopLevel)

{

double x, y;

double len=(1+scale)*rad;

double theta=360.0/numSides;

// Are we done yet?

int level = (int)Math.Log( (numSides-1)*myNum, numSides );

// if so, we return and pop off call stack.

if( level > stopLevel )

return;

angle=0.0;

myChildNum=1;

// Draw me

Gl.glCallList( poly );

// Draw my children

for( int i=0; i<numSides; i++ )

{

angle=(i)*theta;

Gl.glPushMatrix();

// Takes degrees. (

x = Math.Cos(angle)*len;

y = Math.Sin(angle)*len;

Gl.glTranslated( x, y, 0.0);

Gl.glRotated( angle, 0.0, 0.0, 1.0);

Gl.glScaled(scale, scale, 1.0);

myChildNum = myNum*numSides - (numSides-2) + 1;

DoRecurse( myChildNum, numSides, rad, scale, stopLevel );

Gl.glPopMatrix();

}

} The x and y values are computed correctly, but each child is "moved" (translated or translated then rotated, I am not sure) a little bit to the one side. What is happening that I am not expecting? :confused:

I would post a screen shot, but I don't have any place to put it.

Probably a noob question, but I am stumped on this one. I am trying to recursively create squares. However, their children are not comming out as planned.

C# code:

DoRecurse(1, 4, 1.0, 0.5, 3 );

private static void DoRecurse(int myNum, int numSides, double rad, double scale, int stopLevel)

{

double x, y;

double len=(1+scale)*rad;

double theta=360.0/numSides;

// Are we done yet?

int level = (int)Math.Log( (numSides-1)*myNum, numSides );

// if so, we return and pop off call stack.

if( level > stopLevel )

return;

angle=0.0;

myChildNum=1;

// Draw me

Gl.glCallList( poly );

// Draw my children

for( int i=0; i<numSides; i++ )

{

angle=(i)*theta;

Gl.glPushMatrix();

// Takes degrees. (

x = Math.Cos(angle)*len;

y = Math.Sin(angle)*len;

Gl.glTranslated( x, y, 0.0);

Gl.glRotated( angle, 0.0, 0.0, 1.0);

Gl.glScaled(scale, scale, 1.0);

myChildNum = myNum*numSides - (numSides-2) + 1;

DoRecurse( myChildNum, numSides, rad, scale, stopLevel );

Gl.glPopMatrix();

}

} The x and y values are computed correctly, but each child is "moved" (translated or translated then rotated, I am not sure) a little bit to the one side. What is happening that I am not expecting? :confused:

I would post a screen shot, but I don't have any place to put it.