View Full Version : Moving Squares
07-23-2004, 04: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.
07-23-2004, 05:38 AM
It's pretty much the same as rotation but you use glTranslate instead of glRotate to move the square.
07-26-2004, 05:06 AM
Maybe someone has an example.
07-26-2004, 06:19 AM
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.
07-29-2004, 05:00 AM
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.
07-30-2004, 04:09 AM
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?
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.