I’am searching for a demo-code of a moving square. Unfortunately I only found sourcecodes of rotating objects.

What about a square e.g. moving from the center of the screen to the edge?

Does anybody has a link? Thanks.

I’am searching for a demo-code of a moving square. Unfortunately I only found sourcecodes of rotating objects.

What about a square e.g. moving from the center of the screen to the edge?

Does anybody has a link? Thanks.

Hi !

It’s pretty much the same as rotation but you use glTranslate instead of glRotate to move the square.

Mikael

Maybe someone has an example.

Thanks.

Hi !

```
double x = 0.0;
...
glTranslate3d( x, 0.0, 0.0);
```

That’s all there is to it, the actual animation is different depending on OS and platform (glut, win32 and so on).

x is the amount to move along the x axis, just update it before you render each frame from inside a timer or something like that.

Mikael

Ok, got it, thanks.

What if the movement should not be linear? E.g. a movement on a curve or function?

Then just calculate the x, y and z translation based on a function of time or whatever.

```
GLdouble x = fx(t);
GLdouble x = fy(t);
GLdouble y = fz(t);
glTranslated(x, y, z);
```

fx, fy and fz are functions that return the x, y and z coordinate, respectively, for a curve as a function of t.

Thanks again.

Finally, what if I want to move the object in z direction?

I have to use gluPerspective, right? However, with

parameters like (70,1,0.4,8.0) the screen stays black. Wrong perspective or is there an additional trick?