PDA

View Full Version : Moving objects independently of each other



fox
09-07-2000, 02:36 AM
Given a number of objects how would you move them independently og each other

wolfman8k
09-07-2000, 04:10 AM
glLoadIdentity();
glTranslatef(x1, y1, z1);
/* Draw first object */
glLoadIdentity();
glTranslatef(x2, y2, z2);
/* Draw second object */
glLoadIdentity();
glTranslatef(x3, y3, z3);
/* Draw third object */

x1, y1, z1, x2 ... are the coordanites of the first second and third objects. Just change the coordanites of an object and only it will move.

(Note: This example code doesn't implement rotation)

SuperFly
09-07-2000, 04:38 AM
Another way to do it:

glPushMatrix();
glTransatef(x1, y1, z1);
/* Draw object 1 */
glPopMatrix();
glPushMatrix();
glTransatef(x2, y2, z2);
/* Draw object 2 */
glPopMatrix();
glPushMatrix();
glTransatef(x3, y3, z3);
/* Draw object 3 */
glPopMatrix();

This way it keeps any modifications done to the modelview matrix before the drawing.