how 2 animate

i’ve problem…can anyone help me how to animate line using gl_translate…i don’t know the full coding…please help me…

myDraw()
{
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex3f(1.0, 1.0, 1.0);
glVertex3f(10.0, 10.0, 10.0);
glEnd()
MyOS_SwapBuffers();
MyOS_Redisplay();
}

or alternately use static vars and pus/pop matrix calls.

First how do you want to animate it?
Like have it bounce around the screen?
Is it to move around in 3D or just 2D?

Depending on how you want to animate it, you may not need to use glTranslate at all…

Originally posted by ujeans:
i’ve problem…can anyone help me how to animate line using gl_translate…i don’t know the full coding…please help me…

I HAVE DRAWING A FEW SIMPLE BIRDS USING GL_LINE (2D) SO NOW I WANT TO DO SOMETHING TO SHOW THAT BIRDS ARE MOVE(FLYING)…BUT I DONT KNOW HOW TO DO THAT…

Originally posted by nexusone:
[b]First how do you want to animate it?
Like have it bounce around the screen?
Is it to move around in 3D or just 2D?

Depending on how you want to animate it, you may not need to use glTranslate at all…

[/b]

Dude its really easily. Basically here’s how it works.

glTranslate3f(x,y,z) moves the object x far on the x axis, y far on the y axis, and z far on the z axis. So imagine you did something like this:

int x = 0;
int y = 0;
int z = 0;

int yourDrawFunction() {
glTranslatef(x,y,z);
x++;
y++;
z++;
return 0;
}

Get it?

Draw your birds with the origin in the center of the bird.

wing wing
-------*-------
-1,0; 0,0; 1,0

glPushMatrix();
glTranslatef( x, y, z ); // this takes care of movement around the screen.

