View Full Version : Need help stopping and redrawing an object...

04-09-2001, 09:19 PM
I have a question regarding what seems to be a simple function but i cant seem to get it to work, I am using NeHe's Windows framework(the framework is not all that important) and I am hoping that someone could help me accomplish the following:
-> I have an object that I would like to move along the z-axis to a certain point the stop it from moving (once at this point I want to "erase" this object and start to draw a new one from the beginning point and have it travel to a point and erase..then redraw a new object (a simple loop)) also if possible where in NeHe's (http://nehe.gamedev.net/opengl.asp) framework would this be placed, I have tried a number of different places but none seem to work. If someone could help me with this it would be a huge help! I am trying to learn this on my own and running into a few hurdles.

thanks for your time.

04-10-2001, 03:47 AM
you could do something like this:
push matrix
for i=0;i<num of objects;i++
load identity matrix
for j=0;j<how far along the z axis you want to go;j++
end loop
end loop

I'm not saying this is complete, but maybe a good place to start...

04-11-2001, 04:35 AM
Ok... assuming for now you just have the same object looping for this each time you could do this for your display function.

static int nLoc = 0;

// Where scale is the distance you want the
// object to travel to.
float fZ = ((float)nLoc / 1000.0) * scale;

glTranslatef(0.0, 0.0, -fZ);

// Where step is based on how far you want it to move each frame
nLoc += step;
nLoc %= 1000; // If it goes over 1000, it will start over

That's just one possibility... If you are using an OOD you could just store the position as a member of the class and when you draw, if it's too big, you reset the position.

If you want each object that repeats to be different, then the above will work with modifications. You'll have to have some way to specify which object is being drawn at any given time.

04-11-2001, 09:12 PM
Thanks a lot for the help, i did not get a chance today to try it out. But I will defenitly get a chance tomorrow.