PDA

View Full Version : "moving" around object



gemini
02-26-2003, 08:53 AM
Hello everyone.
i have implemented 2 boxes to my gl scene.
Is there any chance to move any of them without using the glTranslatef(d) functions?
Cause when i use:
//first box moves
glTranslatef(x,y,z);
drawobject(1);

//second one moves
glTranslatef(x1,y1,z1);
drawobject(2);

there is a kind of mess over there, they really dont move exactly where x,x1,y,y1,z,z1 points ;(((

Please help.

shinpaughp
02-26-2003, 10:24 AM
Your second glTranslate is relative to the first glTranslate (ie they are added like vectors). So, if you want the second to be absolute you should use glPushMatrix before your first cal, and then glPopMatrix before your second call.

Also, the gl coordinates that are visible are determined by your projection view as in gluPerspective, glFrustum, glOrtho. How they are set up will determine the coordinate system visible within your viewport.

gemini
02-26-2003, 10:32 AM
Big thanks.

sikander
02-26-2003, 07:45 PM
yeah, u r correct. glPushMatrix() saves your previous state in a stack.after calling it u can transform any one of the box and after transforming it call popMatrix() which will restore ur last state and the transform effect forthe first box will not come into effect.
this is the best way out for modelling hierarchical models.
sikander

Originally posted by shinpaughp:
Your second glTranslate is relative to the first glTranslate (ie they are added like vectors). So, if you want the second to be absolute you should use glPushMatrix before your first cal, and then glPopMatrix before your second call.

Also, the gl coordinates that are visible are determined by your projection view as in gluPerspective, glFrustum, glOrtho. How they are set up will determine the coordinate system visible within your viewport.