PDA

View Full Version : 2 objects in harmony



Jules
05-23-2002, 06:29 AM
I have 2 objects, that are defined in the two functions mybody() and orbit(). mybody() sits in the centre of the screen and rotates, while orbit() should orbit mybody(). My problem is that they don't want to appear 2gether. heres the code snippet:

glLoadIdentity();
glTranslatef(0.0,0.0,-8.0);
glRotatef(spin,0.0,1.0,0.0);
mybody();


glTranslatef(5.0,0.0,-5.0);
glRotatef(spin,5.0,4.0,3.0);
orbit();

glutSwapBuffers();
}//end display()

cheers 4 any help
Jules

nexusone
05-23-2002, 08:00 AM
I think the other object is just being drawn off screen. When you translate it effects all objects after it, unless you push the matrix then it only effects the object between the push/pop. Right now your last object(orbit) is being tranlated by -12 on the z-axis.


Try this:

glLoadIdentity();

glPushMatrix();
glTranslatef(0.0,0.0,-8.0);
glRotatef(spin,0.0,1.0,0.0);
mybody();
glPopMatrix();

glPushMatrix();
glTranslatef(5.0,0.0,-5.0);
glRotatef(spin,5.0,4.0,3.0);
orbit();
glPopMatrix();

glutSwapBuffers();
}//end display()

http://www.opengl.org/discussion_boards/ubb/smile.gif


Originally posted by Jules:
I have 2 objects, that are defined in the two functions mybody() and orbit(). mybody() sits in the centre of the screen and rotates, while orbit() should orbit mybody(). My problem is that they don't want to appear 2gether. heres the code snippet:

glLoadIdentity();
glTranslatef(0.0,0.0,-8.0);
glRotatef(spin,0.0,1.0,0.0);
mybody();


glTranslatef(5.0,0.0,-5.0);
glRotatef(spin,5.0,4.0,3.0);
orbit();

glutSwapBuffers();
}//end display()

cheers 4 any help
Jules