I want to rotate a shape in opengl, but I want to rotate it at a point. Namely I have a cylinder and I want to rotate it so it looks like it is spinning at the bottom and the spin 'size' increases until the object falls to the ground. How would I do this kind of rotation in opengl?
Asked
Active
Viewed 4,190 times
1 Answers
3
- Translate to the origin
- Rotate
- Translate back
So, if you want to rotate around (a,b,c), you would translate (-a,-b,-c) in step 1, and (a,b,c) in step 3.
(Don't be afraid of the number of operations, by the way. Internally all you do is multiply the transform matrix three times, but the pipeline that transforms the vertices is agnostic of how many operations you did, it still only uses the one final matrix. The magic of using a matrix for transformation.)

Damon
- 67,688
- 20
- 135
- 185
-
But I am hoping for the object to rotate at an angle, so it looks like it is spinning on the objects point. Does that make sense? – Neutralise Oct 03 '11 at 11:07
-
Hang on, I was caught in confusion for a second... was going to say something stupid. – Damon Oct 03 '11 at 11:51
-
What the API offers to you (unless you maintain your own matrix stack such as in OpenGL 3.x and later) is translation and rotation along an axis _at the origin_. Therefore, to rotate around _some other point_, e.g. the object's point, you first transform to the origin, rotate, and then transform back. That should do just what you want. – Damon Oct 03 '11 at 11:56
-
About the "increasing the spin size and falling to the ground", I am not 100% sure what you mean, but basically it's the same. For "falling" you will probably want to use translations on your object's center-of-mass point, and that is the point you'll transform to the origin and back too, before applying whatever spinning rotation you want. Move the center-of-mass as the object falls. Or, are you talking in "falling" as in a spinner (child's toy) toppling at the end? In that case you would need a mini-physics simulation, basically overlaying two rotations. The OpenGL part remains the same. – Damon Oct 03 '11 at 12:00
-
Ok, it is the mini-physics style I am interested in. So I will translate to the origin so I can rotate it around the point. Thanks. – Neutralise Oct 03 '11 at 12:12
-
Note that for a somewhat realistic simulation (object spinning, then hitting the floor, and bouncing/sliding a bit) you will need something like a rigid body simulation. In the simplest case, something like 6-10 particles connected by stiff distance constraints. The math to figure out the orientation can be daunting if you haven't done that, though. Google for "Jakobsen Advanced Character Animation" or look at [this](http://www.members.lycos.co.uk/olivierrenault/rigid.zip). – Damon Oct 03 '11 at 12:26