Array of shapes

I’m trying to create an array of similar shapes that rotate around the cursor, but all of different speeds, distances and colours.

I’ve experimented by creating two of this shape and giving them two different distances from the cursor. The program builds fine, but the window doesn’t load properly. The empty window just sits there and doesn’t respond.

My code for this bit is:

for(int i=2; i<=4; i+2){
glTranslatef(i,i,0); }
float PI = 3.14159265358979323846264338327950288;
for(int i=0; i<=1; i++){
for(int i=0; i <= 360; i++){
glVertex3f(sin(i*PI/180)1,cos(iPI/180)*1, 1);}}

What am i doing wrong? Can anyone help? Thanks.

Ok, i’ve solved this problem by moving some things round. I got this:

for(int i=1; i<=2; i++){
glTranslatef(mouse_x,mouse_y,0); //Positions circle at cursor.
glColor3f(0.4i,0.4i,0.4i); //Gives colour of circle.
glRotatef(spin, 0.0, 0.0, 0.5
i); //Gives spin of circle.
glTranslatef(2i,2i,0); //Positions the original location of circle in relation to cursor before spin is applied.
for(int i=0; i <= 360; i++){
glVertex3f(sin(i*PI/180)1, cos(iPI/180)*1, 1);}}

But now it only seems to create the first circle that would be in the loop. I’d have thought this would be okay. Can anyone Help?

try adding glPushMatrix(GL_MODELVIEW); right after the { and glPopMatrix(GL_MODELVIEW); right before the }

I get “‘glPushMatrix’ : function does not take 1 arguments” when i do that, but i remember this vaguely. I’ll look it up and see what needs to change.

Yeah sorry, no need for an argument, pop/push is done implicitely on current matrix.

You have nested loops with the same control variable name. And if you want to have an arbitary number of objects rotating, try using a precalculated look up table instead of 360 sin(iPI/180) & cos(iPI/180) per object per frame.

@Pziko : precalc tables are not so good nowadays, as CPU computing speeds have increased a lot more more than memory bandwidth. It may have uses but a careful benchmark should validate it.

First make it work, then optimize performance.

That’s why you stick your precalc in an attribute array (prefferably a VBO) and forget about it.

If you use individual vertex dispatch with some trig between, it’s not good.

I agree with the philosophy of get it working then cache though.

Okay, so can anyone tell me what i can do to make this test work?

You already had a number of advices.

  • Did you put the push/pop at the right places ?
  • Used a different variable to avoid aliasing “i” ?
  • How is your code now ?
  • Does it still not work ?

Your loops aren’t nested.

And when you nest them you’ll have problems since you use ‘i’ in both as Zb said.

P.S. they weren’t nested in first version and so Zb has already given you the answer, it is definitely the ‘i’ namespace collision.