jhc

04-02-2003, 11:20 AM

I'm just starting my first OpenGL project, which is a (Windows) viewer for 3D wireframe models. It needs to load the model and let the user rotate, scale, and translate for viewing purposes. I'm at the point where I have a primitive working prototype to use for testing the individual functions I need to create.

So far, I'm able to load the data and display it (Ortho mode). I'm trying to get the rotation working correctly using up/down buttons for each axis. The intent is to rotate about a fixed axis system relative to the model - if it is rotated, say, 5 degrees about the Z axis then X and Y move with the model. Subsequent rotations about X need to account for this.

Clicking the buttons causes the correct rotation to occur (5 degrees each click), but with one major problem. If I rotate a few times about each axis and then click (e.g.) X+, then the model leaps to a whole new orientation before rotating about X.

The rotations are applied by a drawing routine as follows:

glPushMatrix(); // Dup current matrix onto stack (This will be the identity matrix)

glTranslated(Translate[XX], Translate[YY], Translate[ZZ]);

if (rotateaboutZ)

{

glRotated(Angle[XX], 1.0, 0.0, 0.0); // Apply Z rotations

glRotated(Angle[YY], 0.0, 1.0, 0.0);

glRotated(Angle[ZZ], 0.0, 0.0, 1.0);

}

else if ...

.

...do the others

.

for (i = 0; i < len; i++) // len is number of elements

{

xyzpos1 = bs[i]; // xyzpos1 is XYZ of first vertex

xyzpos2 = bs[i+1]; // xyzpos2 is XYZ of second vertex

glBegin(GL_LINES);

glVertex3d(xyzpos1.X,xyzpos1.Y,xyzpos1.Z);

glVertex3d(xyzpos2.X,xyzpos2.Y,xyzpos2.Z);

glEnd();

}

glPopMatrix();

I think I understand what's happening (I don't think I should be starting with

the identity matrix) and think there's an obvious solution but have

spent many hours now and can't find it. Can anyone point me in the right direction?

Thanks.

John Coelho

So far, I'm able to load the data and display it (Ortho mode). I'm trying to get the rotation working correctly using up/down buttons for each axis. The intent is to rotate about a fixed axis system relative to the model - if it is rotated, say, 5 degrees about the Z axis then X and Y move with the model. Subsequent rotations about X need to account for this.

Clicking the buttons causes the correct rotation to occur (5 degrees each click), but with one major problem. If I rotate a few times about each axis and then click (e.g.) X+, then the model leaps to a whole new orientation before rotating about X.

The rotations are applied by a drawing routine as follows:

glPushMatrix(); // Dup current matrix onto stack (This will be the identity matrix)

glTranslated(Translate[XX], Translate[YY], Translate[ZZ]);

if (rotateaboutZ)

{

glRotated(Angle[XX], 1.0, 0.0, 0.0); // Apply Z rotations

glRotated(Angle[YY], 0.0, 1.0, 0.0);

glRotated(Angle[ZZ], 0.0, 0.0, 1.0);

}

else if ...

.

...do the others

.

for (i = 0; i < len; i++) // len is number of elements

{

xyzpos1 = bs[i]; // xyzpos1 is XYZ of first vertex

xyzpos2 = bs[i+1]; // xyzpos2 is XYZ of second vertex

glBegin(GL_LINES);

glVertex3d(xyzpos1.X,xyzpos1.Y,xyzpos1.Z);

glVertex3d(xyzpos2.X,xyzpos2.Y,xyzpos2.Z);

glEnd();

}

glPopMatrix();

I think I understand what's happening (I don't think I should be starting with

the identity matrix) and think there's an obvious solution but have

spent many hours now and can't find it. Can anyone point me in the right direction?

Thanks.

John Coelho