マウスドラッグ

#include<GL/glut.h>

unsigned char mouseFlag = GL_FALSE;
double yAngle = 0;
int xStart, yStart;

void init(char *name) {
	int width = 400, height = 400;

	glutInitDisplayMode(GLUT_RGBA);
	glutInitWindowSize(width, height);
	glutCreateWindow(name);
	glClearColor(0.0, 0.0, 0.0, 1.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(90.0, (double) width / (double) height, 0.1, 18);
}

void display(void) {
	glClear(GL_COLOR_BUFFER_BIT);

	glColor3d(0.0, 1.0, 1.0);

	glPushMatrix();
	glTranslatef(0.0, 0.0, -3.0);
	glRotated(yAngle, 0.0, 1.0, 0.0);
	glutWireTeapot(1.5);
	glPopMatrix();

	glFlush();
}
void MouseMotion(int x, int y) {
	int xdis;
	if (mouseFlag == GL_FALSE) {
		return 0;
	}

	yAngle += (double) xdis * 0.00000001;

	xStart = x;
	yStart = y;
	glutPostRedisplay();
}

void mouseFunc(int button, int state, int x, int y) {
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
		xStart = x;
		yStart = y;
		mouseFlag = GL_TRUE;
	} else {
		mouseFlag = GL_FALSE;
	}
}

int main(int argc, char **argv) {
	glutInit(&argc, argv);
	init(argv[0]);
	glutDisplayFunc(display);
	glutMouseFunc(mouseFunc);
	glutMotionFunc(MouseMotion);
	glutMainLoop();
	return 0;
}