PDA

View Full Version : Rolling Sphere

11-13-2001, 02:35 PM
Hi.

I am coding a billiard game as an school project. I need some help with the rolling of the ball. I have the rolling angles around x- and z-axes, but I don't know how to combine them to form the final rotation. Using glRotate*() twice in a row is not good (I have heard terms gimble lock and quaternion defining my problem.) How is this problem handled correctly?

This is what I tried, but didn't work: glTranslatef(balls[i]->pos[0],balls[i]->pos[1],balls[i]->pos[2]);
glRotatef(rotx, 1.0, 0.0, 0.0);
glRotatef(rotz, 0.0, 0.0, 1.0);
glutWireSphere(0.2,15,12);

marysowdha
11-13-2001, 03:37 PM
is there any point/line given in xz plane as axis of rotation?

Dong Ke
11-13-2001, 05:36 PM
Can you put a link of you project here showing the problem?

dorbie
11-13-2001, 05:43 PM
OpenGL allows you to specify an axis of rotation. For a ball rolling on a horizontal surface this axis of rotation should be the cross product of the up vector and the velocity vector. You should normalize before using it and beware zero length velocity.

The amount of rotation will be determined by the velocity and the equation for the circumferance of the sphere (Pi * diemeter), where one circumferance corresponds to a 360 degree rotation in OpenGL. For any given distance divide by the circumferance of the ball and rotate by that ammount about the above vector.

11-14-2001, 04:59 AM
The ball moves on the x-z plane. I know the x-velocity and z-velocity. Then I know the rotation around x-axis and around z-axis. The problem is how to combine them...

Ilari