/* draw bird

glPopMatrix()

make an array to animate the wings.

int wings[3] = { 1, 0, 1, 0}; 1= wing up, 0= wing down.

Hope this helps

Originally posted by UJEANS:
[b]I HAVE DRAWING A FEW SIMPLE BIRDS USING GL_LINE (2D) SO NOW I WANT TO DO SOMETHING TO SHOW THAT BIRDS ARE MOVE(FLYING)…BUT I DONT KNOW HOW TO DO THAT…

[/b]

i’ve done what u all tell me…but the result not very well…here i give my simple prog…can you all modify my prog…i want all of my 7 birds move, that all…no need mouse or keyboard…pease help me…


int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow(“Tugasan 2”);
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-20.0, 20.0, -20.0, 20.0, -20.0, 20.0);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES); glColor3f(0.0, 0.8f, 1.0);
glVertex3f( 11.0f, 3.0f, 0.0f);
glColor3f(0.0, 0.0, 1.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 19.0f, 0.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.8f, 1.0);
glVertex3f( -9.0f, 5.0f, 0.0f);
glColor3f(0.0, 0.0, 1.0);
glVertex3f( -18.0f, 0.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES); glColor3f(0.0, 0.95f,0.0);
glVertex3f( -18.0f, 0.0f, 0.0f); glVertex3f( -18.0f, -3.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES); glColor3f(0.0, 0.9f,0.0);
glVertex3f( -18.0f, -3.0f, 0.0f); glVertex3f( -18.0f, -7.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES); glColor3f(0.0, 0.95f,0.0);
glVertex3f( -18.0f, -7.0f, 0.0f); glVertex3f( -18.0f, -14.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( -18.0f, -14.0f, 0.0f);
glVertex3f( -12.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( -12.0f, -14.0f, 0.0f);
glVertex3f( -5.5f, -14.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( -5.5f, -14.0f, 0.0f);
glVertex3f( 1.0f, -14.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 2.0f, -6.0f, 0.0f);
glVertex3f( 5.0f, -3.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 2.0f, -6.0f, 0.0f);
glVertex3f( 1.0f, -14.0f, 0.0f);
glVertex3f( 4.5f, -8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.8f,1.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 5.0f, -3.0f, 0.0f);
glVertex3f( 5.6f, -3.0f, 0.0f);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.8f, 1.0); glVertex3f(3.0, -6.0, 0.0);
glVertex3f(5.6, -3.0, 0.0);
glVertex3f(5.0, -3.0, 0.0);
glVertex3f(2.0, -6.0, 0.0);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.8f, 1.0);
glVertex3f(4.5, -8.0, 0.0);
glVertex3f(6.0, -8.0, 0.0);
glVertex3f(3.0, -6.0, 0.0);
glVertex3f(2.0, -6.0, 0.0);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.8f, 1.0);
glVertex3f(1.0, -14.0, 0.0);
glVertex3f(4.0, -14.0, 0.0);
glVertex3f(6.0, -8.0, 0.0);
glVertex3f(4.5, -8.0, 0.0);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 4.6f, -4.0f, 0.0f);
glVertex3f( 3.0f, -6.0f, 0.0f);
glVertex3f( 6.0f, -8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 6.0f, -8.0f, 0.0f);
glVertex3f( 4.0f, -14.0f, 0.0f);
glVertex3f( 8.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.9f, 0.0); glVertex3f(8.0, -14.0, 0.0);
glVertex3f(15.2, -14.0, 0.0);
glVertex3f(5.6, -3.0, 0.0);
glVertex3f(4.5, -4.0, 0.0);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f(3.0f, 0.0f, 0.0f);
glVertex3f( 15.f, -14.0f, 0.0f);
glVertex3f( 19.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 19.0f, -8.0f, 0.0f);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 19.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 19.0f, -4.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f); glVertex3f( 19.0f, -8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 19.0f, 0.0f, 0.0f);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 19.0f, -4.0f, 0.0f);
glEnd();

//bird1
glBegin(GL_LINES);
glColor3f(0.0, 0.0, 0.0);
glVertex2f(13.0, 10.0);
glVertex2f(14.0, 9.0);
glVertex2f(14.0, 9.0);
glVertex2f(15.0, 10.0);

//bird2
glVertex2f(16.0, 10.0);
glVertex2f(17.0, 9.0);
glVertex2f(17.0, 9.0);
glVertex2f(18.0, 10.0);

//bird3
glVertex2f(14.5f, 9.0);
glVertex2f(15.5f, 8.0);
glVertex2f(15.5f, 8.0);
glVertex2f(16.5f, 9.0);

//bird4
glColor3f(0.0, 0.0, 0.0);
glVertex2f(-12.5f, 9.0);
glVertex2f(-12.0, 9.5f);
glVertex2f(-13.0, 9.5f);
glVertex2f(-12.5f, 9.0);

//bird5
glVertex2f(-12.0, 10.5f);
glVertex2f(-11.5f, 10.0);
glVertex2f(-11.5f, 10.0);
glVertex2f(-11.0, 10.5f);

//bird6
glVertex2f(-13.5, 11.5f);
glVertex2f(-13.0, 11.0);
glVertex2f(-13.0, 11.0);
glVertex2f(-12.5f, 11.5f);

//bird7
glVertex2f(-15.0, 9.5f);
glVertex2f(-14.5f, 9.0);
glVertex2f(-14.5f, 9.0);
glVertex2f(-14.0, 9.5f);

glEnd();

glutSwapBuffers();
}

Here is a modified version of your program.

I have made one of the birds animated, you can make the others by copying what I did to the first bird.

#include <GL\glut.h>
#include <stdio.h>
#include <math.h>

GLfloat bx, by, angle;

// This does our animation of the bird
void Idle_loop(void)
{
bx = 1 * cos( angle );// code to change bird’s position
by = 1 * sin( angle );
angle += 0.1;
if (angle > M_TWOPI ) angle = 0;

glutPostRedisplay();
}

void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-20.0, 20.0, -20.0, 20.0, -20.0, 20.0);
}

void keyboard (unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0); // exit program when [ESC] key presseed
break;
default:
break;
}

}

void Draw_bird( GLfloat x, GLfloat y )
{

//Draw bird

glPushMatrix();
glTranslatef( x, y, 0.0); // position bird somewhere on screen
// Draw lines that make the bird.
glBegin(GL_LINES);
glVertex2f(-2, 2.0);
glVertex2f(0.0, 0.0);
glVertex2f(0.0, 0.0);
glVertex2f(2.0, 2.0);
glEnd();
glPopMatrix();
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES); glColor3f(0.0, 0.8f, 1.0);
glVertex3f( 11.0f, 3.0f, 0.0f);
glColor3f(0.0, 0.0, 1.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 19.0f, 0.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.8f, 1.0);
glVertex3f( -9.0f, 5.0f, 0.0f);
glColor3f(0.0, 0.0, 1.0);
glVertex3f( -18.0f, 0.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES); glColor3f(0.0, 0.95f,0.0);
glVertex3f( -18.0f, 0.0f, 0.0f); glVertex3f( -18.0f, -3.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES); glColor3f(0.0, 0.9f,0.0);
glVertex3f( -18.0f, -3.0f, 0.0f); glVertex3f( -18.0f, -7.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES); glColor3f(0.0, 0.95f,0.0);
glVertex3f( -18.0f, -7.0f, 0.0f); glVertex3f( -18.0f, -14.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( -18.0f, -14.0f, 0.0f);
glVertex3f( -12.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( -12.0f, -14.0f, 0.0f);
glVertex3f( -5.5f, -14.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( -5.5f, -14.0f, 0.0f);
glVertex3f( 1.0f, -14.0f, 0.0f);
glEnd();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 2.0f, -6.0f, 0.0f);
glVertex3f( 5.0f, -3.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 2.0f, -6.0f, 0.0f);
glVertex3f( 1.0f, -14.0f, 0.0f);
glVertex3f( 4.5f, -8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.8f,1.0);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 5.0f, -3.0f, 0.0f);
glVertex3f( 5.6f, -3.0f, 0.0f);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.8f, 1.0); glVertex3f(3.0, -6.0, 0.0);
glVertex3f(5.6, -3.0, 0.0);
glVertex3f(5.0, -3.0, 0.0);
glVertex3f(2.0, -6.0, 0.0);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.8f, 1.0);
glVertex3f(4.5, -8.0, 0.0);
glVertex3f(6.0, -8.0, 0.0);
glVertex3f(3.0, -6.0, 0.0);
glVertex3f(2.0, -6.0, 0.0);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.8f, 1.0);
glVertex3f(1.0, -14.0, 0.0);
glVertex3f(4.0, -14.0, 0.0);
glVertex3f(6.0, -8.0, 0.0);
glVertex3f(4.5, -8.0, 0.0);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 4.6f, -4.0f, 0.0f);
glVertex3f( 3.0f, -6.0f, 0.0f);
glVertex3f( 6.0f, -8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 6.0f, -8.0f, 0.0f);
glVertex3f( 4.0f, -14.0f, 0.0f);
glVertex3f( 8.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_QUADS);
glColor3f(0.0, 0.9f, 0.0); glVertex3f(8.0, -14.0, 0.0);
glVertex3f(15.2, -14.0, 0.0);
glVertex3f(5.6, -3.0, 0.0);
glVertex3f(4.5, -4.0, 0.0);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f(3.0f, 0.0f, 0.0f);
glVertex3f( 15.f, -14.0f, 0.0f);
glVertex3f( 19.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 19.0f, -8.0f, 0.0f);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 19.0f, -14.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.95f,0.0);
glVertex3f( 19.0f, -4.0f, 0.0f); glVertex3f( 3.0f, 0.0f, 0.0f); glVertex3f( 19.0f, -8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.9f,0.0);
glVertex3f( 19.0f, 0.0f, 0.0f);
glVertex3f( 3.0f, 0.0f, 0.0f);
glVertex3f( 19.0f, -4.0f, 0.0f);
glEnd();

//bird1
glColor3f( 0.0, 0.0, 0.0);
Draw_bird(14.0 + bx, 9.0 + by);

//bird2
glColor3f( 0.0, 0.0, 0.0);
Draw_bird(17.0, 9.0);

//bird3

glColor3f(0.0, 0.0, 0.0);
Draw_bird(15.0, 8.0);

//bird4
glColor3f(0.0, 0.0, 0.0);
Draw_bird(-13.0, 9.5);

//bird5
glColor3f(0.0, 0.0, 0.0);
Draw_bird(-11.5, 10.0);

//bird6
glColor3f(0.0, 0.0, 0.0);
Draw_bird(-13.0, 11.0);

//bird7
glColor3f(0.0, 0.0, 0.0);
Draw_bird(-14.0, 9.0);

glutSwapBuffers();
}

int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(0, 0);
glutCreateWindow(“Tugasan 2”);
init();
glutKeyboardFunc(keyboard);
glutDisplayFunc(display);
glutIdleFunc( Idle_loop );
glutMainLoop();
return 0;
}