PDA

View Full Version : Retranslating multiple objects within a scene



codeviking
03-16-2005, 07:06 PM
I am trying to put together a little Pong clone, and can't figure out how to get my paddles moving independantly. Within my keyboard routine I can change the glTranslatef() values for the group of vertices that make up each paddle. This results in the two of them moving together even when I modify the Y coordinate for only one of them. Is there perhaps another way to be doing this?

shinpaughp
03-16-2005, 08:50 PM
Use glPushMatrix and glPopMatrix to save the current matrix on the stack before your transformation and then pop it off the stack to revert to it after you are done with transformation of an object.

pseudocode:

...
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
...
//base tranformations if any
...
glPushMatrix();
...
translatepaddle1();
drawpaddle1();
...
glPopMatrix();
glPushMatrix();
...
translatepaddle2();
drawpaddle2();
...
glPopMatrix();
glPushMatrix();
...
translateball();
drawball();
...
glPopMatrix();
...

codeviking
03-16-2005, 09:56 PM
Oddly, when I try that the righthand paddle (the second one drawn) is no longer rendered in the scene.

jide
03-17-2005, 10:11 AM
you should learn about modelview matrix and vector spaces. Know when you're drawing from the default origin, and know when you're drawing from any arbitrary new basis.