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.
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.5i); //Gives spin of circle.
glTranslatef(2i,2i,0); //Positions the original location of circle in relation to cursor before spin is applied.
glBegin(GL_TRIANGLE_FAN);
for(int i=0; i <= 360; i++){
glVertex3f(sin(i*PI/180)1, cos(iPI/180)*1, 1);}}
glEnd()
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?
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.