I'm using OpenGL and have a stack of cylinders connected by a sphere that I want to rotate.
I'm making a sort of 'pipeline' thing and want the rotations to be smooth (so when the bottom cylinder rotates, the top one moves accordingly, but the top one could rotate without moving the bottom one
The only issue is that I want to build on from this, but even now with just cylinders I can't get the top one rotating without moving the whole thing.
My code is:
void draw_cylinder(float translate_x, float translate_y, float angle1) {
GLUquadricObj *qobj = gluNewQuadric();
//first cylinder
glPushMatrix();
glTranslatef(translate_x, translate_y-0.5, 0.0);
glRotatef(angle1, 0.0, 0.0, 1.0);
glPushMatrix();
glRotatef(90.0, -45.0, 0.0, 0.0);
gluCylinder(qobj, 1.0, 1.0, 10.0, 20, 20);
gluQuadricOrientation (qobj, GLU_INSIDE);
gluDisk(qobj, 0.0, 1.0, 20, 20);
glTranslatef(0.0, 0.0, 10.0);
gluQuadricOrientation (qobj, GLU_OUTSIDE);
gluDisk(qobj, 0.0, 1.0, 20, 20);
glPopMatrix();
glPushMatrix(); //Connecting sphere
glTranslatef(translate_x, translate_y+10.5, 0.0);
glutSolidSphere(1,20,20);
glPopMatrix();
//second cylinder
glPushMatrix();
glTranslatef(translate_x, translate_y+11.3, 0.0);
glRotatef(angle2, 0.0, 0.0, 1.0);
glPushMatrix();
glRotatef(90.0, -45.0, 7.0, -7.0);
gluCylinder(qobj, 1.0, 1.0, 5.0, 20, 20);
gluQuadricOrientation (qobj, GLU_INSIDE);
gluDisk(qobj, 0.0, 1.0, 20, 20);
glTranslatef(0.0, 0.0, 5.0);
gluQuadricOrientation (qobj, GLU_OUTSIDE);
gluDisk(qobj, 0.0, 1.0, 20, 20);
glPopMatrix();
glPopMatrix();
glPopMatrix(); }
any help would be appreciated