I have a vector saving 5 cube coordinates in oxy plan.
Task: 1st cube roll 90 degrees, then disappear then 2nd cube roll 90 dg … until the last cube in the vector.
Problem: whenever the program runs, all the cube will appear and roll the same time.
Q: How can I solve this problem?
- I checked the value in for loop (temp), and value of (count) as below:
angle 1 count 1
temp0
temp1
temp2
temp3
temp4
temp5
temp6
temp7
angle 2 count 2
temp0
temp1
temp2
temp3
temp4
temp5
temp6
temp7
=> I do not know why the for loop does not wait for for the “presskey” action to increase the angle value before move to the next temp value.
int Count(0);
void Display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
SetLight();
glPushMatrix();
ConclusiveAxis();
DrawGrid();
for (int temp = 0; temp < cube.coordinates.size(); temp++) {
cout<< "temp" << temp << endl;
if ((cube.coordinates[temp] == true)) {
sDirection = true;
if (Count <= 90) {
glPushMatrix();
glTranslatef(cube.coordinates[temp].x - 0.5, cube.coordinates[temp].y - 0.5, 0.0);
glRotatef(angle, 0, 1, 0);
glTranslatef(-0.5, 0.5, 0.5);
glColor3f(0.5, 1.5, 1.0);
glutSolidCube(1);
glPopMatrix();
}
else if (Count > 90) {
angle = 0;
Count = 0;
}
else {
sDirection = false;
}
}
else {
}
}
glPopMatrix();
glutSwapBuffers();
}
void SpecialKey(unsigned char key, int x, int y) {
switch (key) {
case 'r':
//condition for next check
if (sDirection == true)
{
angle++;
glutPostRedisplay();
Count++;
cout << "angle " << angle << " count " << Count << endl;
}
else
{
glutPostRedisplay(NULL);
}
break;
}
}
void OpenGLCallBackAnimation(void) {
GLSettings0.PickObject = PickObject0;
OpenGLInitialize(0, GLSettings0, 300, 150, 1000, 650, "window");
glutDisplayFunc(Display);
glutMouseFunc(MouseButton);
glutMotionFunc(OnMouseMotion);
glutPassiveMotionFunc(PassiveMotion);
glutKeyboardFunc(SpecialKey); //keyboard call
glutMouseWheelFunc(OpenGLMouseWheel0);
glutReshapeFunc(OpenGLReshape0);
//glutTimerFunc(0, time_callback, 0);
OpenGLPostprocessor(GLSettings0);
}