PDA

View Full Version : Moving Squares



Sunset
07-23-2004, 03:15 AM
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.

mikael_aronsson
07-23-2004, 04:38 AM
Hi !

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

Mikael

Sunset
07-26-2004, 04:06 AM
Maybe someone has an example.

Thanks.

mikael_aronsson
07-26-2004, 05:19 AM
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

Sunset
07-29-2004, 04:00 AM
Ok, got it, thanks.

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

Bob
07-29-2004, 06:03 AM
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.

Sunset
07-30-2004, 03:09 AM
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?