Creating multiple instances of an object

Started by
4 comments, last by mounty0 19 years, 5 months ago
(beginners question) Im working on some code to animate 2 objects with the same properties (using a loop), then later removing one by clicking a button. My code draws the squares, but the code for removing one of them doesnt seem to be work, and I cant figure out why. I was hoping for some opinions on what Ive come up with so far,


static bool displaySquare[2];
GLfloat xpt[2];
GLfloat ypt[2];

void animateSquares(void)
{	
    for (int i = 0; i < 2; i++)
        {
            displaySquare = true;  
			xpt = 0;
			ypt = 15;		

            if (displaySquare = true)
	   {
                 -translate each for xpt and ypt-
                 -drawing each objects for xpt,ypt-
            }
       }		
}


void display(void)
{
	glPushMatrix();
	animateSquares();
	glPopMatrix();
        glutSwapBuffers();
}

void mouse(int button, int state, int x, int y)
{
	switch (button)
	{
	case GLUT_LEFT_BUTTON:
		displaySquare[0] = false; 
        glutPostRedisplay();
        break;
	
	default:
		break;
	}
}

/*
*/




arrays: boolean is whether the scene is drawn or not float xpt/ypt store the center pts of each square in an array animateSquare function -> goes through a loop and sets boolean to true, and sets the x/y coords. Then (if its true) displays the squares to the screen mouse function -> sets boolean[0] to false to remove 1 of the squares from the screen as I said, it draws 2 squares but the code for removing one wont work, can anyone offer some suggestions altering it ?
Advertisement
on each call of animateSquares you set displaySquare to true, regardless of what it was set to before, so you will always draw all teh squares..
Worse. He sets it true twice. :)
so tell me if I got this right, the mouse function wont set bool displaySquare[0] to false, as display will recall the animateSquare function and reset it to true every redisplay?


[Edited by - mounty0 on November 13, 2004 6:49:26 PM]
Quote:Original post by C-Junkie
Worse. He sets it true twice. :)


oh yes, good point I missed the wrong operator in the if statement (I blame the vodka in my brain, hehe [grin])

mounty0;
You set the value to false in the mouse routine, but then it just resets the value to true (twice, as C-Junkie pointed out) in the animateSquares function, thus over riding the change.
ah I can see now, thanks fellas. will try and amend this tomorrow ~_^

This topic is closed to new replies.

Advertisement