# Rotation question

Hi!
I’m just starting to learn OpenGl and I thought I would do so by making some kinde of a pool or snooker game. My problem is that I want the ball to rotate about an axis perpendicular to the ball’s velocity vector… As it would i real life if you don’t take into consideration it might have some other kind of spin. I just want to be able to roll the ball forward in any direction.
I serched this forum, but I’m not sure I could find the answer I’m looking for… I would be very glad if someone here could help me, since I’m kind of stuck right now.

If you know the direction the ball is rolling, and you know where up is, you can calculate the sidevector by taking the crossproduct of the other two vectors. side = front cross up

There you have the axis you need to rotate about. Just pass this axis along with the angle to glRotatef. The angel at which you need to rotate is depending on the balls radius and speed. I’m sure you can calculate the proper angle if you really want to. Just take a paper and make some nifty drawings.

Hmm… So I have to use Glrotate only once then?! And precalculate what to put in there using the method you described…? Have I understood this correctly?

Thanks, by the way!

Let’s say the directon of the ball is V, and up is U, then the sidevector S = V x U (x = crossproduct). S is the vector you pass to glRotate, like this: glRotatef(angle, S.x, S.y, S.z); That will rotate the object angle degrees about the vector S, which is the same as rotating the ball as it rolls on the table. So yes, I guess you got it right.

I haven’t bothered calculating the formula for the angle, let’s say I left it as an exercise for the reader If you really can’t calculate the angle, I can give it a try, just tell me.

Thank you!
I’ll see if I can get this to work…

Bringing this old topic back to life…
I haven’t had time to try your suggestions until now and… Well… It kind of works but not 100%.
When the ball gets a sudden change in direction (for example if it hits a wall) I sometimes get a strange result. The ball seems to flip or rotate very much in one single frame and then everything is fine until it gets another sudden change in velocity. The strange thing is that it happens most of the times but not EVERY time.

I would appreciate any help I could get on this.
Thanks!

Hmmmm, my opinion?, well considering that it’s a snooker game and not pool. You won’t have numbers on the balls. This means you don’t really need to rotate the balls. You can give the effect with lighting. Otherwise the only way I can see it is with very high precision. I can’t think up a math formula now for ya, gotto almost go home

The thing is that my game has changed a bit sice I first posted this question and now the ball is supposed to roll on an arbitrary shaped landscape and it looks kind of boring if the ball is only sliding around instead of rolling…