import sys, math, time, string from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GLU import * x = 0 y = 0 def draw(): glClear(GL_COLOR_BUFFER_BIT) global x,y glLoadIdentity() glTranslatef(x, y, 0) glColor3f(1, 1, 0) glutWireTeapot(10) glutSwapBuffers() def reshape(width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(10.0, 500.0, -70.0, 220.0) glMatrixMode(GL_MODELVIEW) def keyboard(key, x, y): if key == chr(27): sys.exit(0) bpressed = False def mousebutton(button, state, mx, my): global bpressed if button == GLUT_MIDDLE_BUTTON: bpressed = (state == GLUT_DOWN) def mousemotion(mx,my): global x,y, bpressed if bpressed: # x = mx # y = glutGet(GLUT_WINDOW_HEIGHT) - my x = (float(mx) / glutGet(GLUT_WINDOW_WIDTH)) * 490.0 + 10.0 y = (1.0 - float(my) / glutGet(GLUT_WINDOW_HEIGHT)) * 290.0 - 70.0 glutPostRedisplay() glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutInitWindowSize(400, 400) glutInitWindowPosition(0,0) glutCreateWindow(sys.argv[0]) glutDisplayFunc(draw) glutKeyboardFunc(keyboard) glutMotionFunc(mousemotion) glutMouseFunc(mousebutton) glutReshapeFunc(reshape) reshape(400,400) glutMainLoop()