Sign in to follow this  
mounty0

Creating multiple instances of an object

Recommended Posts

(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[i] = true;  
			xpt[i] = 0;
			ypt[i] = 15;		

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


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 ?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this