# The Industry's Foundation for High Performance Graphics

1. ## axis,rotation

I have drawn a rod with its centre at 0.0.0.When I use rotate it is rotated at its centre. Is there a way to rotated about an axis at the 2/3 of its length ,without changing the way it is drawn (with 0.0.0 at its center) ?

2. ## Re: axis,rotation

Yes, certainly. The trick is to use a composition of translations and a rotation. Let's say you're in the standard GL coordinate system, i.e.:

a. positive-x axis is to the right
b. positive-y axis is upwards
c. negative-z axis is into the screen

Say you're at (0, 0, 5) and looking in the negative-z direction, so that you can see the origin.

At the origin there is a vertical line going from (0, -3, 0) to (0, 3, 0).

If you call:

glRotatef(90, 1, 0, 0);

before drawing the line, the line will be rotated 90 degrees about the x-axis.

Now, you want to rotate the line (rod) about an axis somewhere other than the center. Suppose you want to rotate it 90 degrees about the line that is parallel to the x-axis and passes through the point (0, 1.5, 0).

This can be accomplished by:

glTranslatef(0, 1.5, 0);
glRotatef(90, 1, 0, 0);
glTranslatef(0, -1.5, 0);

// code to draw the line

Remember that modelview transformations are applied in the reverse order that they appear. So the above code:

1. translates everything down 1.5 units; in other words, the axis you want to rotate about has now been moved down to the x-axis

2. then rotates 90-degrees about the x-axis

3. finally translates the model back up 1.5 units

I suggest drawing a picture ... hope that helps.

Eric

3. ## Re: axis,rotation

Thanx Eric.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•