# Simple rotation question

Hello everyone,

This is my first post of many to come, I’m sure.

I have a model loaded in OpenGL that I want to rotate about a specific point. Right now, when I rotate the model (a beam) about Y, it rotates about a point located at the center of the beam.

I really want it to rotate about a point at the end of the beam. AFAIK, I cannot use glTranslatef followed by glRotatef because the point of rotation must be fixed in space.

The only solution I can come up with so far is to add a point at the desired point of rotation, and then rotate the beam in the point’s coordinate system.

Is this the right idea? Any suggestions would be great.

Something like this should work (or the reverse order, I can’t check now) :

glTranslate( endpoint_to_center_of_view)
glRotate()
glTranslate( - endpoint_to_center_of_view)

center = (cx,cy,cz)

glTranslatef(cx,cy,cz)
glRotatef(…)
glTranslatef(-cx,-cy,-cz)

N.

Thank you for the responses! Let me give that a shot and we’ll see what happens.

I’m now realizing that it was a huge mistake to make assumptions and write code to implement the behavior I’m looking for, without fully understanding how OpenGL works.

I’m taking a step back and would just like to confirm that I am thinking about things correctly.

Please take a look at the PDF below:

http://www.mediafire.com/?2sg5z5tmyne

Basically, I have 3 links, a, b, and c. a and b are pinned, and b and c are pinned. If I rotate b, then c should follow, as in (2). If I then rotate a, then b and c should follow, as in (3). If I rotate c, then a and b should keep their current orientation, as in (3).

In general, it almost looks like the algorithm is – do whatever transformation the link’s parent did, followed by its own transformation.

(3) shows two ways of thinking side-by-side. The one on the left (with a faint X through it) is what I believe is incorrect thinking. The one on the right is correct.

(4) shows the transformations that I think should be applied to c to get the desired effect.

Can anyone please glance at the PDF and let me know if I’m on the right track? Thanks!

EDIT – Can anyone also add input about how pushing and popping the modelview matrix could affect things? I think than in my example, the same modelview matrix would be used

maybe you can try something like this,

glPushMatrix();
glTranslate(a_to_center);
glRotate(rotA);
glTranslate(-a_to_center);
Draw(a);
glPopMatrix();

glPushMatrix();
glTranslate(a_to_center);
glRotate(rotA);
glTranslate(-a_to_center);
glTranslate(b_to_center);
glRotate(rotB);
glTranslate(-b_to_center);
Draw(b);
glPopMatrix();

glPushMatrix();
glTranslate(a_to_center);
glRotate(rotA);
glTranslate(-a_to_center);
glTranslate(b_to_center);
glRotate(rotB);
glTranslate(-b_to_center);
glTranslate(c_to_center);
glRotate(rotC);
glTranslate(-c_to_center);