#!/usr/bin/env python # # CS 365 Spring 2011, Lab 1 Skeleton # from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from math import sin, cos, pi import sys # Draw one axis plus marks # axno 0=x, 1=y, 2=z # leng length from origin to each end of axis # # You do not need to have a draw_axis function like this one. # def draw_axis(axno, leng): pass def axes(): draw_axis(0, 5) draw_axis(1, 5) draw_axis(2, 5) # Convert degrees to radians def toradians(deg): return pi * deg / 180.0 # Draw an open sphere (with the pole caps removed) centered at the origin. # Radius is passed in. def sphere_open(r): pass # display callback def display(): # Clear frame buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() # Set up the synthetic camera in the Modelview matrix with gluLookAt() # Draw axes axes() # This draws a teapot, so you have something to see. # Eliminate it when you are ready with the sphere. glutWireTeapot(0.5); # Then draw open sphere # Make it all visible glFlush() glutSwapBuffers() # Special key callback def specialkey(keypressed, x, y): global eyex, eyey, eyez # Need to redisplay at the end glutPostRedisplay() # Regular key callback def key(keypressed, x, y): if keypressed == 'e' or keypressed == 'E': sys.exit() # Special ctrl-C handler seems to be needed by pyopengl if (((glutGetModifiers() & GLUT_ACTIVE_CTRL) != 0) and (keypressed == 'c' or keypressed == 'C' or keypressed==chr(3))): sys.exit() # Reshape handler def reshape(w, h): # Set viewport based on w and h # Switch to Projection matrix # Set Projection matrix using glFrustum # Switch back to Modelview matrix # Post a redisplay # Here is a simplest imaginable version with an orthographic projection glViewport(0, 0, 500, 500) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(-1, 1, -1, 1, -1, 1) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glutPostRedisplay() # Redraw on window maximize, etc. def windowstatus(state): if not (state == GLUT_HIDDEN or state == GLUT_FULLY_COVERED): glutPostRedisplay() # Main program if __name__ == "__main__": glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(500, 500) glutCreateWindow("CS 365 Lab 1: MYNAME") glutReshapeFunc(reshape) glutDisplayFunc(display) glutWindowStatusFunc(windowstatus); glutSpecialFunc(specialkey) glutKeyboardFunc(key) glEnable(GL_DEPTH_TEST) glutMainLoop()