Okay, Ive got a cog (toothed gear) that I have drawn in opengl. I have a cylinder attached to one side of it thats supposed to model a handle (Basically, im making a simulation of a hand-cranked drill). Now when i rotate the cog (working), I want the cylinder to move as if it is attached to it. The centre-hole of the cog is at the origin, by the way.
I.e i want it to work like in this pic:
http://www.uktoolcentre.co.uk/ProductImages/25133/BIG/BIG/25133.jpg
except the handle part will be sticking straight out of the red bit, instead of on an extension.
I just cant get my head around the maths to make it so that when i rotate the cog, the cylinder moves as if it is attached to it.
Any help?
You simply need to make sure the translation out to the point near the outer circle of the "red bit" is done after the rotation is applied.
In "classical" immediate OpenGL (which I'm not sure applies to your code), it would be something like:
const float main_cog_radius = 1.f;
const float crank_radius = 0.08f;
glPushMatrix();
glRotatef(main_cog_angle, 0.f, 0.f, 1.f);
draw_main_cog(main_cog_radius);
glTranslatef(main_cog_radius - crank_radius, 0.f, 0.f);
draw_crank(crank_radius);
glPopMatrix();
This assumes the axis through the main cog's center is (0,0,1).