New to openGL, transformations help needed

Hi,

I am having a lot of trouble trying to perform the following transformation in openGL. I have two cylinders. One of them is pointing straight upwards at the origin and the other comes out of the first at a 45 degree angle (imagine a sort of slingshot shaped object and you’ve got the right idea). Now, what I’m trying (and failing) to do is rotate and then translate the first cylinder (the one that is pointing straight upwards) and ALSO perform the exact same transformations to the second cylinder so that the overall shape of my slingshot-like object is preserved.

Here is the code I have so far:


// draw second cylinder
glPushMatrix();
glTranslated(0, 0.5, 0);
glRotated(45, 0.0, 1.0, 0.0);
glRotated(-45, 1.0, 0.0, 0.0);
gluCylinder(quadratic2, 0.1, 0.1, 1.0, 12, 2);
glPopMatrix();

// draw first cylinder (points straight up)
glPushMatrix();
glTranslated(0, -1, 0);
glRotated(-90, 1.0, 0.0, 0.0);
gluCylinder(quadratic, 0.3, 0.3, 3.0, 12, 2);
glPopMatrix();


Could anyone please show me how to add the transformations to the above code? Rememeber that all I’m trying to do is move my slingshot object about in 3D space whilst maintaining the object’s exact shape. Everything I’ve tried so far has ended up altering the shape of the object.

Thanks.

Just wrap another transformation around the whole thing…

glPushMatrix();
some_transformations();

draw_the_slingshot();

glPopMatrix();

some_transformations() is whatever you want to do with the object, and draw_the_slingshot() is exactly the code you posted.

The code to draw the original object is not altered, so you could call it multiple times with different transformations applied to it.

Thanks, works like a charm now

yes i can do it