glRotate and glTranslate

pushVTEC

Senior member
Aug 30, 2003
265
0
0
I'm writing a little program for a class first it's supposed to create a triangle and have it rotate on it's y axis, then draw another triangle 3 spaces over and have it rotate on it's x axis, both in place. I can get both of them to spin correctly, the first spins in place on the y like it's supposed to, and the second spins on it's x axis but it also orbiting around the first object as it's spinning on it's axis.

my code is like this:

glRotatef(rotate, 0.0f, 1.0f, 0.0f);
glTranslate(0.0f, -0.5f, 0.0f);
triangle.draw();
glRotate(rotate, 1.0f, 0.0f, 0.0f);
glTranslate(rotate, 3.0f, 0.0f, 0.0f);
triangle.draw();

do i need to do a pushmatrix and popmatrix for each triangle object? or what am I doing wrong?
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Originally posted by: pushVTEC
do i need to do a pushmatrix and popmatrix for each triangle object?

Yes. IIRC, do a push before you start the rotations/translations/scales, then pop after the object is drawn.
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
Yeah I thought I had tried that but apparently I left a pop out of it and caused my objects to spin into oblivion lol

floor1.draw();
glPushMatrix();
glTranslatef(0.0f, -0.5f, 0.0f);
glRotatef(rotate, 0.0f, 1.0f, 0.0f);
glColor3d(1.0, 0.0, 0.0);
pyramid1.draw();
glPopMatrix();
glPushMatrix();
glColor3d(0.0, 1.0, 0.0);
glTranslatef(3.0, -0.5f, 0.0);
glRotatef(rotate, 1.0, 0.0, 0.0);
pyramid1.draw();
glPopMatrix();