I want to know that how i can rotate an object about a point where I click on the screen.
Currently I am able to rotate it about the center of the screen.
My code is as following. Please suggest a simple way to modify this for the desired results.
void mouse(int button, int state, int x, int y)
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
mouseDown = true;
xdiff = x - yrot;
ydiff = -y + xrot;
mouseDown = false;
void mouseMotion(int x, int y)
yrot = x - xdiff;
xrot = y + ydiff;
and these lines in my display function:
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);