I've been trying to do a simple animation on the x-axis, where I have a chair and I've drawn it by several cubes, and in all those cubes I want to move the x-variable of them so they can move in that direction.
He is already moving what happens is that I have to do some type of iteration with the keyboard or the mouse so that it moves. Just like the Start Image for the Image After Motion . I wanted this to happen, but without some kind of iteration on the part of the user.
When the chair comes close to the table it reaches the coordinate limit, and has to go back, what happens is that it goes back once 0.05, and then disappears, as it is in the Final Image >.
Initial Image: ImageAfterMotion: FinalImage:
Code I made for the chair to do this animation:
float animation()
{
//glFlush();
for(;varX < 1;)
{
varX += 0.05;
return varX;
}
if (varX >= 1)
{
for(;varX == 0;)
{
returnPosition();
return varX;
}
}
//glutPostRedisplay();
/*
do
{
varX += 0.05;
return varX;
}while(varX < 1);
*/
}
float returnPosition()
{
//glFlush();
for(;varX != 0;)
{
if(varX < 0)
{
for(;varX == 0;)
{
varX += 0.05;
return varX;
}
}
if(varX > 0)
{
for(;varX == 0;)
{
varX -= 0.05;
return varX;
}
}
}
//glutPostRedisplay();
}
These functions are being called in the following function:
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (0.32, 0.32, 0.32); // Achei esta cor RGB em: http://www.rapidtables.com/web/color/RGB_Color.htm
glLoadIdentity ();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, zoom /*zoom*/);
glRotatef(rotateX, 2.0, 0.0, 0.0);
glRotatef(rotateY, 0.0, 2.0, 0.0);
glRotatef(rotateZ, 0.0, 0.0, 2.0);
anim = animation();
chair(0, 0, 0, anim);
chair(0, 0, 1, 0);
table(0.05, 0.05, 0.05);
glFlush ();
}
If someone knows how to help me so that I do not need to interact and the animation happens in the same thanks. If anyone knows how can I do it so that the chair does not disappear at the end of animation, I would also be grateful.
Best wishes and thanks.