Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have a "cannon" object (basically a long cylinder) and I want to be able to control its angle. The code I have now is:

    glRotated(self.tube_angle, 1.0, 0.0, 1.0)
    glScaled(1.0, 0.5, 1.0)

This rotates it around the axis, obviously. I want the bottom to stay in the spot it is (moving object) and just change the angle.

share|improve this question
You can teach yourself :)… – Byte56 Mar 9 '12 at 3:09
rotate around point P: (1) translate by -P (2) rotate around origin (3) translate by P (4) Profit!!! – Jimmy Mar 9 '12 at 3:55

Since glRotated() rotates a specified angle around the desired axies (x and z in your example), you'll need to translate your object first. This is important.

Note: The rotation center is always considered (0,0,0).

Example: Rotate 20° About Point (0, 5, -10)

// Save the current display for other items.

// Translate by the opposite of the desired point of rotation.
glTranslate(0, -5, 10);

// perform the desired rotation.
glRotate(20, 1, 0, 0);

// Put the object back where it was.
glTranslate(0, 5, -10);

// Now, draw the object with proper rotation!
...draw code...

// Finally, reset our transformation matrix to where we left it.
// It's the polite thing to do, after all.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.